Skip to content

Commit

Permalink
Corrects composer.json
Browse files Browse the repository at this point in the history
  • Loading branch information
alexstandiford committed Nov 23, 2021
1 parent 60174e9 commit 1d80952
Show file tree
Hide file tree
Showing 13 changed files with 66 additions and 78 deletions.
11 changes: 11 additions & 0 deletions bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

use Underpin\Abstracts\Underpin;
use Underpin\Factories\Observers\Loader;

if ( ! defined( 'ABSPATH' ) ) {
exit;
}

// Add this loader.
Underpin::attach( 'setup', new Loader( 'scripts', [ 'class' => 'Underpin\Scripts\Loaders\Scripts' ] ) );
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
"underpin/underpin": "^2.0"
},
"autoload": {
"psr-4": {"Underpin\\Scripts\\": "lib/"},
"files": [
"scripts.php"
"bootstrap.php"
]
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php

namespace Underpin_Scripts\Abstracts;
namespace Underpin\Scripts\Abstracts;


use Underpin\Abstracts\Observer;
use Underpin\Abstracts\Storage;
use function Underpin\underpin;
use Underpin\Loaders\Logger;

if ( ! defined( 'ABSPATH' ) ) {
exit;
Expand All @@ -23,9 +23,9 @@ public function enqueue() {
if ( $this->instance instanceof Script ) {
$this->instance->enqueue();
} else {
underpin()->logger()->log( 'warning', 'rest_middleware_action_failed_to_run', 'Middleware action failed to run. Rest_Middleware expects to run on a Script loader.', [
Logger::log( 'warning', 'rest_middleware_action_failed_to_run', 'Middleware action failed to run. Rest_Middleware expects to run on a Script loader.', [
'loader' => get_class( $this->instance ),
'expects' => 'Underpin_Scripts\Abstracts\Script',
'expects' => 'Underpin\Scripts\Abstracts\Script',
] );
}
}
Expand Down
23 changes: 12 additions & 11 deletions lib/abstracts/Script.php → lib/Abstracts/Script.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
*/


namespace Underpin_Scripts\Abstracts;
namespace Underpin\Scripts\Abstracts;

use Underpin\Loaders\Logger;
use Underpin\Traits\Feature_Extension;
use Underpin\Traits\With_Middleware;
use WP_Error;
use function Underpin\underpin;


if ( ! defined( 'ABSPATH' ) ) {
exit;
Expand Down Expand Up @@ -108,7 +109,7 @@ public function __construct() {
$this->ver = $file['version'];
}
} else {
underpin()->logger()->log(
Logger::log(
'error',
'dependencies_file_not_found',
'A dependency file was specified, but it could not be found.',
Expand Down Expand Up @@ -182,7 +183,7 @@ public function set_param( $key, $value ) {

// If the script is already enqueued, return an error.
if ( $this->is_enqueued() ) {
return underpin()->logger()->log_as_error(
return Logger::log_as_error(
'error',
'param_set_too_late',
'The localized param ' . $key . ' was set after the script was already enqueued.',
Expand All @@ -207,7 +208,7 @@ public function remove_param( $key ) {

// If the script is already enqueued, return an error.
if ( wp_script_is( $this->handle ) ) {
return underpin()->logger()->log_as_error(
return Logger::log_as_error(
'error',
'param_removed_too_late',
'The localized param ' . $key . ' attempted to be removed after the script was already enqueued.',
Expand Down Expand Up @@ -235,14 +236,14 @@ public function localize() {
$localized = wp_localize_script( $this->handle, $this->localized_var, $localized_params );

if ( false === $localized ) {
underpin()->logger()->log(
Logger::log(
'error',
'script_was_not_localized',
'The script ' . $this->handle . ' failed to localize. That is all I know, unfortunately.',
[ 'handle' => $this->handle, 'params' => $localized_params ]
);
} else {
underpin()->logger()->log(
Logger::log(
'notice',
'script_was_localized',
'The script ' . $this->handle . ' localized successfully.',
Expand All @@ -262,14 +263,14 @@ public function register() {
$registered = wp_register_script( $this->handle, $this->src, $this->deps, $this->ver, $this->in_footer );

if ( false === $registered ) {
underpin()->logger()->log(
Logger::log(
'error',
'script_was_not_registered',
'The script ' . $this->handle . ' failed to register. That is all I know, unfortunately.',
[ 'ref' => $this->handle ]
);
} else {
underpin()->logger()->log(
Logger::log(
'notice',
'script_was_registered',
'The script ' . $this->handle . ' registered successfully.',
Expand All @@ -289,14 +290,14 @@ public function enqueue() {

// Confirm it was enqueued.
if ( wp_script_is( $this->handle, 'enqueued' ) ) {
underpin()->logger()->log(
Logger::log(
'notice',
'script_was_enqueued',
'The script ' . $this->handle . ' has been enqueued.',
[ 'ref' => $this->handle ]
);
} else {
underpin()->logger()->log(
Logger::log(
'error',
'script_failed_to_enqueue',
'The script ' . $this->handle . ' failed to enqueue.',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php


namespace Underpin_Scripts\Factories;
namespace Underpin\Scripts\Factories;


use Underpin\Abstracts\Observer;
use Underpin\Abstracts\Storage;
use Underpin_Scripts\Abstracts\Script;
use function Underpin\underpin;
use Underpin\Loaders\Logger;
use Underpin\Scripts\Abstracts\Script;

if ( ! defined( 'ABSPATH' ) ) {
exit;
Expand All @@ -22,9 +22,9 @@ function update( $instance, Storage $storage ) {
if ( $instance instanceof Script ) {
add_action( 'admin_enqueue_scripts', [ $instance, 'enqueue' ] );
} else {
underpin()->logger()->log( 'warning', 'rest_middleware_action_failed_to_run', 'Middleware action failed to run. Rest_Middleware expects to run on a Script loader.', [
Logger::log( 'warning', 'rest_middleware_action_failed_to_run', 'Middleware action failed to run. Rest_Middleware expects to run on a Script loader.', [
'loader' => get_class( $this->loader_item ),
'expects' => 'Underpin_Scripts\Abstracts\Script',
'expects' => 'Underpin\Scripts\Abstracts\Script',
] );
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
namespace Underpin_Scripts\Factories;
namespace Underpin\Scripts\Factories;

if ( ! defined( 'ABSPATH' ) ) {
exit;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php


namespace Underpin_Scripts\Factories;
namespace Underpin\Scripts\Factories;


use Underpin\Abstracts\Storage;
use Underpin_Scripts\Abstracts\Enqueue_Conditional;
use Underpin\Scripts\Abstracts\Enqueue_Conditional;

if ( ! defined( 'ABSPATH' ) ) {
exit;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php


namespace Underpin_Scripts\Factories;
namespace Underpin\Scripts\Factories;


use Underpin\Abstracts\Observer;
use Underpin\Abstracts\Storage;
use Underpin_Scripts\Abstracts\Script;
use function Underpin\underpin;
use Underpin\Loaders\Logger;
use Underpin\Scripts\Abstracts\Script;

if ( ! defined( 'ABSPATH' ) ) {
exit;
Expand All @@ -22,9 +22,9 @@ public function update( $instance, Storage $args ) {
if ( $instance instanceof Script ) {
add_action( 'login_enqueue_scripts', [ $instance, 'enqueue' ] );
} else {
underpin()->logger()->log( 'warning', 'rest_middleware_action_failed_to_run', 'Middleware action failed to run. Rest_Middleware expects to run on a Script loader.', [
Logger::log( 'warning', 'rest_middleware_action_failed_to_run', 'Middleware action failed to run. Rest_Middleware expects to run on a Script loader.', [
'loader' => get_class( $instance ),
'expects' => 'Underpin_Scripts\Abstracts\Script',
'expects' => 'Underpin\Scripts\Abstracts\Script',
] );
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php


namespace Underpin_Scripts\Factories;
namespace Underpin\Scripts\Factories;


use Underpin\Abstracts\Observer;
use Underpin\Abstracts\Storage;
use Underpin_Scripts\Abstracts\Script;
use function Underpin\underpin;
use Underpin\Loaders\Logger;
use Underpin\Scripts\Abstracts\Script;

if ( ! defined( 'ABSPATH' ) ) {
exit;
Expand All @@ -22,9 +22,9 @@ public function update( $instance, Storage $args ) {
if ( $instance instanceof Script ) {
add_action( 'wp_enqueue_scripts', [ $instance, 'enqueue' ] );
} else {
underpin()->logger()->log( 'warning', 'rest_middleware_action_failed_to_run', 'Middleware action failed to run. Rest_Middleware expects to run on a Script loader.', [
Logger::log( 'warning', 'rest_middleware_action_failed_to_run', 'Middleware action failed to run. Rest_Middleware expects to run on a Script loader.', [
'loader' => get_class( $instance ),
'expects' => 'Underpin_Scripts\Abstracts\Script',
'expects' => 'Underpin\Scripts\Abstracts\Script',
] );
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<?php

namespace Underpin_Scripts\Factories;
namespace Underpin\Scripts\Factories;


use Underpin\Abstracts\Storage;
use Underpin\Loaders\Logger;
use Underpin\Traits\Instance_Setter;
use Underpin_Scripts\Abstracts\Enqueue_Conditional;
use Underpin_Scripts\Abstracts\Script;
use function Underpin\underpin;
use Underpin\Scripts\Abstracts\Enqueue_Conditional;
use Underpin\Scripts\Abstracts\Script;


if ( ! defined( 'ABSPATH' ) ) {
exit;
Expand All @@ -32,9 +33,9 @@ public function enqueue() {
if ( $this->loader_item instanceof Script ) {
$this->loader_item->enqueue();
} else {
underpin()->logger()->log( 'warning', 'rest_middleware_action_failed_to_run', 'Middleware action failed to run. Rest_Middleware expects to run on a Script loader.', [
Logger::log( 'warning', 'rest_middleware_action_failed_to_run', 'Middleware action failed to run. Rest_Middleware expects to run on a Script loader.', [
'loader' => get_class( $this->loader_item ),
'expects' => 'Underpin_Scripts\Abstracts\Script',
'expects' => 'Underpin\Scripts\Abstracts\Script',
] );
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
*/


namespace Underpin_Scripts\Factories;
namespace Underpin\Scripts\Factories;


use Underpin\Traits\Instance_Setter;
use Underpin_Scripts\Abstracts\Script;
use function Underpin\underpin;
use Underpin\Scripts\Abstracts\Script;


if ( ! defined( 'ABSPATH' ) ) {
exit;
Expand Down
17 changes: 9 additions & 8 deletions lib/loaders/Scripts.php → lib/Loaders/Scripts.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
*/


namespace Underpin_Scripts\Loaders;
namespace Underpin\Scripts\Loaders;

use Underpin\Abstracts\Registries\Object_Registry;
use Underpin_Scripts\Abstracts\Script;
use Underpin\Loaders\Logger;
use Underpin\Scripts\Abstracts\Script;
use WP_Error;
use function Underpin\underpin;


if ( ! defined( 'ABSPATH' ) ) {
exit;
Expand All @@ -30,9 +31,9 @@ class Scripts extends Object_Registry {
/**
* @inheritDoc
*/
protected $abstraction_class = '\Underpin_Scripts\Abstracts\Script';
protected $abstraction_class = '\Underpin\Scripts\Abstracts\Script';

protected $default_factory = '\Underpin_Scripts\Factories\Script_Instance';
protected $default_factory = '\Underpin\Scripts\Factories\Script_Instance';

/**
* @inheritDoc
Expand Down Expand Up @@ -61,7 +62,7 @@ public function set_param( $script, $key, $value ) {
$script = $this->get( $script );

if ( is_wp_error( $script ) ) {
return underpin()->logger()->log_as_error(
return Logger::log_as_error(
'error',
'set_param_invalid_script',
'A param was not set because the script could not be found',
Expand All @@ -85,7 +86,7 @@ public function remove_param( $script, $key ) {
$script = $this->get( $script );

if ( is_wp_error( $script ) ) {
return underpin()->logger()->log_as_error(
return Logger::log_as_error(
'error',
'set_param_inavlid_script',
'A param was not set because the script could not be found',
Expand All @@ -112,7 +113,7 @@ public function enqueue( $handle ) {

return true;
} else {
return underpin()->logger()->log_as_error(
return Logger::log_as_error(
'error',
'script_not_enqueued',
'The specified script could not be enqueued because it has not been registered.',
Expand Down
27 changes: 0 additions & 27 deletions scripts.php

This file was deleted.

0 comments on commit 1d80952

Please sign in to comment.