Skip to content

Commit

Permalink
Merge pull request #190 from wp-cli/fix/186
Browse files Browse the repository at this point in the history
Fix deprecation warnings on PHP 8.2
  • Loading branch information
swissspidy authored May 24, 2024
2 parents df98093 + 04c9da6 commit ab3b9d1
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 17 deletions.
42 changes: 29 additions & 13 deletions src/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 ] );
}

/**
Expand Down
14 changes: 10 additions & 4 deletions src/Profiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand All @@ -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 {
Expand Down

0 comments on commit ab3b9d1

Please sign in to comment.