Skip to content

Commit

Permalink
Corrects underpin autoloader
Browse files Browse the repository at this point in the history
  • Loading branch information
alexstandiford committed May 12, 2021
1 parent 8164420 commit 4d4dc4d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/abstracts/Underpin.php
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ public function logger() {
*
* @return bool True if debug mode is enabled, otherwise false.
*/
public function is_debug_mode_enabled() {
public static function is_debug_mode_enabled() {
$is_invalid_request = defined( 'WP_TESTS_DOMAIN' ) || defined( 'WP_CLI' ) || wp_doing_ajax() || wp_doing_cron() || defined( 'REST_REQUEST' );

// Bail early if this is not a valid request for debug mode.
Expand Down
2 changes: 1 addition & 1 deletion lib/abstracts/registries/Loader_Registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function add( $key, $value ) {

if ( ! $this instanceof \Underpin_Logger\Loaders\Logger && ! is_wp_error( underpin()->logger() ) ) {
underpin()->logger()->log(
'notice',
'debug',
'loader_actions_ran',
'The actions for the ' . $this->registry_id . ' item called ' . $key . ' ran.',
[ 'ref' => $this->registry_id, 'key' => $key, 'value' => $value ]
Expand Down
21 changes: 18 additions & 3 deletions lib/abstracts/registries/Registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,15 @@ public function add( $key, $value ) {
do_action( 'underpin/registry/after_added_item', $this->registry_id, $key, $value );
if ( ! is_wp_error( underpin()->logger() ) ) {
underpin()->logger()->log(
'notice',
'debug',
'valid_event_added',
'A valid item registry item was registered.',
[ 'ref' => $this->registry_id, 'key' => $key, 'value' => $value, 'class' => get_called_class() ]
[
'ref' => $this->registry_id,
'key' => $key,
'value' => $value,
'class' => get_called_class()
]
);
}
} else {
Expand All @@ -139,7 +144,17 @@ public function get( $key ) {
if ( isset( $this[ $key ] ) ) {
return $this[$key];
} else {
$error = new WP_Error( 'key_not_set', 'Specified key is not set.', [ 'key' => $key ] );
$error = new WP_Error(
'key_not_set',
'Specified key is not set.',
[
'key' => $key,
'registry_id' => $this->registry_id,
'name' => $this->name,
'description' => $this->description,
'registry_type' => get_called_class(),
]
);

if ( 'logger' !== $key && ! is_wp_error( underpin()->logger() ) && underpin()->is_debug_mode_enabled() ) {
underpin()->logger()->log_wp_error( 'warning', $error );
Expand Down
9 changes: 7 additions & 2 deletions lib/traits/Templates.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,16 @@ public function get_template( $template_name, array $params = [] ) {
do_action( 'underpin/templates/invalid_template_file_doesnt_exist', $template_name, $params, $template_path, $template );
}
} else {
$class = __CLASS__;
$template = underpin()->logger()->log_as_error(
'error',
'underpin_invalid_template',
__( "Template $template_name was not loaded because it is not in the list of use-able templates for $class", 'underpin' )
"Template was not loaded because it is not in the list of use-able templates.",
[
'class' => get_called_class(),
'name' => $this->name,
'description' => $this->description,
'template' => $template_name,
]
);

/**
Expand Down

0 comments on commit 4d4dc4d

Please sign in to comment.