Merge pull request #190 from wp-cli/fix/186

Fix deprecation warnings on PHP 8.2
This commit is contained in:
Pascal Birchler 2024-05-24 11:29:39 +02:00 committed by GitHub
commit ab3b9d18df
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 39 additions and 17 deletions

View file

@ -4,18 +4,16 @@ namespace WP_CLI\Profile;
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,14 +22,32 @@ 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 ] );
}
/**
* Start this logger
*/

View file

@ -99,8 +99,11 @@ class Profiler {
}
}
);
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 @@ class Profiler {
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 {