diff --git a/src/Logger.php b/src/Logger.php index b59e30a7..0c3ab116 100644 --- a/src/Logger.php +++ b/src/Logger.php @@ -4,18 +4,16 @@ class Logger { - public $time = 0; - public $query_count = 0; - public $query_time = 0; - public $cache_hits = 0; - public $cache_misses = 0; - public $cache_ratio = null; - public $hook_count = 0; - public $hook_time = 0; - public $request_count = 0; - public $request_time = 0; - public $callback_count = 0; - + public $time = 0; + public $query_count = 0; + public $query_time = 0; + public $cache_hits = 0; + public $cache_misses = 0; + public $cache_ratio = null; + public $hook_count = 0; + public $hook_time = 0; + public $request_count = 0; + public $request_time = 0; private $start_time = null; private $query_offset = null; private $cache_hit_offset = null; @@ -24,12 +22,30 @@ class Logger { private $hook_depth = 0; private $request_start_time = null; + private $definitions = array(); + public static $active_loggers = array(); public function __construct( $definition = array() ) { foreach ( $definition as $k => $v ) { - $this->$k = $v; + $this->definitions[ $k ] = $v; + } + } + + public function __get( $key ) { + if ( isset( $this->definitions[ $key ] ) ) { + return $this->definitions[ $key ]; } + + return null; + } + + public function __set( $key, $value ) { + $this->definitions[ $key ] = $value; + } + + public function __isset( $key ) { + return isset( $this->definitions[ $key ] ); } /** diff --git a/src/Profiler.php b/src/Profiler.php index 5c8e5acb..7d376575 100644 --- a/src/Profiler.php +++ b/src/Profiler.php @@ -99,8 +99,11 @@ function () { } } ); - if ( 'hook' === $this->type - && ':before' === substr( $this->focus, -7, 7 ) ) { + if ( + 'hook' === $this->type && + $this->focus && + ':before' === substr( $this->focus, -7, 7 ) + ) { $stage_hooks = array(); foreach ( $this->stage_hooks as $hooks ) { $stage_hooks = array_merge( $stage_hooks, $hooks ); @@ -114,8 +117,11 @@ function () { WP_CLI::add_hook( 'after_wp_config_load', array( $this, 'wp_tick_profile_begin' ) ); } WP_CLI::add_wp_hook( $end_hook, array( $this, 'wp_tick_profile_end' ), -9999 ); - } elseif ( 'hook' === $this->type - && ':after' === substr( $this->focus, -6, 6 ) ) { + } elseif ( + 'hook' === $this->type && + $this->focus && + ':after' === substr( $this->focus, -6, 6 ) + ) { $start_hook = substr( $this->focus, 0, -6 ); WP_CLI::add_wp_hook( $start_hook, array( $this, 'wp_tick_profile_begin' ), 9999 ); } else {