mirror of
https://hk.gh-proxy.com/https://github.com/wp-cli/profile-command.git
synced 2025-08-21 06:39:02 +08:00
Abstract to a dedicated helper method
This commit is contained in:
parent
a449366b66
commit
785c83949e
1 changed files with 18 additions and 8 deletions
|
@ -228,15 +228,8 @@ class Profile_Command {
|
|||
foreach ( (array) current($wp_filter[$tag]) as $i => $the_ )
|
||||
if ( !is_null($the_['function']) ) {
|
||||
if ( ! isset( $this->hook_log[ $i ] ) ) {
|
||||
if ( is_array( $the_['function'] ) && is_object( $the_['function'][0] ) ) {
|
||||
$callback = get_class( $the_['function'][0] ) . '->' . $the_['function'][1];
|
||||
} elseif ( is_array( $the_['function'] ) && method_exists( $the_['function'][0], $the_['function'][1] ) ) {
|
||||
$callback = $the_['function'][0] . '::' . $the_['function'][1];
|
||||
} elseif ( is_object( $the_['function'] ) && is_a( $the_['function'], 'Closure' ) ) {
|
||||
$callback = 'function(){}';
|
||||
}
|
||||
$this->hook_log[ $i ] = array(
|
||||
'callback' => $callback,
|
||||
'callback' => self::get_name_from_callback( $the_['function'] ),
|
||||
'execution_time' => 0,
|
||||
'query_count' => 0,
|
||||
'query_time' => 0,
|
||||
|
@ -371,4 +364,21 @@ class Profile_Command {
|
|||
$this->focus_start_time = microtime( true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a human-readable name from a callback
|
||||
*/
|
||||
private static function get_name_from_callback( $callback ) {
|
||||
$name = '';
|
||||
if ( is_array( $callback ) && is_object( $callback[0] ) ) {
|
||||
$name = get_class( $callback[0] ) . '->' . $callback[1] . '()';
|
||||
} elseif ( is_array( $callback ) && method_exists( $callback[0], $callback[1] ) ) {
|
||||
$name = $callback[0] . '::' . $callback[1] . '()';
|
||||
} elseif ( is_object( $callback ) && is_a( $callback, 'Closure' ) ) {
|
||||
$name = 'function(){}';
|
||||
} else if ( is_string( $callback ) ) {
|
||||
$name = $callback . '()';
|
||||
}
|
||||
return $name;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue