@@ -11,94 +11,94 @@ |
||
| 11 | 11 | |
| 12 | 12 | final class Application |
| 13 | 13 | { |
| 14 | - public const CONSOLE_HOOK = 'console'; |
|
| 15 | - public const ID = 'blackbar'; |
|
| 16 | - public const PROFILER_START_HOOK = 'timer:start'; |
|
| 17 | - public const PROFILER_STOP_HOOK = 'timer:stop'; |
|
| 14 | + public const CONSOLE_HOOK = 'console'; |
|
| 15 | + public const ID = 'blackbar'; |
|
| 16 | + public const PROFILER_START_HOOK = 'timer:start'; |
|
| 17 | + public const PROFILER_STOP_HOOK = 'timer:stop'; |
|
| 18 | 18 | |
| 19 | - public $actions; |
|
| 20 | - public $console; |
|
| 21 | - public $file; |
|
| 22 | - public $globals; |
|
| 23 | - public $profiler; |
|
| 24 | - public $queries; |
|
| 25 | - public $templates; |
|
| 19 | + public $actions; |
|
| 20 | + public $console; |
|
| 21 | + public $file; |
|
| 22 | + public $globals; |
|
| 23 | + public $profiler; |
|
| 24 | + public $queries; |
|
| 25 | + public $templates; |
|
| 26 | 26 | |
| 27 | - private static $instance; |
|
| 27 | + private static $instance; |
|
| 28 | 28 | |
| 29 | - public function __construct() |
|
| 30 | - { |
|
| 31 | - $file = wp_normalize_path((new \ReflectionClass($this))->getFileName()); |
|
| 32 | - $this->actions = new Actions($this); |
|
| 33 | - $this->console = new Console($this); |
|
| 34 | - $this->file = str_replace('plugin/Application', static::ID, $file); |
|
| 35 | - $this->globals = new Globals($this); |
|
| 36 | - $this->profiler = new Profiler($this); |
|
| 37 | - $this->queries = new Queries($this); |
|
| 38 | - $this->templates = new Templates($this); |
|
| 39 | - } |
|
| 29 | + public function __construct() |
|
| 30 | + { |
|
| 31 | + $file = wp_normalize_path((new \ReflectionClass($this))->getFileName()); |
|
| 32 | + $this->actions = new Actions($this); |
|
| 33 | + $this->console = new Console($this); |
|
| 34 | + $this->file = str_replace('plugin/Application', static::ID, $file); |
|
| 35 | + $this->globals = new Globals($this); |
|
| 36 | + $this->profiler = new Profiler($this); |
|
| 37 | + $this->queries = new Queries($this); |
|
| 38 | + $this->templates = new Templates($this); |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - public function errorHandler(int $errno, string $message, string $file, int $line): bool |
|
| 42 | - { |
|
| 43 | - $path = explode(ABSPATH, $file); |
|
| 44 | - $location = sprintf('%s:%s', array_pop($path), $line); |
|
| 45 | - $this->console->store($message, (string) $errno, $location); |
|
| 46 | - return true; |
|
| 47 | - } |
|
| 41 | + public function errorHandler(int $errno, string $message, string $file, int $line): bool |
|
| 42 | + { |
|
| 43 | + $path = explode(ABSPATH, $file); |
|
| 44 | + $location = sprintf('%s:%s', array_pop($path), $line); |
|
| 45 | + $this->console->store($message, (string) $errno, $location); |
|
| 46 | + return true; |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - public function init(): void |
|
| 50 | - { |
|
| 51 | - $controller = new Controller($this); |
|
| 52 | - add_action('all', [$controller, 'initActions']); |
|
| 53 | - add_action('all', [$controller, 'initConsole']); |
|
| 54 | - add_action('all', [$controller, 'initProfiler']); |
|
| 55 | - do_action('blackbar/profiler/start'); // start profiler |
|
| 56 | - do_action('blackbar/profiler/noise'); // measure profiler noise |
|
| 57 | - add_action('plugins_loaded', [$controller, 'registerLanguages']); |
|
| 58 | - add_action('init', function () use ($controller) { |
|
| 59 | - if (!apply_filters('blackbar/enabled', current_user_can('administrator'))) { |
|
| 60 | - return; |
|
| 61 | - } |
|
| 62 | - add_action('admin_enqueue_scripts', [$controller, 'enqueueAssets']); |
|
| 63 | - add_action('wp_enqueue_scripts', [$controller, 'enqueueAssets']); |
|
| 64 | - add_action('admin_footer', [$controller, 'renderBar'], 99999); |
|
| 65 | - add_action('wp_footer', [$controller, 'renderBar'], 99999); |
|
| 66 | - add_filter('admin_body_class', [$controller, 'filterBodyClasses']); |
|
| 67 | - }); |
|
| 68 | - set_error_handler([$this, 'errorHandler'], E_ALL | E_STRICT); |
|
| 69 | - } |
|
| 49 | + public function init(): void |
|
| 50 | + { |
|
| 51 | + $controller = new Controller($this); |
|
| 52 | + add_action('all', [$controller, 'initActions']); |
|
| 53 | + add_action('all', [$controller, 'initConsole']); |
|
| 54 | + add_action('all', [$controller, 'initProfiler']); |
|
| 55 | + do_action('blackbar/profiler/start'); // start profiler |
|
| 56 | + do_action('blackbar/profiler/noise'); // measure profiler noise |
|
| 57 | + add_action('plugins_loaded', [$controller, 'registerLanguages']); |
|
| 58 | + add_action('init', function () use ($controller) { |
|
| 59 | + if (!apply_filters('blackbar/enabled', current_user_can('administrator'))) { |
|
| 60 | + return; |
|
| 61 | + } |
|
| 62 | + add_action('admin_enqueue_scripts', [$controller, 'enqueueAssets']); |
|
| 63 | + add_action('wp_enqueue_scripts', [$controller, 'enqueueAssets']); |
|
| 64 | + add_action('admin_footer', [$controller, 'renderBar'], 99999); |
|
| 65 | + add_action('wp_footer', [$controller, 'renderBar'], 99999); |
|
| 66 | + add_filter('admin_body_class', [$controller, 'filterBodyClasses']); |
|
| 67 | + }); |
|
| 68 | + set_error_handler([$this, 'errorHandler'], E_ALL | E_STRICT); |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * @return static |
|
| 73 | - */ |
|
| 74 | - public static function load() |
|
| 75 | - { |
|
| 76 | - if (empty(static::$instance)) { |
|
| 77 | - static::$instance = new static(); |
|
| 78 | - } |
|
| 79 | - return static::$instance; |
|
| 80 | - } |
|
| 71 | + /** |
|
| 72 | + * @return static |
|
| 73 | + */ |
|
| 74 | + public static function load() |
|
| 75 | + { |
|
| 76 | + if (empty(static::$instance)) { |
|
| 77 | + static::$instance = new static(); |
|
| 78 | + } |
|
| 79 | + return static::$instance; |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - public function path(string $file = '', bool $realpath = true): string |
|
| 83 | - { |
|
| 84 | - $path = $realpath |
|
| 85 | - ? plugin_dir_path($this->file) |
|
| 86 | - : trailingslashit(WP_PLUGIN_DIR).basename(dirname($this->file)); |
|
| 87 | - return trailingslashit($path).ltrim(trim($file), '/'); |
|
| 88 | - } |
|
| 82 | + public function path(string $file = '', bool $realpath = true): string |
|
| 83 | + { |
|
| 84 | + $path = $realpath |
|
| 85 | + ? plugin_dir_path($this->file) |
|
| 86 | + : trailingslashit(WP_PLUGIN_DIR).basename(dirname($this->file)); |
|
| 87 | + return trailingslashit($path).ltrim(trim($file), '/'); |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | - public function render(string $view, array $data = []): void |
|
| 91 | - { |
|
| 92 | - $file = $this->path(sprintf('views/%s.php', str_replace('.php', '', $view))); |
|
| 93 | - if (!file_exists($file)) { |
|
| 94 | - return; |
|
| 95 | - } |
|
| 96 | - extract($data); |
|
| 97 | - include $file; |
|
| 98 | - } |
|
| 90 | + public function render(string $view, array $data = []): void |
|
| 91 | + { |
|
| 92 | + $file = $this->path(sprintf('views/%s.php', str_replace('.php', '', $view))); |
|
| 93 | + if (!file_exists($file)) { |
|
| 94 | + return; |
|
| 95 | + } |
|
| 96 | + extract($data); |
|
| 97 | + include $file; |
|
| 98 | + } |
|
| 99 | 99 | |
| 100 | - public function url(string $path = ''): string |
|
| 101 | - { |
|
| 102 | - return esc_url(plugin_dir_url($this->file).ltrim(trim($path), '/')); |
|
| 103 | - } |
|
| 100 | + public function url(string $path = ''): string |
|
| 101 | + { |
|
| 102 | + return esc_url(plugin_dir_url($this->file).ltrim(trim($path), '/')); |
|
| 103 | + } |
|
| 104 | 104 | } |
@@ -28,44 +28,44 @@ discard block |
||
| 28 | 28 | |
| 29 | 29 | public function __construct() |
| 30 | 30 | { |
| 31 | - $file = wp_normalize_path((new \ReflectionClass($this))->getFileName()); |
|
| 32 | - $this->actions = new Actions($this); |
|
| 33 | - $this->console = new Console($this); |
|
| 34 | - $this->file = str_replace('plugin/Application', static::ID, $file); |
|
| 35 | - $this->globals = new Globals($this); |
|
| 36 | - $this->profiler = new Profiler($this); |
|
| 37 | - $this->queries = new Queries($this); |
|
| 38 | - $this->templates = new Templates($this); |
|
| 31 | + $file = wp_normalize_path( ( new \ReflectionClass( $this ) )->getFileName() ); |
|
| 32 | + $this->actions = new Actions( $this ); |
|
| 33 | + $this->console = new Console( $this ); |
|
| 34 | + $this->file = str_replace( 'plugin/Application', static::ID, $file ); |
|
| 35 | + $this->globals = new Globals( $this ); |
|
| 36 | + $this->profiler = new Profiler( $this ); |
|
| 37 | + $this->queries = new Queries( $this ); |
|
| 38 | + $this->templates = new Templates( $this ); |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | - public function errorHandler(int $errno, string $message, string $file, int $line): bool |
|
| 41 | + public function errorHandler( int $errno, string $message, string $file, int $line ): bool |
|
| 42 | 42 | { |
| 43 | - $path = explode(ABSPATH, $file); |
|
| 44 | - $location = sprintf('%s:%s', array_pop($path), $line); |
|
| 45 | - $this->console->store($message, (string) $errno, $location); |
|
| 43 | + $path = explode( ABSPATH, $file ); |
|
| 44 | + $location = sprintf( '%s:%s', array_pop( $path ), $line ); |
|
| 45 | + $this->console->store( $message, (string) $errno, $location ); |
|
| 46 | 46 | return true; |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | public function init(): void |
| 50 | 50 | { |
| 51 | - $controller = new Controller($this); |
|
| 52 | - add_action('all', [$controller, 'initActions']); |
|
| 53 | - add_action('all', [$controller, 'initConsole']); |
|
| 54 | - add_action('all', [$controller, 'initProfiler']); |
|
| 55 | - do_action('blackbar/profiler/start'); // start profiler |
|
| 56 | - do_action('blackbar/profiler/noise'); // measure profiler noise |
|
| 57 | - add_action('plugins_loaded', [$controller, 'registerLanguages']); |
|
| 58 | - add_action('init', function () use ($controller) { |
|
| 59 | - if (!apply_filters('blackbar/enabled', current_user_can('administrator'))) { |
|
| 51 | + $controller = new Controller( $this ); |
|
| 52 | + add_action( 'all', [ $controller, 'initActions' ] ); |
|
| 53 | + add_action( 'all', [ $controller, 'initConsole' ] ); |
|
| 54 | + add_action( 'all', [ $controller, 'initProfiler' ] ); |
|
| 55 | + do_action( 'blackbar/profiler/start' ); // start profiler |
|
| 56 | + do_action( 'blackbar/profiler/noise' ); // measure profiler noise |
|
| 57 | + add_action( 'plugins_loaded', [ $controller, 'registerLanguages' ] ); |
|
| 58 | + add_action( 'init', function() use ( $controller ) { |
|
| 59 | + if( !apply_filters( 'blackbar/enabled', current_user_can( 'administrator' ) ) ) { |
|
| 60 | 60 | return; |
| 61 | 61 | } |
| 62 | - add_action('admin_enqueue_scripts', [$controller, 'enqueueAssets']); |
|
| 63 | - add_action('wp_enqueue_scripts', [$controller, 'enqueueAssets']); |
|
| 64 | - add_action('admin_footer', [$controller, 'renderBar'], 99999); |
|
| 65 | - add_action('wp_footer', [$controller, 'renderBar'], 99999); |
|
| 66 | - add_filter('admin_body_class', [$controller, 'filterBodyClasses']); |
|
| 62 | + add_action( 'admin_enqueue_scripts', [ $controller, 'enqueueAssets' ] ); |
|
| 63 | + add_action( 'wp_enqueue_scripts', [ $controller, 'enqueueAssets' ] ); |
|
| 64 | + add_action( 'admin_footer', [ $controller, 'renderBar' ], 99999 ); |
|
| 65 | + add_action( 'wp_footer', [ $controller, 'renderBar' ], 99999 ); |
|
| 66 | + add_filter( 'admin_body_class', [ $controller, 'filterBodyClasses' ] ); |
|
| 67 | 67 | }); |
| 68 | - set_error_handler([$this, 'errorHandler'], E_ALL | E_STRICT); |
|
| 68 | + set_error_handler( [ $this, 'errorHandler' ], E_ALL | E_STRICT ); |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | /** |
@@ -73,32 +73,32 @@ discard block |
||
| 73 | 73 | */ |
| 74 | 74 | public static function load() |
| 75 | 75 | { |
| 76 | - if (empty(static::$instance)) { |
|
| 76 | + if( empty( static::$instance ) ) { |
|
| 77 | 77 | static::$instance = new static(); |
| 78 | 78 | } |
| 79 | 79 | return static::$instance; |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | - public function path(string $file = '', bool $realpath = true): string |
|
| 82 | + public function path( string $file = '', bool $realpath = true ): string |
|
| 83 | 83 | { |
| 84 | 84 | $path = $realpath |
| 85 | - ? plugin_dir_path($this->file) |
|
| 86 | - : trailingslashit(WP_PLUGIN_DIR).basename(dirname($this->file)); |
|
| 87 | - return trailingslashit($path).ltrim(trim($file), '/'); |
|
| 85 | + ? plugin_dir_path( $this->file ) |
|
| 86 | + : trailingslashit( WP_PLUGIN_DIR ) . basename( dirname( $this->file ) ); |
|
| 87 | + return trailingslashit( $path ) . ltrim( trim( $file ), '/' ); |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | - public function render(string $view, array $data = []): void |
|
| 90 | + public function render( string $view, array $data = [ ] ): void |
|
| 91 | 91 | { |
| 92 | - $file = $this->path(sprintf('views/%s.php', str_replace('.php', '', $view))); |
|
| 93 | - if (!file_exists($file)) { |
|
| 92 | + $file = $this->path( sprintf( 'views/%s.php', str_replace( '.php', '', $view ) ) ); |
|
| 93 | + if( !file_exists( $file ) ) { |
|
| 94 | 94 | return; |
| 95 | 95 | } |
| 96 | - extract($data); |
|
| 96 | + extract( $data ); |
|
| 97 | 97 | include $file; |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | - public function url(string $path = ''): string |
|
| 100 | + public function url( string $path = '' ): string |
|
| 101 | 101 | { |
| 102 | - return esc_url(plugin_dir_url($this->file).ltrim(trim($path), '/')); |
|
| 102 | + return esc_url( plugin_dir_url( $this->file ) . ltrim( trim( $path ), '/' ) ); |
|
| 103 | 103 | } |
| 104 | 104 | } |
@@ -55,7 +55,8 @@ |
||
| 55 | 55 | do_action('blackbar/profiler/start'); // start profiler |
| 56 | 56 | do_action('blackbar/profiler/noise'); // measure profiler noise |
| 57 | 57 | add_action('plugins_loaded', [$controller, 'registerLanguages']); |
| 58 | - add_action('init', function () use ($controller) { |
|
| 58 | + add_action('init', function () use ($controller) |
|
| 59 | + { |
|
| 59 | 60 | if (!apply_filters('blackbar/enabled', current_user_can('administrator'))) { |
| 60 | 61 | return; |
| 61 | 62 | } |
@@ -6,75 +6,75 @@ |
||
| 6 | 6 | |
| 7 | 7 | class Globals implements Module |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * @var Application |
|
| 11 | - */ |
|
| 12 | - protected $app; |
|
| 13 | - /** |
|
| 14 | - * @var array |
|
| 15 | - */ |
|
| 16 | - protected $entries; |
|
| 9 | + /** |
|
| 10 | + * @var Application |
|
| 11 | + */ |
|
| 12 | + protected $app; |
|
| 13 | + /** |
|
| 14 | + * @var array |
|
| 15 | + */ |
|
| 16 | + protected $entries; |
|
| 17 | 17 | |
| 18 | - public function __construct(Application $app) |
|
| 19 | - { |
|
| 20 | - $this->app = $app; |
|
| 21 | - $this->entries = []; |
|
| 22 | - } |
|
| 18 | + public function __construct(Application $app) |
|
| 19 | + { |
|
| 20 | + $this->app = $app; |
|
| 21 | + $this->entries = []; |
|
| 22 | + } |
|
| 23 | 23 | |
| 24 | - public function entries(): array |
|
| 25 | - { |
|
| 26 | - if (!empty($this->entries)) { |
|
| 27 | - return $this->entries; |
|
| 28 | - } |
|
| 29 | - $globals = [ |
|
| 30 | - 'INPUT_COOKIE' => $_COOKIE, |
|
| 31 | - 'INPUT_ENV' => $_ENV, |
|
| 32 | - 'INPUT_GET' => $_GET, |
|
| 33 | - 'INPUT_POST' => $_POST, |
|
| 34 | - 'INPUT_SERVER' => $_SERVER, |
|
| 35 | - ]; |
|
| 36 | - if (is_admin() && $screen = get_current_screen()) { |
|
| 37 | - $reflection = new \ReflectionClass($screen); |
|
| 38 | - $properties = $reflection->getProperties(\ReflectionProperty::IS_PUBLIC); |
|
| 39 | - $values = []; |
|
| 40 | - foreach ($properties as $property) { |
|
| 41 | - $values[$property->getName()] = $property->getValue($screen); |
|
| 42 | - } |
|
| 43 | - $globals['WP_Screen'] = $values; |
|
| 44 | - } |
|
| 45 | - $globals = apply_filters('blackbar/globals', $globals); |
|
| 46 | - $globals = array_filter($globals); |
|
| 47 | - foreach ($globals as $key => $values) { |
|
| 48 | - $this->entries[] = [ |
|
| 49 | - 'name' => $key, |
|
| 50 | - 'value' => var_export($values, true), |
|
| 51 | - ]; |
|
| 52 | - } |
|
| 53 | - return $this->entries; |
|
| 54 | - } |
|
| 24 | + public function entries(): array |
|
| 25 | + { |
|
| 26 | + if (!empty($this->entries)) { |
|
| 27 | + return $this->entries; |
|
| 28 | + } |
|
| 29 | + $globals = [ |
|
| 30 | + 'INPUT_COOKIE' => $_COOKIE, |
|
| 31 | + 'INPUT_ENV' => $_ENV, |
|
| 32 | + 'INPUT_GET' => $_GET, |
|
| 33 | + 'INPUT_POST' => $_POST, |
|
| 34 | + 'INPUT_SERVER' => $_SERVER, |
|
| 35 | + ]; |
|
| 36 | + if (is_admin() && $screen = get_current_screen()) { |
|
| 37 | + $reflection = new \ReflectionClass($screen); |
|
| 38 | + $properties = $reflection->getProperties(\ReflectionProperty::IS_PUBLIC); |
|
| 39 | + $values = []; |
|
| 40 | + foreach ($properties as $property) { |
|
| 41 | + $values[$property->getName()] = $property->getValue($screen); |
|
| 42 | + } |
|
| 43 | + $globals['WP_Screen'] = $values; |
|
| 44 | + } |
|
| 45 | + $globals = apply_filters('blackbar/globals', $globals); |
|
| 46 | + $globals = array_filter($globals); |
|
| 47 | + foreach ($globals as $key => $values) { |
|
| 48 | + $this->entries[] = [ |
|
| 49 | + 'name' => $key, |
|
| 50 | + 'value' => var_export($values, true), |
|
| 51 | + ]; |
|
| 52 | + } |
|
| 53 | + return $this->entries; |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - public function hasEntries(): bool |
|
| 57 | - { |
|
| 58 | - return !empty($this->entries()); |
|
| 59 | - } |
|
| 56 | + public function hasEntries(): bool |
|
| 57 | + { |
|
| 58 | + return !empty($this->entries()); |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - public function id(): string |
|
| 62 | - { |
|
| 63 | - return 'glbb-globals'; |
|
| 64 | - } |
|
| 61 | + public function id(): string |
|
| 62 | + { |
|
| 63 | + return 'glbb-globals'; |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - public function isVisible(): bool |
|
| 67 | - { |
|
| 68 | - return true; |
|
| 69 | - } |
|
| 66 | + public function isVisible(): bool |
|
| 67 | + { |
|
| 68 | + return true; |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - public function label(): string |
|
| 72 | - { |
|
| 73 | - return __('Globals', 'blackbar'); |
|
| 74 | - } |
|
| 71 | + public function label(): string |
|
| 72 | + { |
|
| 73 | + return __('Globals', 'blackbar'); |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - public function render(): void |
|
| 77 | - { |
|
| 78 | - $this->app->render('panels/globals', ['globals' => $this]); |
|
| 79 | - } |
|
| 76 | + public function render(): void |
|
| 77 | + { |
|
| 78 | + $this->app->render('panels/globals', ['globals' => $this]); |
|
| 79 | + } |
|
| 80 | 80 | } |
@@ -15,15 +15,15 @@ discard block |
||
| 15 | 15 | */ |
| 16 | 16 | protected $entries; |
| 17 | 17 | |
| 18 | - public function __construct(Application $app) |
|
| 18 | + public function __construct( Application $app ) |
|
| 19 | 19 | { |
| 20 | 20 | $this->app = $app; |
| 21 | - $this->entries = []; |
|
| 21 | + $this->entries = [ ]; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | public function entries(): array |
| 25 | 25 | { |
| 26 | - if (!empty($this->entries)) { |
|
| 26 | + if( !empty( $this->entries ) ) { |
|
| 27 | 27 | return $this->entries; |
| 28 | 28 | } |
| 29 | 29 | $globals = [ |
@@ -33,21 +33,21 @@ discard block |
||
| 33 | 33 | 'INPUT_POST' => $_POST, |
| 34 | 34 | 'INPUT_SERVER' => $_SERVER, |
| 35 | 35 | ]; |
| 36 | - if (is_admin() && $screen = get_current_screen()) { |
|
| 37 | - $reflection = new \ReflectionClass($screen); |
|
| 38 | - $properties = $reflection->getProperties(\ReflectionProperty::IS_PUBLIC); |
|
| 39 | - $values = []; |
|
| 40 | - foreach ($properties as $property) { |
|
| 41 | - $values[$property->getName()] = $property->getValue($screen); |
|
| 36 | + if( is_admin() && $screen = get_current_screen() ) { |
|
| 37 | + $reflection = new \ReflectionClass( $screen ); |
|
| 38 | + $properties = $reflection->getProperties( \ReflectionProperty::IS_PUBLIC ); |
|
| 39 | + $values = [ ]; |
|
| 40 | + foreach( $properties as $property ) { |
|
| 41 | + $values[ $property->getName() ] = $property->getValue( $screen ); |
|
| 42 | 42 | } |
| 43 | - $globals['WP_Screen'] = $values; |
|
| 43 | + $globals[ 'WP_Screen' ] = $values; |
|
| 44 | 44 | } |
| 45 | - $globals = apply_filters('blackbar/globals', $globals); |
|
| 46 | - $globals = array_filter($globals); |
|
| 47 | - foreach ($globals as $key => $values) { |
|
| 48 | - $this->entries[] = [ |
|
| 45 | + $globals = apply_filters( 'blackbar/globals', $globals ); |
|
| 46 | + $globals = array_filter( $globals ); |
|
| 47 | + foreach( $globals as $key => $values ) { |
|
| 48 | + $this->entries[ ] = [ |
|
| 49 | 49 | 'name' => $key, |
| 50 | - 'value' => var_export($values, true), |
|
| 50 | + 'value' => var_export( $values, true ), |
|
| 51 | 51 | ]; |
| 52 | 52 | } |
| 53 | 53 | return $this->entries; |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | |
| 56 | 56 | public function hasEntries(): bool |
| 57 | 57 | { |
| 58 | - return !empty($this->entries()); |
|
| 58 | + return !empty( $this->entries() ); |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | public function id(): string |
@@ -70,11 +70,11 @@ discard block |
||
| 70 | 70 | |
| 71 | 71 | public function label(): string |
| 72 | 72 | { |
| 73 | - return __('Globals', 'blackbar'); |
|
| 73 | + return __( 'Globals', 'blackbar' ); |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | public function render(): void |
| 77 | 77 | { |
| 78 | - $this->app->render('panels/globals', ['globals' => $this]); |
|
| 78 | + $this->app->render( 'panels/globals', [ 'globals' => $this ] ); |
|
| 79 | 79 | } |
| 80 | 80 | } |
@@ -6,130 +6,130 @@ |
||
| 6 | 6 | |
| 7 | 7 | class Profiler implements Module |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * @var Application |
|
| 11 | - */ |
|
| 12 | - protected $app; |
|
| 13 | - /** |
|
| 14 | - * @var float |
|
| 15 | - */ |
|
| 16 | - protected $noise; |
|
| 17 | - /** |
|
| 18 | - * @var float |
|
| 19 | - */ |
|
| 20 | - protected $start; |
|
| 21 | - /** |
|
| 22 | - * @var float |
|
| 23 | - */ |
|
| 24 | - protected $stop; |
|
| 25 | - /** |
|
| 26 | - * @var array |
|
| 27 | - */ |
|
| 28 | - protected $timer; |
|
| 29 | - /** |
|
| 30 | - * @var array |
|
| 31 | - */ |
|
| 32 | - protected $timers; |
|
| 33 | - |
|
| 34 | - public function __construct(Application $app) |
|
| 35 | - { |
|
| 36 | - $this->app = $app; |
|
| 37 | - $this->noise = floatval(0); |
|
| 38 | - $this->start = floatval(0); |
|
| 39 | - $this->stop = floatval(0); |
|
| 40 | - $this->timer = []; |
|
| 41 | - $this->timers = []; |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - public function entries(): array |
|
| 45 | - { |
|
| 46 | - $entries = []; |
|
| 47 | - foreach ($this->timers as $timer) { |
|
| 48 | - $timer['memory'] = round($timer['memory'] / 1000); // convert bytes to KB |
|
| 49 | - $timer['time'] = $this->formatTime($timer['time']); |
|
| 50 | - $entries[] = $timer; |
|
| 51 | - } |
|
| 52 | - return $entries; |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - public function hasEntries(): bool |
|
| 56 | - { |
|
| 57 | - return !empty($this->timers); |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - public function id(): string |
|
| 61 | - { |
|
| 62 | - return 'glbb-profiler'; |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - public function isVisible(): bool |
|
| 66 | - { |
|
| 67 | - return !empty($this->timers); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - public function label(): string |
|
| 71 | - { |
|
| 72 | - $label = __('Profiler', 'blackbar'); |
|
| 73 | - $time = $this->totalTime(); |
|
| 74 | - if ($time > 0) { |
|
| 75 | - $info = sprintf('<span class="glbb-link-info">(%s)</span>', $this->formatTime($time)); |
|
| 76 | - $label = sprintf('%s %s', $label, $info); |
|
| 77 | - } |
|
| 78 | - return $label; |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - public function render(): void |
|
| 82 | - { |
|
| 83 | - $this->app->render('panels/profiler', ['profiler' => $this]); |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - public function setNoise(float $microtime): void |
|
| 87 | - { |
|
| 88 | - $this->noise = $this->start - $microtime; |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - public function setStart(float $microtime): void |
|
| 92 | - { |
|
| 93 | - $this->start = $microtime; |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - public function setStop(float $microtime): void |
|
| 97 | - { |
|
| 98 | - $this->stop = $microtime; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - public function start(string $name): void |
|
| 102 | - { |
|
| 103 | - $this->timer = [ |
|
| 104 | - 'memory' => memory_get_peak_usage(), |
|
| 105 | - 'name' => $name, |
|
| 106 | - 'start' => microtime(true), |
|
| 107 | - 'stop' => floatval(0), |
|
| 108 | - 'time' => floatval(0), |
|
| 109 | - ]; |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - public function stop(string $name): void |
|
| 113 | - { |
|
| 114 | - if (empty($this->timer)) { |
|
| 115 | - return; |
|
| 116 | - } |
|
| 117 | - $this->timer['stop'] = microtime(true) - $this->noise; |
|
| 118 | - $this->timer['time'] = $this->timer['stop'] - $this->timer['start']; |
|
| 119 | - $this->timers[] = $this->timer; |
|
| 120 | - $this->timer = []; // reset timer |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - public function totalTime(): float |
|
| 124 | - { |
|
| 125 | - return array_sum(wp_list_pluck($this->timers, 'time')); |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - protected function formatTime(float $time): string |
|
| 129 | - { |
|
| 130 | - if ($time < 100) { |
|
| 131 | - return sprintf('%.3f µs', $time); |
|
| 132 | - } |
|
| 133 | - return sprintf('%.3f ms', $time * 1000); |
|
| 134 | - } |
|
| 9 | + /** |
|
| 10 | + * @var Application |
|
| 11 | + */ |
|
| 12 | + protected $app; |
|
| 13 | + /** |
|
| 14 | + * @var float |
|
| 15 | + */ |
|
| 16 | + protected $noise; |
|
| 17 | + /** |
|
| 18 | + * @var float |
|
| 19 | + */ |
|
| 20 | + protected $start; |
|
| 21 | + /** |
|
| 22 | + * @var float |
|
| 23 | + */ |
|
| 24 | + protected $stop; |
|
| 25 | + /** |
|
| 26 | + * @var array |
|
| 27 | + */ |
|
| 28 | + protected $timer; |
|
| 29 | + /** |
|
| 30 | + * @var array |
|
| 31 | + */ |
|
| 32 | + protected $timers; |
|
| 33 | + |
|
| 34 | + public function __construct(Application $app) |
|
| 35 | + { |
|
| 36 | + $this->app = $app; |
|
| 37 | + $this->noise = floatval(0); |
|
| 38 | + $this->start = floatval(0); |
|
| 39 | + $this->stop = floatval(0); |
|
| 40 | + $this->timer = []; |
|
| 41 | + $this->timers = []; |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + public function entries(): array |
|
| 45 | + { |
|
| 46 | + $entries = []; |
|
| 47 | + foreach ($this->timers as $timer) { |
|
| 48 | + $timer['memory'] = round($timer['memory'] / 1000); // convert bytes to KB |
|
| 49 | + $timer['time'] = $this->formatTime($timer['time']); |
|
| 50 | + $entries[] = $timer; |
|
| 51 | + } |
|
| 52 | + return $entries; |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + public function hasEntries(): bool |
|
| 56 | + { |
|
| 57 | + return !empty($this->timers); |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + public function id(): string |
|
| 61 | + { |
|
| 62 | + return 'glbb-profiler'; |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + public function isVisible(): bool |
|
| 66 | + { |
|
| 67 | + return !empty($this->timers); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + public function label(): string |
|
| 71 | + { |
|
| 72 | + $label = __('Profiler', 'blackbar'); |
|
| 73 | + $time = $this->totalTime(); |
|
| 74 | + if ($time > 0) { |
|
| 75 | + $info = sprintf('<span class="glbb-link-info">(%s)</span>', $this->formatTime($time)); |
|
| 76 | + $label = sprintf('%s %s', $label, $info); |
|
| 77 | + } |
|
| 78 | + return $label; |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + public function render(): void |
|
| 82 | + { |
|
| 83 | + $this->app->render('panels/profiler', ['profiler' => $this]); |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + public function setNoise(float $microtime): void |
|
| 87 | + { |
|
| 88 | + $this->noise = $this->start - $microtime; |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + public function setStart(float $microtime): void |
|
| 92 | + { |
|
| 93 | + $this->start = $microtime; |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + public function setStop(float $microtime): void |
|
| 97 | + { |
|
| 98 | + $this->stop = $microtime; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + public function start(string $name): void |
|
| 102 | + { |
|
| 103 | + $this->timer = [ |
|
| 104 | + 'memory' => memory_get_peak_usage(), |
|
| 105 | + 'name' => $name, |
|
| 106 | + 'start' => microtime(true), |
|
| 107 | + 'stop' => floatval(0), |
|
| 108 | + 'time' => floatval(0), |
|
| 109 | + ]; |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + public function stop(string $name): void |
|
| 113 | + { |
|
| 114 | + if (empty($this->timer)) { |
|
| 115 | + return; |
|
| 116 | + } |
|
| 117 | + $this->timer['stop'] = microtime(true) - $this->noise; |
|
| 118 | + $this->timer['time'] = $this->timer['stop'] - $this->timer['start']; |
|
| 119 | + $this->timers[] = $this->timer; |
|
| 120 | + $this->timer = []; // reset timer |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + public function totalTime(): float |
|
| 124 | + { |
|
| 125 | + return array_sum(wp_list_pluck($this->timers, 'time')); |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + protected function formatTime(float $time): string |
|
| 129 | + { |
|
| 130 | + if ($time < 100) { |
|
| 131 | + return sprintf('%.3f µs', $time); |
|
| 132 | + } |
|
| 133 | + return sprintf('%.3f ms', $time * 1000); |
|
| 134 | + } |
|
| 135 | 135 | } |
@@ -31,30 +31,30 @@ discard block |
||
| 31 | 31 | */ |
| 32 | 32 | protected $timers; |
| 33 | 33 | |
| 34 | - public function __construct(Application $app) |
|
| 34 | + public function __construct( Application $app ) |
|
| 35 | 35 | { |
| 36 | 36 | $this->app = $app; |
| 37 | - $this->noise = floatval(0); |
|
| 38 | - $this->start = floatval(0); |
|
| 39 | - $this->stop = floatval(0); |
|
| 40 | - $this->timer = []; |
|
| 41 | - $this->timers = []; |
|
| 37 | + $this->noise = floatval( 0 ); |
|
| 38 | + $this->start = floatval( 0 ); |
|
| 39 | + $this->stop = floatval( 0 ); |
|
| 40 | + $this->timer = [ ]; |
|
| 41 | + $this->timers = [ ]; |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | public function entries(): array |
| 45 | 45 | { |
| 46 | - $entries = []; |
|
| 47 | - foreach ($this->timers as $timer) { |
|
| 48 | - $timer['memory'] = round($timer['memory'] / 1000); // convert bytes to KB |
|
| 49 | - $timer['time'] = $this->formatTime($timer['time']); |
|
| 50 | - $entries[] = $timer; |
|
| 46 | + $entries = [ ]; |
|
| 47 | + foreach( $this->timers as $timer ) { |
|
| 48 | + $timer[ 'memory' ] = round( $timer[ 'memory' ] / 1000 ); // convert bytes to KB |
|
| 49 | + $timer[ 'time' ] = $this->formatTime( $timer[ 'time' ] ); |
|
| 50 | + $entries[ ] = $timer; |
|
| 51 | 51 | } |
| 52 | 52 | return $entries; |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | public function hasEntries(): bool |
| 56 | 56 | { |
| 57 | - return !empty($this->timers); |
|
| 57 | + return !empty( $this->timers ); |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | public function id(): string |
@@ -64,72 +64,72 @@ discard block |
||
| 64 | 64 | |
| 65 | 65 | public function isVisible(): bool |
| 66 | 66 | { |
| 67 | - return !empty($this->timers); |
|
| 67 | + return !empty( $this->timers ); |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | public function label(): string |
| 71 | 71 | { |
| 72 | - $label = __('Profiler', 'blackbar'); |
|
| 72 | + $label = __( 'Profiler', 'blackbar' ); |
|
| 73 | 73 | $time = $this->totalTime(); |
| 74 | - if ($time > 0) { |
|
| 75 | - $info = sprintf('<span class="glbb-link-info">(%s)</span>', $this->formatTime($time)); |
|
| 76 | - $label = sprintf('%s %s', $label, $info); |
|
| 74 | + if( $time > 0 ) { |
|
| 75 | + $info = sprintf( '<span class="glbb-link-info">(%s)</span>', $this->formatTime( $time ) ); |
|
| 76 | + $label = sprintf( '%s %s', $label, $info ); |
|
| 77 | 77 | } |
| 78 | 78 | return $label; |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | public function render(): void |
| 82 | 82 | { |
| 83 | - $this->app->render('panels/profiler', ['profiler' => $this]); |
|
| 83 | + $this->app->render( 'panels/profiler', [ 'profiler' => $this ] ); |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | - public function setNoise(float $microtime): void |
|
| 86 | + public function setNoise( float $microtime ): void |
|
| 87 | 87 | { |
| 88 | 88 | $this->noise = $this->start - $microtime; |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | - public function setStart(float $microtime): void |
|
| 91 | + public function setStart( float $microtime ): void |
|
| 92 | 92 | { |
| 93 | 93 | $this->start = $microtime; |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | - public function setStop(float $microtime): void |
|
| 96 | + public function setStop( float $microtime ): void |
|
| 97 | 97 | { |
| 98 | 98 | $this->stop = $microtime; |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | - public function start(string $name): void |
|
| 101 | + public function start( string $name ): void |
|
| 102 | 102 | { |
| 103 | 103 | $this->timer = [ |
| 104 | 104 | 'memory' => memory_get_peak_usage(), |
| 105 | 105 | 'name' => $name, |
| 106 | - 'start' => microtime(true), |
|
| 107 | - 'stop' => floatval(0), |
|
| 108 | - 'time' => floatval(0), |
|
| 106 | + 'start' => microtime( true ), |
|
| 107 | + 'stop' => floatval( 0 ), |
|
| 108 | + 'time' => floatval( 0 ), |
|
| 109 | 109 | ]; |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | - public function stop(string $name): void |
|
| 112 | + public function stop( string $name ): void |
|
| 113 | 113 | { |
| 114 | - if (empty($this->timer)) { |
|
| 114 | + if( empty( $this->timer ) ) { |
|
| 115 | 115 | return; |
| 116 | 116 | } |
| 117 | - $this->timer['stop'] = microtime(true) - $this->noise; |
|
| 118 | - $this->timer['time'] = $this->timer['stop'] - $this->timer['start']; |
|
| 119 | - $this->timers[] = $this->timer; |
|
| 120 | - $this->timer = []; // reset timer |
|
| 117 | + $this->timer[ 'stop' ] = microtime( true ) - $this->noise; |
|
| 118 | + $this->timer[ 'time' ] = $this->timer[ 'stop' ] - $this->timer[ 'start' ]; |
|
| 119 | + $this->timers[ ] = $this->timer; |
|
| 120 | + $this->timer = [ ]; // reset timer |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | public function totalTime(): float |
| 124 | 124 | { |
| 125 | - return array_sum(wp_list_pluck($this->timers, 'time')); |
|
| 125 | + return array_sum( wp_list_pluck( $this->timers, 'time' ) ); |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | - protected function formatTime(float $time): string |
|
| 128 | + protected function formatTime( float $time ): string |
|
| 129 | 129 | { |
| 130 | - if ($time < 100) { |
|
| 131 | - return sprintf('%.3f µs', $time); |
|
| 130 | + if( $time < 100 ) { |
|
| 131 | + return sprintf( '%.3f µs', $time ); |
|
| 132 | 132 | } |
| 133 | - return sprintf('%.3f ms', $time * 1000); |
|
| 133 | + return sprintf( '%.3f ms', $time * 1000 ); |
|
| 134 | 134 | } |
| 135 | 135 | } |
@@ -6,100 +6,100 @@ |
||
| 6 | 6 | |
| 7 | 7 | class Queries implements Module |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * @var Application |
|
| 11 | - */ |
|
| 12 | - protected $app; |
|
| 9 | + /** |
|
| 10 | + * @var Application |
|
| 11 | + */ |
|
| 12 | + protected $app; |
|
| 13 | 13 | |
| 14 | - public function __construct(Application $app) |
|
| 15 | - { |
|
| 16 | - $this->app = $app; |
|
| 17 | - } |
|
| 14 | + public function __construct(Application $app) |
|
| 15 | + { |
|
| 16 | + $this->app = $app; |
|
| 17 | + } |
|
| 18 | 18 | |
| 19 | - public function entries(): array |
|
| 20 | - { |
|
| 21 | - global $wpdb; |
|
| 22 | - $entries = []; |
|
| 23 | - $index = 0; |
|
| 24 | - $search = [ |
|
| 25 | - 'FROM', 'GROUP BY', 'INNER JOIN', 'LEFT JOIN', 'LIMIT', |
|
| 26 | - 'ON DUPLICATE KEY UPDATE', 'ORDER BY', 'OFFSET', ' SET', 'WHERE', |
|
| 27 | - ]; |
|
| 28 | - $replace = array_map(function ($value) { |
|
| 29 | - return PHP_EOL.$value; |
|
| 30 | - }, $search); |
|
| 31 | - foreach ($wpdb->queries as $query) { |
|
| 32 | - $miliseconds = number_format(round($query[1] * 1000, 4), 4); |
|
| 33 | - $sql = preg_replace('/\s\s+/', ' ', trim($query[0])); |
|
| 34 | - $sql = str_replace(PHP_EOL, ' ', $sql); |
|
| 35 | - $sql = str_replace(['( ',' )',' ,'], ['(',')',','], $sql); |
|
| 36 | - $sql = str_replace($search, $replace, $sql); |
|
| 37 | - $parts = explode(PHP_EOL, $sql); |
|
| 38 | - $sql = array_reduce($parts, function ($carry, $part) { |
|
| 39 | - if (str_starts_with($part, 'SELECT') && strlen($part) > 100) { |
|
| 40 | - $part = preg_replace('/\s*(,)\s*/', ','.PHP_EOL.' ', $part); |
|
| 41 | - } |
|
| 42 | - if (str_starts_with($part, 'WHERE')) { |
|
| 43 | - $part = str_replace('AND', PHP_EOL.' AND', $part); |
|
| 44 | - } |
|
| 45 | - return $carry.$part.PHP_EOL; |
|
| 46 | - }); |
|
| 47 | - $trace = explode(', ', $query[2]); |
|
| 48 | - $entries[] = [ |
|
| 49 | - 'index' => $index++, |
|
| 50 | - 'sql' => $sql, |
|
| 51 | - 'time' => $miliseconds, |
|
| 52 | - 'trace' => array_reverse($trace, true), |
|
| 53 | - ]; |
|
| 54 | - } |
|
| 55 | - uasort($entries, [$this, 'sortByTime']); |
|
| 56 | - return $entries; |
|
| 57 | - } |
|
| 19 | + public function entries(): array |
|
| 20 | + { |
|
| 21 | + global $wpdb; |
|
| 22 | + $entries = []; |
|
| 23 | + $index = 0; |
|
| 24 | + $search = [ |
|
| 25 | + 'FROM', 'GROUP BY', 'INNER JOIN', 'LEFT JOIN', 'LIMIT', |
|
| 26 | + 'ON DUPLICATE KEY UPDATE', 'ORDER BY', 'OFFSET', ' SET', 'WHERE', |
|
| 27 | + ]; |
|
| 28 | + $replace = array_map(function ($value) { |
|
| 29 | + return PHP_EOL.$value; |
|
| 30 | + }, $search); |
|
| 31 | + foreach ($wpdb->queries as $query) { |
|
| 32 | + $miliseconds = number_format(round($query[1] * 1000, 4), 4); |
|
| 33 | + $sql = preg_replace('/\s\s+/', ' ', trim($query[0])); |
|
| 34 | + $sql = str_replace(PHP_EOL, ' ', $sql); |
|
| 35 | + $sql = str_replace(['( ',' )',' ,'], ['(',')',','], $sql); |
|
| 36 | + $sql = str_replace($search, $replace, $sql); |
|
| 37 | + $parts = explode(PHP_EOL, $sql); |
|
| 38 | + $sql = array_reduce($parts, function ($carry, $part) { |
|
| 39 | + if (str_starts_with($part, 'SELECT') && strlen($part) > 100) { |
|
| 40 | + $part = preg_replace('/\s*(,)\s*/', ','.PHP_EOL.' ', $part); |
|
| 41 | + } |
|
| 42 | + if (str_starts_with($part, 'WHERE')) { |
|
| 43 | + $part = str_replace('AND', PHP_EOL.' AND', $part); |
|
| 44 | + } |
|
| 45 | + return $carry.$part.PHP_EOL; |
|
| 46 | + }); |
|
| 47 | + $trace = explode(', ', $query[2]); |
|
| 48 | + $entries[] = [ |
|
| 49 | + 'index' => $index++, |
|
| 50 | + 'sql' => $sql, |
|
| 51 | + 'time' => $miliseconds, |
|
| 52 | + 'trace' => array_reverse($trace, true), |
|
| 53 | + ]; |
|
| 54 | + } |
|
| 55 | + uasort($entries, [$this, 'sortByTime']); |
|
| 56 | + return $entries; |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - public function hasEntries(): bool |
|
| 60 | - { |
|
| 61 | - global $wpdb; |
|
| 62 | - return !empty($wpdb->queries); |
|
| 63 | - } |
|
| 59 | + public function hasEntries(): bool |
|
| 60 | + { |
|
| 61 | + global $wpdb; |
|
| 62 | + return !empty($wpdb->queries); |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - public function id(): string |
|
| 66 | - { |
|
| 67 | - return 'glbb-queries'; |
|
| 68 | - } |
|
| 65 | + public function id(): string |
|
| 66 | + { |
|
| 67 | + return 'glbb-queries'; |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | - public function isVisible(): bool |
|
| 71 | - { |
|
| 72 | - return true; |
|
| 73 | - } |
|
| 70 | + public function isVisible(): bool |
|
| 71 | + { |
|
| 72 | + return true; |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - public function label(): string |
|
| 76 | - { |
|
| 77 | - $label = __('SQL', 'blackbar'); |
|
| 78 | - if (!defined('SAVEQUERIES') || !SAVEQUERIES) { |
|
| 79 | - return $label; |
|
| 80 | - } |
|
| 81 | - global $wpdb; |
|
| 82 | - $queryTime = 0; |
|
| 83 | - foreach ($wpdb->queries as $query) { |
|
| 84 | - $queryTime += $query[1]; |
|
| 85 | - } |
|
| 86 | - $queryTime = number_format($queryTime * 1000, 2); |
|
| 87 | - $queriesCount = sprintf('<span class="glbb-queries-count">%s</span>', count($wpdb->queries)); |
|
| 88 | - $queriesTime = sprintf('<span class="glbb-queries-time">%s</span>', $queryTime); |
|
| 89 | - $info = sprintf('<span class="glbb-link-info">(%s / %s ms)</span>', $queriesCount, $queriesTime); |
|
| 90 | - return sprintf('%s %s', $label, $info); |
|
| 91 | - } |
|
| 75 | + public function label(): string |
|
| 76 | + { |
|
| 77 | + $label = __('SQL', 'blackbar'); |
|
| 78 | + if (!defined('SAVEQUERIES') || !SAVEQUERIES) { |
|
| 79 | + return $label; |
|
| 80 | + } |
|
| 81 | + global $wpdb; |
|
| 82 | + $queryTime = 0; |
|
| 83 | + foreach ($wpdb->queries as $query) { |
|
| 84 | + $queryTime += $query[1]; |
|
| 85 | + } |
|
| 86 | + $queryTime = number_format($queryTime * 1000, 2); |
|
| 87 | + $queriesCount = sprintf('<span class="glbb-queries-count">%s</span>', count($wpdb->queries)); |
|
| 88 | + $queriesTime = sprintf('<span class="glbb-queries-time">%s</span>', $queryTime); |
|
| 89 | + $info = sprintf('<span class="glbb-link-info">(%s / %s ms)</span>', $queriesCount, $queriesTime); |
|
| 90 | + return sprintf('%s %s', $label, $info); |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - public function render(): void |
|
| 94 | - { |
|
| 95 | - $this->app->render('panels/queries', ['queries' => $this]); |
|
| 96 | - } |
|
| 93 | + public function render(): void |
|
| 94 | + { |
|
| 95 | + $this->app->render('panels/queries', ['queries' => $this]); |
|
| 96 | + } |
|
| 97 | 97 | |
| 98 | - protected function sortByTime(array $a, array $b): int |
|
| 99 | - { |
|
| 100 | - if ($a['time'] !== $b['time']) { |
|
| 101 | - return ($a['time'] > $b['time']) ? -1 : 1; |
|
| 102 | - } |
|
| 103 | - return 0; |
|
| 104 | - } |
|
| 98 | + protected function sortByTime(array $a, array $b): int |
|
| 99 | + { |
|
| 100 | + if ($a['time'] !== $b['time']) { |
|
| 101 | + return ($a['time'] > $b['time']) ? -1 : 1; |
|
| 102 | + } |
|
| 103 | + return 0; |
|
| 104 | + } |
|
| 105 | 105 | } |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | */ |
| 12 | 12 | protected $app; |
| 13 | 13 | |
| 14 | - public function __construct(Application $app) |
|
| 14 | + public function __construct( Application $app ) |
|
| 15 | 15 | { |
| 16 | 16 | $this->app = $app; |
| 17 | 17 | } |
@@ -19,47 +19,47 @@ discard block |
||
| 19 | 19 | public function entries(): array |
| 20 | 20 | { |
| 21 | 21 | global $wpdb; |
| 22 | - $entries = []; |
|
| 22 | + $entries = [ ]; |
|
| 23 | 23 | $index = 0; |
| 24 | 24 | $search = [ |
| 25 | 25 | 'FROM', 'GROUP BY', 'INNER JOIN', 'LEFT JOIN', 'LIMIT', |
| 26 | 26 | 'ON DUPLICATE KEY UPDATE', 'ORDER BY', 'OFFSET', ' SET', 'WHERE', |
| 27 | 27 | ]; |
| 28 | - $replace = array_map(function ($value) { |
|
| 29 | - return PHP_EOL.$value; |
|
| 30 | - }, $search); |
|
| 31 | - foreach ($wpdb->queries as $query) { |
|
| 32 | - $miliseconds = number_format(round($query[1] * 1000, 4), 4); |
|
| 33 | - $sql = preg_replace('/\s\s+/', ' ', trim($query[0])); |
|
| 34 | - $sql = str_replace(PHP_EOL, ' ', $sql); |
|
| 35 | - $sql = str_replace(['( ',' )',' ,'], ['(',')',','], $sql); |
|
| 36 | - $sql = str_replace($search, $replace, $sql); |
|
| 37 | - $parts = explode(PHP_EOL, $sql); |
|
| 38 | - $sql = array_reduce($parts, function ($carry, $part) { |
|
| 39 | - if (str_starts_with($part, 'SELECT') && strlen($part) > 100) { |
|
| 40 | - $part = preg_replace('/\s*(,)\s*/', ','.PHP_EOL.' ', $part); |
|
| 28 | + $replace = array_map( function( $value ) { |
|
| 29 | + return PHP_EOL . $value; |
|
| 30 | + }, $search ); |
|
| 31 | + foreach( $wpdb->queries as $query ) { |
|
| 32 | + $miliseconds = number_format( round( $query[ 1 ] * 1000, 4 ), 4 ); |
|
| 33 | + $sql = preg_replace( '/\s\s+/', ' ', trim( $query[ 0 ] ) ); |
|
| 34 | + $sql = str_replace( PHP_EOL, ' ', $sql ); |
|
| 35 | + $sql = str_replace( [ '( ', ' )', ' ,' ], [ '(', ')', ',' ], $sql ); |
|
| 36 | + $sql = str_replace( $search, $replace, $sql ); |
|
| 37 | + $parts = explode( PHP_EOL, $sql ); |
|
| 38 | + $sql = array_reduce( $parts, function( $carry, $part ) { |
|
| 39 | + if( str_starts_with( $part, 'SELECT' ) && strlen( $part ) > 100 ) { |
|
| 40 | + $part = preg_replace( '/\s*(,)\s*/', ',' . PHP_EOL . ' ', $part ); |
|
| 41 | 41 | } |
| 42 | - if (str_starts_with($part, 'WHERE')) { |
|
| 43 | - $part = str_replace('AND', PHP_EOL.' AND', $part); |
|
| 42 | + if( str_starts_with( $part, 'WHERE' ) ) { |
|
| 43 | + $part = str_replace( 'AND', PHP_EOL . ' AND', $part ); |
|
| 44 | 44 | } |
| 45 | - return $carry.$part.PHP_EOL; |
|
| 45 | + return $carry . $part . PHP_EOL; |
|
| 46 | 46 | }); |
| 47 | - $trace = explode(', ', $query[2]); |
|
| 48 | - $entries[] = [ |
|
| 47 | + $trace = explode( ', ', $query[ 2 ] ); |
|
| 48 | + $entries[ ] = [ |
|
| 49 | 49 | 'index' => $index++, |
| 50 | 50 | 'sql' => $sql, |
| 51 | 51 | 'time' => $miliseconds, |
| 52 | - 'trace' => array_reverse($trace, true), |
|
| 52 | + 'trace' => array_reverse( $trace, true ), |
|
| 53 | 53 | ]; |
| 54 | 54 | } |
| 55 | - uasort($entries, [$this, 'sortByTime']); |
|
| 55 | + uasort( $entries, [ $this, 'sortByTime' ] ); |
|
| 56 | 56 | return $entries; |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | public function hasEntries(): bool |
| 60 | 60 | { |
| 61 | 61 | global $wpdb; |
| 62 | - return !empty($wpdb->queries); |
|
| 62 | + return !empty( $wpdb->queries ); |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | public function id(): string |
@@ -74,31 +74,31 @@ discard block |
||
| 74 | 74 | |
| 75 | 75 | public function label(): string |
| 76 | 76 | { |
| 77 | - $label = __('SQL', 'blackbar'); |
|
| 78 | - if (!defined('SAVEQUERIES') || !SAVEQUERIES) { |
|
| 77 | + $label = __( 'SQL', 'blackbar' ); |
|
| 78 | + if( !defined( 'SAVEQUERIES' ) || !SAVEQUERIES ) { |
|
| 79 | 79 | return $label; |
| 80 | 80 | } |
| 81 | 81 | global $wpdb; |
| 82 | 82 | $queryTime = 0; |
| 83 | - foreach ($wpdb->queries as $query) { |
|
| 84 | - $queryTime += $query[1]; |
|
| 83 | + foreach( $wpdb->queries as $query ) { |
|
| 84 | + $queryTime += $query[ 1 ]; |
|
| 85 | 85 | } |
| 86 | - $queryTime = number_format($queryTime * 1000, 2); |
|
| 87 | - $queriesCount = sprintf('<span class="glbb-queries-count">%s</span>', count($wpdb->queries)); |
|
| 88 | - $queriesTime = sprintf('<span class="glbb-queries-time">%s</span>', $queryTime); |
|
| 89 | - $info = sprintf('<span class="glbb-link-info">(%s / %s ms)</span>', $queriesCount, $queriesTime); |
|
| 90 | - return sprintf('%s %s', $label, $info); |
|
| 86 | + $queryTime = number_format( $queryTime * 1000, 2 ); |
|
| 87 | + $queriesCount = sprintf( '<span class="glbb-queries-count">%s</span>', count( $wpdb->queries ) ); |
|
| 88 | + $queriesTime = sprintf( '<span class="glbb-queries-time">%s</span>', $queryTime ); |
|
| 89 | + $info = sprintf( '<span class="glbb-link-info">(%s / %s ms)</span>', $queriesCount, $queriesTime ); |
|
| 90 | + return sprintf( '%s %s', $label, $info ); |
|
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | public function render(): void |
| 94 | 94 | { |
| 95 | - $this->app->render('panels/queries', ['queries' => $this]); |
|
| 95 | + $this->app->render( 'panels/queries', [ 'queries' => $this ] ); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | - protected function sortByTime(array $a, array $b): int |
|
| 98 | + protected function sortByTime( array $a, array $b ): int |
|
| 99 | 99 | { |
| 100 | - if ($a['time'] !== $b['time']) { |
|
| 101 | - return ($a['time'] > $b['time']) ? -1 : 1; |
|
| 100 | + if( $a[ 'time' ] !== $b[ 'time' ] ) { |
|
| 101 | + return ( $a[ 'time' ] > $b[ 'time' ] ) ? -1 : 1; |
|
| 102 | 102 | } |
| 103 | 103 | return 0; |
| 104 | 104 | } |
@@ -25,7 +25,8 @@ discard block |
||
| 25 | 25 | 'FROM', 'GROUP BY', 'INNER JOIN', 'LEFT JOIN', 'LIMIT', |
| 26 | 26 | 'ON DUPLICATE KEY UPDATE', 'ORDER BY', 'OFFSET', ' SET', 'WHERE', |
| 27 | 27 | ]; |
| 28 | - $replace = array_map(function ($value) { |
|
| 28 | + $replace = array_map(function ($value) |
|
| 29 | + { |
|
| 29 | 30 | return PHP_EOL.$value; |
| 30 | 31 | }, $search); |
| 31 | 32 | foreach ($wpdb->queries as $query) { |
@@ -35,7 +36,8 @@ discard block |
||
| 35 | 36 | $sql = str_replace(['( ',' )',' ,'], ['(',')',','], $sql); |
| 36 | 37 | $sql = str_replace($search, $replace, $sql); |
| 37 | 38 | $parts = explode(PHP_EOL, $sql); |
| 38 | - $sql = array_reduce($parts, function ($carry, $part) { |
|
| 39 | + $sql = array_reduce($parts, function ($carry, $part) |
|
| 40 | + { |
|
| 39 | 41 | if (str_starts_with($part, 'SELECT') && strlen($part) > 100) { |
| 40 | 42 | $part = preg_replace('/\s*(,)\s*/', ','.PHP_EOL.' ', $part); |
| 41 | 43 | } |
@@ -7,145 +7,145 @@ |
||
| 7 | 7 | |
| 8 | 8 | class Console implements Module |
| 9 | 9 | { |
| 10 | - public const ERROR_CODES = [ |
|
| 11 | - E_ERROR => 'error', // 1 |
|
| 12 | - E_WARNING => 'warning', // 2 |
|
| 13 | - E_NOTICE => 'notice', // 8 |
|
| 14 | - E_STRICT => 'strict', // 2048 |
|
| 15 | - E_DEPRECATED => 'deprecated', // 8192 |
|
| 16 | - ]; |
|
| 10 | + public const ERROR_CODES = [ |
|
| 11 | + E_ERROR => 'error', // 1 |
|
| 12 | + E_WARNING => 'warning', // 2 |
|
| 13 | + E_NOTICE => 'notice', // 8 |
|
| 14 | + E_STRICT => 'strict', // 2048 |
|
| 15 | + E_DEPRECATED => 'deprecated', // 8192 |
|
| 16 | + ]; |
|
| 17 | 17 | |
| 18 | - public const MAPPED_ERROR_CODES = [ |
|
| 19 | - 'debug' => 0, |
|
| 20 | - 'info' => E_NOTICE, |
|
| 21 | - 'deprecated' => E_DEPRECATED, // 8192 |
|
| 22 | - 'error' => E_ERROR, // 1 |
|
| 23 | - 'notice' => E_NOTICE, // 8 |
|
| 24 | - 'strict' => E_STRICT, // 2048 |
|
| 25 | - 'warning' => E_WARNING, // 2 |
|
| 26 | - 'critical' => E_ERROR, // 1 |
|
| 27 | - 'alert' => E_ERROR, // 1 |
|
| 28 | - 'emergency' => E_ERROR, // 1 |
|
| 29 | - ]; |
|
| 18 | + public const MAPPED_ERROR_CODES = [ |
|
| 19 | + 'debug' => 0, |
|
| 20 | + 'info' => E_NOTICE, |
|
| 21 | + 'deprecated' => E_DEPRECATED, // 8192 |
|
| 22 | + 'error' => E_ERROR, // 1 |
|
| 23 | + 'notice' => E_NOTICE, // 8 |
|
| 24 | + 'strict' => E_STRICT, // 2048 |
|
| 25 | + 'warning' => E_WARNING, // 2 |
|
| 26 | + 'critical' => E_ERROR, // 1 |
|
| 27 | + 'alert' => E_ERROR, // 1 |
|
| 28 | + 'emergency' => E_ERROR, // 1 |
|
| 29 | + ]; |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * @var Application |
|
| 33 | - */ |
|
| 34 | - protected $app; |
|
| 35 | - /** |
|
| 36 | - * @var array |
|
| 37 | - */ |
|
| 38 | - protected $entries; |
|
| 31 | + /** |
|
| 32 | + * @var Application |
|
| 33 | + */ |
|
| 34 | + protected $app; |
|
| 35 | + /** |
|
| 36 | + * @var array |
|
| 37 | + */ |
|
| 38 | + protected $entries; |
|
| 39 | 39 | |
| 40 | - public function __construct(Application $app) |
|
| 41 | - { |
|
| 42 | - $this->app = $app; |
|
| 43 | - $this->entries = []; |
|
| 44 | - } |
|
| 40 | + public function __construct(Application $app) |
|
| 41 | + { |
|
| 42 | + $this->app = $app; |
|
| 43 | + $this->entries = []; |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - public function entries(): array |
|
| 47 | - { |
|
| 48 | - $entries = []; |
|
| 49 | - foreach ($this->entries as $entry) { |
|
| 50 | - $entry['name'] = ucfirst($entry['errname']); |
|
| 51 | - if ($entry['count'] > 1) { |
|
| 52 | - $entry['name'] = sprintf('%s (%s)', $entry['name'], $entry['count']); |
|
| 53 | - } |
|
| 54 | - $entries[] = $entry; |
|
| 55 | - } |
|
| 56 | - return $entries; |
|
| 57 | - } |
|
| 46 | + public function entries(): array |
|
| 47 | + { |
|
| 48 | + $entries = []; |
|
| 49 | + foreach ($this->entries as $entry) { |
|
| 50 | + $entry['name'] = ucfirst($entry['errname']); |
|
| 51 | + if ($entry['count'] > 1) { |
|
| 52 | + $entry['name'] = sprintf('%s (%s)', $entry['name'], $entry['count']); |
|
| 53 | + } |
|
| 54 | + $entries[] = $entry; |
|
| 55 | + } |
|
| 56 | + return $entries; |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - public function hasEntries(): bool |
|
| 60 | - { |
|
| 61 | - return !empty($this->entries); |
|
| 62 | - } |
|
| 59 | + public function hasEntries(): bool |
|
| 60 | + { |
|
| 61 | + return !empty($this->entries); |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - public function id(): string |
|
| 65 | - { |
|
| 66 | - return 'glbb-console'; |
|
| 67 | - } |
|
| 64 | + public function id(): string |
|
| 65 | + { |
|
| 66 | + return 'glbb-console'; |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - public function isVisible(): bool |
|
| 70 | - { |
|
| 71 | - return true; |
|
| 72 | - } |
|
| 69 | + public function isVisible(): bool |
|
| 70 | + { |
|
| 71 | + return true; |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - public function label(): string |
|
| 75 | - { |
|
| 76 | - $class = ''; |
|
| 77 | - $entryCount = count($this->entries); |
|
| 78 | - $errorCount = 0; |
|
| 79 | - $label = __('Console', 'blackbar'); |
|
| 80 | - foreach ($this->entries as $entry) { |
|
| 81 | - if (in_array($entry['errno'], [E_WARNING])) { |
|
| 82 | - $class = 'glbb-warning'; |
|
| 83 | - } |
|
| 84 | - if (in_array($entry['errno'], [E_ERROR])) { |
|
| 85 | - ++$errorCount; |
|
| 86 | - } |
|
| 87 | - } |
|
| 88 | - if ($errorCount > 0) { |
|
| 89 | - $class = 'glbb-error'; |
|
| 90 | - $info = sprintf('<span class="glbb-link-info">(%d, %d!)</span>', $entryCount, $errorCount); |
|
| 91 | - $label = sprintf('%s %s', $label, $info); |
|
| 92 | - } elseif ($entryCount > 0) { |
|
| 93 | - $info = sprintf('<span class="glbb-link-info">(%d)</span>', $entryCount); |
|
| 94 | - $label = sprintf('%s %s', $label, $info); |
|
| 95 | - } |
|
| 96 | - return sprintf('<span class="%s">%s</span>', $class, $label); |
|
| 97 | - } |
|
| 74 | + public function label(): string |
|
| 75 | + { |
|
| 76 | + $class = ''; |
|
| 77 | + $entryCount = count($this->entries); |
|
| 78 | + $errorCount = 0; |
|
| 79 | + $label = __('Console', 'blackbar'); |
|
| 80 | + foreach ($this->entries as $entry) { |
|
| 81 | + if (in_array($entry['errno'], [E_WARNING])) { |
|
| 82 | + $class = 'glbb-warning'; |
|
| 83 | + } |
|
| 84 | + if (in_array($entry['errno'], [E_ERROR])) { |
|
| 85 | + ++$errorCount; |
|
| 86 | + } |
|
| 87 | + } |
|
| 88 | + if ($errorCount > 0) { |
|
| 89 | + $class = 'glbb-error'; |
|
| 90 | + $info = sprintf('<span class="glbb-link-info">(%d, %d!)</span>', $entryCount, $errorCount); |
|
| 91 | + $label = sprintf('%s %s', $label, $info); |
|
| 92 | + } elseif ($entryCount > 0) { |
|
| 93 | + $info = sprintf('<span class="glbb-link-info">(%d)</span>', $entryCount); |
|
| 94 | + $label = sprintf('%s %s', $label, $info); |
|
| 95 | + } |
|
| 96 | + return sprintf('<span class="%s">%s</span>', $class, $label); |
|
| 97 | + } |
|
| 98 | 98 | |
| 99 | - public function render(): void |
|
| 100 | - { |
|
| 101 | - $this->app->render('panels/console', ['console' => $this]); |
|
| 102 | - } |
|
| 99 | + public function render(): void |
|
| 100 | + { |
|
| 101 | + $this->app->render('panels/console', ['console' => $this]); |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | - public function store(string $message, string $errno = '', string $location = ''): void |
|
| 105 | - { |
|
| 106 | - if (is_numeric($errno)) { |
|
| 107 | - // entry likely stored by set_error_handler() |
|
| 108 | - $errname = 'Unknown'; |
|
| 109 | - if (array_key_exists((int) $errno, static::ERROR_CODES)) { |
|
| 110 | - $errname = static::ERROR_CODES[$errno]; |
|
| 111 | - } |
|
| 112 | - } else { |
|
| 113 | - // entry likely stored by filter hook |
|
| 114 | - $errname = 'Debug'; |
|
| 115 | - if (array_key_exists($errno, static::MAPPED_ERROR_CODES)) { |
|
| 116 | - $errname = $errno; |
|
| 117 | - $errno = static::MAPPED_ERROR_CODES[$errno]; |
|
| 118 | - } |
|
| 119 | - } |
|
| 120 | - $errname = strtolower($errname); |
|
| 121 | - $hash = md5($errno.$errname.$message.$location); |
|
| 122 | - if (array_key_exists($hash, $this->entries)) { |
|
| 123 | - ++$this->entries[$hash]['count']; |
|
| 124 | - } else { |
|
| 125 | - $this->entries[$hash] = [ |
|
| 126 | - 'count' => 0, |
|
| 127 | - 'errname' => $errname, |
|
| 128 | - 'errno' => (int) $errno, |
|
| 129 | - 'message' => $this->normalizeMessage($message, $location), |
|
| 130 | - ]; |
|
| 131 | - }; |
|
| 132 | - } |
|
| 104 | + public function store(string $message, string $errno = '', string $location = ''): void |
|
| 105 | + { |
|
| 106 | + if (is_numeric($errno)) { |
|
| 107 | + // entry likely stored by set_error_handler() |
|
| 108 | + $errname = 'Unknown'; |
|
| 109 | + if (array_key_exists((int) $errno, static::ERROR_CODES)) { |
|
| 110 | + $errname = static::ERROR_CODES[$errno]; |
|
| 111 | + } |
|
| 112 | + } else { |
|
| 113 | + // entry likely stored by filter hook |
|
| 114 | + $errname = 'Debug'; |
|
| 115 | + if (array_key_exists($errno, static::MAPPED_ERROR_CODES)) { |
|
| 116 | + $errname = $errno; |
|
| 117 | + $errno = static::MAPPED_ERROR_CODES[$errno]; |
|
| 118 | + } |
|
| 119 | + } |
|
| 120 | + $errname = strtolower($errname); |
|
| 121 | + $hash = md5($errno.$errname.$message.$location); |
|
| 122 | + if (array_key_exists($hash, $this->entries)) { |
|
| 123 | + ++$this->entries[$hash]['count']; |
|
| 124 | + } else { |
|
| 125 | + $this->entries[$hash] = [ |
|
| 126 | + 'count' => 0, |
|
| 127 | + 'errname' => $errname, |
|
| 128 | + 'errno' => (int) $errno, |
|
| 129 | + 'message' => $this->normalizeMessage($message, $location), |
|
| 130 | + ]; |
|
| 131 | + }; |
|
| 132 | + } |
|
| 133 | 133 | |
| 134 | - protected function normalizeMessage($message, string $location): string |
|
| 135 | - { |
|
| 136 | - error_log('1:: '.$message); |
|
| 137 | - if ($message instanceof \DateTime) { |
|
| 138 | - $message = $message->format('Y-m-d H:i:s'); |
|
| 139 | - } elseif (is_object($message) || is_array($message)) { |
|
| 140 | - $message = (new Dump())->dump($message); |
|
| 141 | - } else { |
|
| 142 | - $message = esc_html(trim((string) $message)); |
|
| 143 | - } |
|
| 144 | - $location = trim($location); |
|
| 145 | - if (!empty($location)) { |
|
| 146 | - $location = str_replace([WP_CONTENT_DIR, ABSPATH], '', $location); |
|
| 147 | - $location = sprintf('[%s] ', $location); |
|
| 148 | - } |
|
| 149 | - return sprintf('%s%s', $location, (string) $message); |
|
| 150 | - } |
|
| 134 | + protected function normalizeMessage($message, string $location): string |
|
| 135 | + { |
|
| 136 | + error_log('1:: '.$message); |
|
| 137 | + if ($message instanceof \DateTime) { |
|
| 138 | + $message = $message->format('Y-m-d H:i:s'); |
|
| 139 | + } elseif (is_object($message) || is_array($message)) { |
|
| 140 | + $message = (new Dump())->dump($message); |
|
| 141 | + } else { |
|
| 142 | + $message = esc_html(trim((string) $message)); |
|
| 143 | + } |
|
| 144 | + $location = trim($location); |
|
| 145 | + if (!empty($location)) { |
|
| 146 | + $location = str_replace([WP_CONTENT_DIR, ABSPATH], '', $location); |
|
| 147 | + $location = sprintf('[%s] ', $location); |
|
| 148 | + } |
|
| 149 | + return sprintf('%s%s', $location, (string) $message); |
|
| 150 | + } |
|
| 151 | 151 | } |
@@ -37,28 +37,28 @@ discard block |
||
| 37 | 37 | */ |
| 38 | 38 | protected $entries; |
| 39 | 39 | |
| 40 | - public function __construct(Application $app) |
|
| 40 | + public function __construct( Application $app ) |
|
| 41 | 41 | { |
| 42 | 42 | $this->app = $app; |
| 43 | - $this->entries = []; |
|
| 43 | + $this->entries = [ ]; |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | public function entries(): array |
| 47 | 47 | { |
| 48 | - $entries = []; |
|
| 49 | - foreach ($this->entries as $entry) { |
|
| 50 | - $entry['name'] = ucfirst($entry['errname']); |
|
| 51 | - if ($entry['count'] > 1) { |
|
| 52 | - $entry['name'] = sprintf('%s (%s)', $entry['name'], $entry['count']); |
|
| 48 | + $entries = [ ]; |
|
| 49 | + foreach( $this->entries as $entry ) { |
|
| 50 | + $entry[ 'name' ] = ucfirst( $entry[ 'errname' ] ); |
|
| 51 | + if( $entry[ 'count' ] > 1 ) { |
|
| 52 | + $entry[ 'name' ] = sprintf( '%s (%s)', $entry[ 'name' ], $entry[ 'count' ] ); |
|
| 53 | 53 | } |
| 54 | - $entries[] = $entry; |
|
| 54 | + $entries[ ] = $entry; |
|
| 55 | 55 | } |
| 56 | 56 | return $entries; |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | public function hasEntries(): bool |
| 60 | 60 | { |
| 61 | - return !empty($this->entries); |
|
| 61 | + return !empty( $this->entries ); |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | public function id(): string |
@@ -74,78 +74,78 @@ discard block |
||
| 74 | 74 | public function label(): string |
| 75 | 75 | { |
| 76 | 76 | $class = ''; |
| 77 | - $entryCount = count($this->entries); |
|
| 77 | + $entryCount = count( $this->entries ); |
|
| 78 | 78 | $errorCount = 0; |
| 79 | - $label = __('Console', 'blackbar'); |
|
| 80 | - foreach ($this->entries as $entry) { |
|
| 81 | - if (in_array($entry['errno'], [E_WARNING])) { |
|
| 79 | + $label = __( 'Console', 'blackbar' ); |
|
| 80 | + foreach( $this->entries as $entry ) { |
|
| 81 | + if( in_array( $entry[ 'errno' ], [ E_WARNING ] ) ) { |
|
| 82 | 82 | $class = 'glbb-warning'; |
| 83 | 83 | } |
| 84 | - if (in_array($entry['errno'], [E_ERROR])) { |
|
| 84 | + if( in_array( $entry[ 'errno' ], [ E_ERROR ] ) ) { |
|
| 85 | 85 | ++$errorCount; |
| 86 | 86 | } |
| 87 | 87 | } |
| 88 | - if ($errorCount > 0) { |
|
| 88 | + if( $errorCount > 0 ) { |
|
| 89 | 89 | $class = 'glbb-error'; |
| 90 | - $info = sprintf('<span class="glbb-link-info">(%d, %d!)</span>', $entryCount, $errorCount); |
|
| 91 | - $label = sprintf('%s %s', $label, $info); |
|
| 92 | - } elseif ($entryCount > 0) { |
|
| 93 | - $info = sprintf('<span class="glbb-link-info">(%d)</span>', $entryCount); |
|
| 94 | - $label = sprintf('%s %s', $label, $info); |
|
| 90 | + $info = sprintf( '<span class="glbb-link-info">(%d, %d!)</span>', $entryCount, $errorCount ); |
|
| 91 | + $label = sprintf( '%s %s', $label, $info ); |
|
| 92 | + } elseif( $entryCount > 0 ) { |
|
| 93 | + $info = sprintf( '<span class="glbb-link-info">(%d)</span>', $entryCount ); |
|
| 94 | + $label = sprintf( '%s %s', $label, $info ); |
|
| 95 | 95 | } |
| 96 | - return sprintf('<span class="%s">%s</span>', $class, $label); |
|
| 96 | + return sprintf( '<span class="%s">%s</span>', $class, $label ); |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | public function render(): void |
| 100 | 100 | { |
| 101 | - $this->app->render('panels/console', ['console' => $this]); |
|
| 101 | + $this->app->render( 'panels/console', [ 'console' => $this ] ); |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | - public function store(string $message, string $errno = '', string $location = ''): void |
|
| 104 | + public function store( string $message, string $errno = '', string $location = '' ): void |
|
| 105 | 105 | { |
| 106 | - if (is_numeric($errno)) { |
|
| 106 | + if( is_numeric( $errno ) ) { |
|
| 107 | 107 | // entry likely stored by set_error_handler() |
| 108 | 108 | $errname = 'Unknown'; |
| 109 | - if (array_key_exists((int) $errno, static::ERROR_CODES)) { |
|
| 110 | - $errname = static::ERROR_CODES[$errno]; |
|
| 109 | + if( array_key_exists( (int) $errno, static::ERROR_CODES ) ) { |
|
| 110 | + $errname = static::ERROR_CODES[ $errno ]; |
|
| 111 | 111 | } |
| 112 | 112 | } else { |
| 113 | 113 | // entry likely stored by filter hook |
| 114 | 114 | $errname = 'Debug'; |
| 115 | - if (array_key_exists($errno, static::MAPPED_ERROR_CODES)) { |
|
| 115 | + if( array_key_exists( $errno, static::MAPPED_ERROR_CODES ) ) { |
|
| 116 | 116 | $errname = $errno; |
| 117 | - $errno = static::MAPPED_ERROR_CODES[$errno]; |
|
| 117 | + $errno = static::MAPPED_ERROR_CODES[ $errno ]; |
|
| 118 | 118 | } |
| 119 | 119 | } |
| 120 | - $errname = strtolower($errname); |
|
| 121 | - $hash = md5($errno.$errname.$message.$location); |
|
| 122 | - if (array_key_exists($hash, $this->entries)) { |
|
| 123 | - ++$this->entries[$hash]['count']; |
|
| 120 | + $errname = strtolower( $errname ); |
|
| 121 | + $hash = md5( $errno . $errname . $message . $location ); |
|
| 122 | + if( array_key_exists( $hash, $this->entries ) ) { |
|
| 123 | + ++$this->entries[ $hash ][ 'count' ]; |
|
| 124 | 124 | } else { |
| 125 | - $this->entries[$hash] = [ |
|
| 125 | + $this->entries[ $hash ] = [ |
|
| 126 | 126 | 'count' => 0, |
| 127 | 127 | 'errname' => $errname, |
| 128 | 128 | 'errno' => (int) $errno, |
| 129 | - 'message' => $this->normalizeMessage($message, $location), |
|
| 129 | + 'message' => $this->normalizeMessage( $message, $location ), |
|
| 130 | 130 | ]; |
| 131 | 131 | }; |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | - protected function normalizeMessage($message, string $location): string |
|
| 134 | + protected function normalizeMessage( $message, string $location ): string |
|
| 135 | 135 | { |
| 136 | - error_log('1:: '.$message); |
|
| 137 | - if ($message instanceof \DateTime) { |
|
| 138 | - $message = $message->format('Y-m-d H:i:s'); |
|
| 139 | - } elseif (is_object($message) || is_array($message)) { |
|
| 140 | - $message = (new Dump())->dump($message); |
|
| 136 | + error_log( '1:: ' . $message ); |
|
| 137 | + if( $message instanceof \DateTime ) { |
|
| 138 | + $message = $message->format( 'Y-m-d H:i:s' ); |
|
| 139 | + } elseif( is_object( $message ) || is_array( $message ) ) { |
|
| 140 | + $message = ( new Dump() )->dump( $message ); |
|
| 141 | 141 | } else { |
| 142 | - $message = esc_html(trim((string) $message)); |
|
| 142 | + $message = esc_html( trim( (string) $message ) ); |
|
| 143 | 143 | } |
| 144 | - $location = trim($location); |
|
| 145 | - if (!empty($location)) { |
|
| 146 | - $location = str_replace([WP_CONTENT_DIR, ABSPATH], '', $location); |
|
| 147 | - $location = sprintf('[%s] ', $location); |
|
| 144 | + $location = trim( $location ); |
|
| 145 | + if( !empty( $location ) ) { |
|
| 146 | + $location = str_replace( [ WP_CONTENT_DIR, ABSPATH ], '', $location ); |
|
| 147 | + $location = sprintf( '[%s] ', $location ); |
|
| 148 | 148 | } |
| 149 | - return sprintf('%s%s', $location, (string) $message); |
|
| 149 | + return sprintf( '%s%s', $location, (string) $message ); |
|
| 150 | 150 | } |
| 151 | 151 | } |
@@ -89,7 +89,8 @@ discard block |
||
| 89 | 89 | $class = 'glbb-error'; |
| 90 | 90 | $info = sprintf('<span class="glbb-link-info">(%d, %d!)</span>', $entryCount, $errorCount); |
| 91 | 91 | $label = sprintf('%s %s', $label, $info); |
| 92 | - } elseif ($entryCount > 0) { |
|
| 92 | + } |
|
| 93 | + elseif ($entryCount > 0) { |
|
| 93 | 94 | $info = sprintf('<span class="glbb-link-info">(%d)</span>', $entryCount); |
| 94 | 95 | $label = sprintf('%s %s', $label, $info); |
| 95 | 96 | } |
@@ -109,7 +110,8 @@ discard block |
||
| 109 | 110 | if (array_key_exists((int) $errno, static::ERROR_CODES)) { |
| 110 | 111 | $errname = static::ERROR_CODES[$errno]; |
| 111 | 112 | } |
| 112 | - } else { |
|
| 113 | + } |
|
| 114 | + else { |
|
| 113 | 115 | // entry likely stored by filter hook |
| 114 | 116 | $errname = 'Debug'; |
| 115 | 117 | if (array_key_exists($errno, static::MAPPED_ERROR_CODES)) { |
@@ -121,7 +123,8 @@ discard block |
||
| 121 | 123 | $hash = md5($errno.$errname.$message.$location); |
| 122 | 124 | if (array_key_exists($hash, $this->entries)) { |
| 123 | 125 | ++$this->entries[$hash]['count']; |
| 124 | - } else { |
|
| 126 | + } |
|
| 127 | + else { |
|
| 125 | 128 | $this->entries[$hash] = [ |
| 126 | 129 | 'count' => 0, |
| 127 | 130 | 'errname' => $errname, |
@@ -136,9 +139,11 @@ discard block |
||
| 136 | 139 | error_log('1:: '.$message); |
| 137 | 140 | if ($message instanceof \DateTime) { |
| 138 | 141 | $message = $message->format('Y-m-d H:i:s'); |
| 139 | - } elseif (is_object($message) || is_array($message)) { |
|
| 142 | + } |
|
| 143 | + elseif (is_object($message) || is_array($message)) { |
|
| 140 | 144 | $message = (new Dump())->dump($message); |
| 141 | - } else { |
|
| 145 | + } |
|
| 146 | + else { |
|
| 142 | 147 | $message = esc_html(trim((string) $message)); |
| 143 | 148 | } |
| 144 | 149 | $location = trim($location); |
@@ -6,172 +6,172 @@ |
||
| 6 | 6 | |
| 7 | 7 | class Actions implements Module |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * @var Application |
|
| 11 | - */ |
|
| 12 | - protected $app; |
|
| 13 | - /** |
|
| 14 | - * @var array |
|
| 15 | - */ |
|
| 16 | - protected $entries; |
|
| 17 | - /** |
|
| 18 | - * @var array |
|
| 19 | - */ |
|
| 20 | - protected $hooks; |
|
| 21 | - /** |
|
| 22 | - * @var int |
|
| 23 | - */ |
|
| 24 | - protected $totalActions; |
|
| 25 | - /** |
|
| 26 | - * @var float |
|
| 27 | - */ |
|
| 28 | - protected $totalTime; |
|
| 9 | + /** |
|
| 10 | + * @var Application |
|
| 11 | + */ |
|
| 12 | + protected $app; |
|
| 13 | + /** |
|
| 14 | + * @var array |
|
| 15 | + */ |
|
| 16 | + protected $entries; |
|
| 17 | + /** |
|
| 18 | + * @var array |
|
| 19 | + */ |
|
| 20 | + protected $hooks; |
|
| 21 | + /** |
|
| 22 | + * @var int |
|
| 23 | + */ |
|
| 24 | + protected $totalActions; |
|
| 25 | + /** |
|
| 26 | + * @var float |
|
| 27 | + */ |
|
| 28 | + protected $totalTime; |
|
| 29 | 29 | |
| 30 | - public function __construct(Application $app) |
|
| 31 | - { |
|
| 32 | - $this->app = $app; |
|
| 33 | - $this->entries = []; |
|
| 34 | - $this->hooks = []; |
|
| 35 | - $this->totalActions = 0; |
|
| 36 | - $this->totalTime = (float) 0; |
|
| 37 | - } |
|
| 30 | + public function __construct(Application $app) |
|
| 31 | + { |
|
| 32 | + $this->app = $app; |
|
| 33 | + $this->entries = []; |
|
| 34 | + $this->hooks = []; |
|
| 35 | + $this->totalActions = 0; |
|
| 36 | + $this->totalTime = (float) 0; |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - public function callbacksForHook(string $action): void |
|
| 40 | - { |
|
| 41 | - global $wp_filter; |
|
| 42 | - if (!isset($this->hooks[$action]) || !isset($wp_filter[$action])) { |
|
| 43 | - return; |
|
| 44 | - } |
|
| 45 | - $this->hooks[$action]['callbacks_count'] = 0; |
|
| 46 | - foreach ($wp_filter[$action] as $priority => $callbacks) { |
|
| 47 | - if (!array_key_exists($priority, $this->hooks[$action]['callbacks'])) { |
|
| 48 | - $this->hooks[$action]['callbacks'][$priority] = []; |
|
| 49 | - } |
|
| 50 | - foreach ($callbacks as $callback) { |
|
| 51 | - if (is_array($callback['function']) && 2 === count($callback['function'])) { |
|
| 52 | - list($object, $method) = $callback['function']; |
|
| 53 | - if (is_object($object)) { |
|
| 54 | - $object = get_class($object); |
|
| 55 | - $reflection = new \ReflectionClass($object); |
|
| 56 | - if (str_starts_with($reflection->getNamespaceName(), 'GeminiLabs\BlackBar')) { |
|
| 57 | - continue; // skip blackbar callbacks |
|
| 58 | - } |
|
| 59 | - } |
|
| 60 | - $this->hooks[$action]['callbacks'][$priority][] = sprintf('%s::%s', $object, $method); |
|
| 61 | - } elseif (is_object($callback['function'])) { |
|
| 62 | - $this->hooks[$action]['callbacks'][$priority][] = get_class($callback['function']); |
|
| 63 | - } else { |
|
| 64 | - $this->hooks[$action]['callbacks'][$priority][] = $callback['function']; |
|
| 65 | - } |
|
| 66 | - ++$this->hooks[$action]['callbacks_count']; |
|
| 67 | - } |
|
| 68 | - } |
|
| 69 | - } |
|
| 39 | + public function callbacksForHook(string $action): void |
|
| 40 | + { |
|
| 41 | + global $wp_filter; |
|
| 42 | + if (!isset($this->hooks[$action]) || !isset($wp_filter[$action])) { |
|
| 43 | + return; |
|
| 44 | + } |
|
| 45 | + $this->hooks[$action]['callbacks_count'] = 0; |
|
| 46 | + foreach ($wp_filter[$action] as $priority => $callbacks) { |
|
| 47 | + if (!array_key_exists($priority, $this->hooks[$action]['callbacks'])) { |
|
| 48 | + $this->hooks[$action]['callbacks'][$priority] = []; |
|
| 49 | + } |
|
| 50 | + foreach ($callbacks as $callback) { |
|
| 51 | + if (is_array($callback['function']) && 2 === count($callback['function'])) { |
|
| 52 | + list($object, $method) = $callback['function']; |
|
| 53 | + if (is_object($object)) { |
|
| 54 | + $object = get_class($object); |
|
| 55 | + $reflection = new \ReflectionClass($object); |
|
| 56 | + if (str_starts_with($reflection->getNamespaceName(), 'GeminiLabs\BlackBar')) { |
|
| 57 | + continue; // skip blackbar callbacks |
|
| 58 | + } |
|
| 59 | + } |
|
| 60 | + $this->hooks[$action]['callbacks'][$priority][] = sprintf('%s::%s', $object, $method); |
|
| 61 | + } elseif (is_object($callback['function'])) { |
|
| 62 | + $this->hooks[$action]['callbacks'][$priority][] = get_class($callback['function']); |
|
| 63 | + } else { |
|
| 64 | + $this->hooks[$action]['callbacks'][$priority][] = $callback['function']; |
|
| 65 | + } |
|
| 66 | + ++$this->hooks[$action]['callbacks_count']; |
|
| 67 | + } |
|
| 68 | + } |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - public function entries(): array |
|
| 72 | - { |
|
| 73 | - if (class_exists('Debug_Bar_Slow_Actions')) { |
|
| 74 | - return []; |
|
| 75 | - } |
|
| 76 | - if (!empty($this->entries) || empty($this->hooks)) { |
|
| 77 | - return $this->entries; |
|
| 78 | - } |
|
| 79 | - $orderedActions = array_keys($this->hooks); |
|
| 80 | - foreach ($this->hooks as $action => $data) { |
|
| 81 | - $total = $this->totalTimeForHook($data); |
|
| 82 | - $this->hooks[$action]['total'] = $total; |
|
| 83 | - $this->totalTime += $total; |
|
| 84 | - $this->totalActions += $data['count']; |
|
| 85 | - $this->callbacksForHook($action); |
|
| 86 | - } |
|
| 87 | - $this->hooks = array_filter($this->hooks, function ($hook) { |
|
| 88 | - return !empty($hook['callbacks_count']); // skip blackbar callbacks |
|
| 89 | - }); |
|
| 90 | - uasort($this->hooks, [$this, 'sortByTime']); |
|
| 91 | - $this->entries = array_slice($this->hooks, 0, 50); // return the 50 slowest actions |
|
| 92 | - $order = array_intersect($orderedActions, array_keys($this->entries)); |
|
| 93 | - foreach ($order as $index => $action) { |
|
| 94 | - $this->entries[$action]['index'] = $index; |
|
| 95 | - } |
|
| 96 | - return $this->entries; |
|
| 97 | - } |
|
| 71 | + public function entries(): array |
|
| 72 | + { |
|
| 73 | + if (class_exists('Debug_Bar_Slow_Actions')) { |
|
| 74 | + return []; |
|
| 75 | + } |
|
| 76 | + if (!empty($this->entries) || empty($this->hooks)) { |
|
| 77 | + return $this->entries; |
|
| 78 | + } |
|
| 79 | + $orderedActions = array_keys($this->hooks); |
|
| 80 | + foreach ($this->hooks as $action => $data) { |
|
| 81 | + $total = $this->totalTimeForHook($data); |
|
| 82 | + $this->hooks[$action]['total'] = $total; |
|
| 83 | + $this->totalTime += $total; |
|
| 84 | + $this->totalActions += $data['count']; |
|
| 85 | + $this->callbacksForHook($action); |
|
| 86 | + } |
|
| 87 | + $this->hooks = array_filter($this->hooks, function ($hook) { |
|
| 88 | + return !empty($hook['callbacks_count']); // skip blackbar callbacks |
|
| 89 | + }); |
|
| 90 | + uasort($this->hooks, [$this, 'sortByTime']); |
|
| 91 | + $this->entries = array_slice($this->hooks, 0, 50); // return the 50 slowest actions |
|
| 92 | + $order = array_intersect($orderedActions, array_keys($this->entries)); |
|
| 93 | + foreach ($order as $index => $action) { |
|
| 94 | + $this->entries[$action]['index'] = $index; |
|
| 95 | + } |
|
| 96 | + return $this->entries; |
|
| 97 | + } |
|
| 98 | 98 | |
| 99 | - public function hasEntries(): bool |
|
| 100 | - { |
|
| 101 | - return !empty($this->entries()); |
|
| 102 | - } |
|
| 99 | + public function hasEntries(): bool |
|
| 100 | + { |
|
| 101 | + return !empty($this->entries()); |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | - public function id(): string |
|
| 105 | - { |
|
| 106 | - return 'glbb-actions'; |
|
| 107 | - } |
|
| 104 | + public function id(): string |
|
| 105 | + { |
|
| 106 | + return 'glbb-actions'; |
|
| 107 | + } |
|
| 108 | 108 | |
| 109 | - public function isVisible(): bool |
|
| 110 | - { |
|
| 111 | - return true; |
|
| 112 | - } |
|
| 109 | + public function isVisible(): bool |
|
| 110 | + { |
|
| 111 | + return true; |
|
| 112 | + } |
|
| 113 | 113 | |
| 114 | - public function label(): string |
|
| 115 | - { |
|
| 116 | - $label = __('Hooks', 'blackbar'); |
|
| 117 | - if (class_exists('Debug_Bar_Slow_Actions')) { |
|
| 118 | - return $label; |
|
| 119 | - } |
|
| 120 | - $this->entries(); // calculates the totalTime |
|
| 121 | - if ($this->totalTime > 0) { |
|
| 122 | - $info = sprintf('<span class="glbb-link-info">(<span class="glbb-actions-time">%.2f</span> ms)</span>', $this->totalTime); |
|
| 123 | - $label = sprintf('%s %s', $label, $info); |
|
| 124 | - } |
|
| 125 | - return $label; |
|
| 126 | - } |
|
| 114 | + public function label(): string |
|
| 115 | + { |
|
| 116 | + $label = __('Hooks', 'blackbar'); |
|
| 117 | + if (class_exists('Debug_Bar_Slow_Actions')) { |
|
| 118 | + return $label; |
|
| 119 | + } |
|
| 120 | + $this->entries(); // calculates the totalTime |
|
| 121 | + if ($this->totalTime > 0) { |
|
| 122 | + $info = sprintf('<span class="glbb-link-info">(<span class="glbb-actions-time">%.2f</span> ms)</span>', $this->totalTime); |
|
| 123 | + $label = sprintf('%s %s', $label, $info); |
|
| 124 | + } |
|
| 125 | + return $label; |
|
| 126 | + } |
|
| 127 | 127 | |
| 128 | - public function render(): void |
|
| 129 | - { |
|
| 130 | - $this->app->render('panels/actions', ['actions' => $this]); |
|
| 131 | - } |
|
| 128 | + public function render(): void |
|
| 129 | + { |
|
| 130 | + $this->app->render('panels/actions', ['actions' => $this]); |
|
| 131 | + } |
|
| 132 | 132 | |
| 133 | - public function startTimer(): void |
|
| 134 | - { |
|
| 135 | - $action = current_filter(); |
|
| 136 | - if (!isset($this->hooks[$action])) { |
|
| 137 | - $this->hooks[$action] = [ |
|
| 138 | - 'callbacks' => [], |
|
| 139 | - 'count' => 0, |
|
| 140 | - 'stack' => [], |
|
| 141 | - 'time' => [], |
|
| 142 | - ]; |
|
| 143 | - add_action($action, [$this, 'stopTimer'], 9999); // @phpstan-ignore-line |
|
| 144 | - } |
|
| 145 | - ++$this->hooks[$action]['count']; |
|
| 146 | - array_push($this->hooks[$action]['stack'], ['start' => microtime(true)]); |
|
| 147 | - } |
|
| 133 | + public function startTimer(): void |
|
| 134 | + { |
|
| 135 | + $action = current_filter(); |
|
| 136 | + if (!isset($this->hooks[$action])) { |
|
| 137 | + $this->hooks[$action] = [ |
|
| 138 | + 'callbacks' => [], |
|
| 139 | + 'count' => 0, |
|
| 140 | + 'stack' => [], |
|
| 141 | + 'time' => [], |
|
| 142 | + ]; |
|
| 143 | + add_action($action, [$this, 'stopTimer'], 9999); // @phpstan-ignore-line |
|
| 144 | + } |
|
| 145 | + ++$this->hooks[$action]['count']; |
|
| 146 | + array_push($this->hooks[$action]['stack'], ['start' => microtime(true)]); |
|
| 147 | + } |
|
| 148 | 148 | |
| 149 | - /** |
|
| 150 | - * @param mixed $filteredValue |
|
| 151 | - * @return mixed |
|
| 152 | - */ |
|
| 153 | - public function stopTimer($filteredValue = null) |
|
| 154 | - { |
|
| 155 | - $time = array_pop($this->hooks[current_filter()]['stack']); |
|
| 156 | - $time['stop'] = microtime(true); |
|
| 157 | - array_push($this->hooks[current_filter()]['time'], $time); |
|
| 158 | - return $filteredValue; // In case this was a filter. |
|
| 159 | - } |
|
| 149 | + /** |
|
| 150 | + * @param mixed $filteredValue |
|
| 151 | + * @return mixed |
|
| 152 | + */ |
|
| 153 | + public function stopTimer($filteredValue = null) |
|
| 154 | + { |
|
| 155 | + $time = array_pop($this->hooks[current_filter()]['stack']); |
|
| 156 | + $time['stop'] = microtime(true); |
|
| 157 | + array_push($this->hooks[current_filter()]['time'], $time); |
|
| 158 | + return $filteredValue; // In case this was a filter. |
|
| 159 | + } |
|
| 160 | 160 | |
| 161 | - public function totalTimeForHook(array $data): float |
|
| 162 | - { |
|
| 163 | - $total = 0; |
|
| 164 | - foreach ($data['time'] as $time) { |
|
| 165 | - $total += ($time['stop'] - $time['start']) * 1000; |
|
| 166 | - } |
|
| 167 | - return (float) $total; |
|
| 168 | - } |
|
| 161 | + public function totalTimeForHook(array $data): float |
|
| 162 | + { |
|
| 163 | + $total = 0; |
|
| 164 | + foreach ($data['time'] as $time) { |
|
| 165 | + $total += ($time['stop'] - $time['start']) * 1000; |
|
| 166 | + } |
|
| 167 | + return (float) $total; |
|
| 168 | + } |
|
| 169 | 169 | |
| 170 | - protected function sortByTime(array $a, array $b): int |
|
| 171 | - { |
|
| 172 | - if ($a['total'] !== $b['total']) { |
|
| 173 | - return ($a['total'] > $b['total']) ? -1 : 1; |
|
| 174 | - } |
|
| 175 | - return 0; |
|
| 176 | - } |
|
| 170 | + protected function sortByTime(array $a, array $b): int |
|
| 171 | + { |
|
| 172 | + if ($a['total'] !== $b['total']) { |
|
| 173 | + return ($a['total'] > $b['total']) ? -1 : 1; |
|
| 174 | + } |
|
| 175 | + return 0; |
|
| 176 | + } |
|
| 177 | 177 | } |
@@ -27,78 +27,78 @@ discard block |
||
| 27 | 27 | */ |
| 28 | 28 | protected $totalTime; |
| 29 | 29 | |
| 30 | - public function __construct(Application $app) |
|
| 30 | + public function __construct( Application $app ) |
|
| 31 | 31 | { |
| 32 | 32 | $this->app = $app; |
| 33 | - $this->entries = []; |
|
| 34 | - $this->hooks = []; |
|
| 33 | + $this->entries = [ ]; |
|
| 34 | + $this->hooks = [ ]; |
|
| 35 | 35 | $this->totalActions = 0; |
| 36 | 36 | $this->totalTime = (float) 0; |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | - public function callbacksForHook(string $action): void |
|
| 39 | + public function callbacksForHook( string $action ): void |
|
| 40 | 40 | { |
| 41 | 41 | global $wp_filter; |
| 42 | - if (!isset($this->hooks[$action]) || !isset($wp_filter[$action])) { |
|
| 42 | + if( !isset( $this->hooks[ $action ] ) || !isset( $wp_filter[ $action ] ) ) { |
|
| 43 | 43 | return; |
| 44 | 44 | } |
| 45 | - $this->hooks[$action]['callbacks_count'] = 0; |
|
| 46 | - foreach ($wp_filter[$action] as $priority => $callbacks) { |
|
| 47 | - if (!array_key_exists($priority, $this->hooks[$action]['callbacks'])) { |
|
| 48 | - $this->hooks[$action]['callbacks'][$priority] = []; |
|
| 45 | + $this->hooks[ $action ][ 'callbacks_count' ] = 0; |
|
| 46 | + foreach( $wp_filter[ $action ] as $priority => $callbacks ) { |
|
| 47 | + if( !array_key_exists( $priority, $this->hooks[ $action ][ 'callbacks' ] ) ) { |
|
| 48 | + $this->hooks[ $action ][ 'callbacks' ][ $priority ] = [ ]; |
|
| 49 | 49 | } |
| 50 | - foreach ($callbacks as $callback) { |
|
| 51 | - if (is_array($callback['function']) && 2 === count($callback['function'])) { |
|
| 52 | - list($object, $method) = $callback['function']; |
|
| 53 | - if (is_object($object)) { |
|
| 54 | - $object = get_class($object); |
|
| 55 | - $reflection = new \ReflectionClass($object); |
|
| 56 | - if (str_starts_with($reflection->getNamespaceName(), 'GeminiLabs\BlackBar')) { |
|
| 50 | + foreach( $callbacks as $callback ) { |
|
| 51 | + if( is_array( $callback[ 'function' ] ) && 2 === count( $callback[ 'function' ] ) ) { |
|
| 52 | + list( $object, $method ) = $callback[ 'function' ]; |
|
| 53 | + if( is_object( $object ) ) { |
|
| 54 | + $object = get_class( $object ); |
|
| 55 | + $reflection = new \ReflectionClass( $object ); |
|
| 56 | + if( str_starts_with( $reflection->getNamespaceName(), 'GeminiLabs\BlackBar' ) ) { |
|
| 57 | 57 | continue; // skip blackbar callbacks |
| 58 | 58 | } |
| 59 | 59 | } |
| 60 | - $this->hooks[$action]['callbacks'][$priority][] = sprintf('%s::%s', $object, $method); |
|
| 61 | - } elseif (is_object($callback['function'])) { |
|
| 62 | - $this->hooks[$action]['callbacks'][$priority][] = get_class($callback['function']); |
|
| 60 | + $this->hooks[ $action ][ 'callbacks' ][ $priority ][ ] = sprintf( '%s::%s', $object, $method ); |
|
| 61 | + } elseif( is_object( $callback[ 'function' ] ) ) { |
|
| 62 | + $this->hooks[ $action ][ 'callbacks' ][ $priority ][ ] = get_class( $callback[ 'function' ] ); |
|
| 63 | 63 | } else { |
| 64 | - $this->hooks[$action]['callbacks'][$priority][] = $callback['function']; |
|
| 64 | + $this->hooks[ $action ][ 'callbacks' ][ $priority ][ ] = $callback[ 'function' ]; |
|
| 65 | 65 | } |
| 66 | - ++$this->hooks[$action]['callbacks_count']; |
|
| 66 | + ++$this->hooks[ $action ][ 'callbacks_count' ]; |
|
| 67 | 67 | } |
| 68 | 68 | } |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | public function entries(): array |
| 72 | 72 | { |
| 73 | - if (class_exists('Debug_Bar_Slow_Actions')) { |
|
| 74 | - return []; |
|
| 73 | + if( class_exists( 'Debug_Bar_Slow_Actions' ) ) { |
|
| 74 | + return [ ]; |
|
| 75 | 75 | } |
| 76 | - if (!empty($this->entries) || empty($this->hooks)) { |
|
| 76 | + if( !empty( $this->entries ) || empty( $this->hooks ) ) { |
|
| 77 | 77 | return $this->entries; |
| 78 | 78 | } |
| 79 | - $orderedActions = array_keys($this->hooks); |
|
| 80 | - foreach ($this->hooks as $action => $data) { |
|
| 81 | - $total = $this->totalTimeForHook($data); |
|
| 82 | - $this->hooks[$action]['total'] = $total; |
|
| 79 | + $orderedActions = array_keys( $this->hooks ); |
|
| 80 | + foreach( $this->hooks as $action => $data ) { |
|
| 81 | + $total = $this->totalTimeForHook( $data ); |
|
| 82 | + $this->hooks[ $action ][ 'total' ] = $total; |
|
| 83 | 83 | $this->totalTime += $total; |
| 84 | - $this->totalActions += $data['count']; |
|
| 85 | - $this->callbacksForHook($action); |
|
| 84 | + $this->totalActions += $data[ 'count' ]; |
|
| 85 | + $this->callbacksForHook( $action ); |
|
| 86 | 86 | } |
| 87 | - $this->hooks = array_filter($this->hooks, function ($hook) { |
|
| 88 | - return !empty($hook['callbacks_count']); // skip blackbar callbacks |
|
| 87 | + $this->hooks = array_filter( $this->hooks, function( $hook ) { |
|
| 88 | + return !empty( $hook[ 'callbacks_count' ] ); // skip blackbar callbacks |
|
| 89 | 89 | }); |
| 90 | - uasort($this->hooks, [$this, 'sortByTime']); |
|
| 91 | - $this->entries = array_slice($this->hooks, 0, 50); // return the 50 slowest actions |
|
| 92 | - $order = array_intersect($orderedActions, array_keys($this->entries)); |
|
| 93 | - foreach ($order as $index => $action) { |
|
| 94 | - $this->entries[$action]['index'] = $index; |
|
| 90 | + uasort( $this->hooks, [ $this, 'sortByTime' ] ); |
|
| 91 | + $this->entries = array_slice( $this->hooks, 0, 50 ); // return the 50 slowest actions |
|
| 92 | + $order = array_intersect( $orderedActions, array_keys( $this->entries ) ); |
|
| 93 | + foreach( $order as $index => $action ) { |
|
| 94 | + $this->entries[ $action ][ 'index' ] = $index; |
|
| 95 | 95 | } |
| 96 | 96 | return $this->entries; |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | public function hasEntries(): bool |
| 100 | 100 | { |
| 101 | - return !empty($this->entries()); |
|
| 101 | + return !empty( $this->entries() ); |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | public function id(): string |
@@ -113,64 +113,64 @@ discard block |
||
| 113 | 113 | |
| 114 | 114 | public function label(): string |
| 115 | 115 | { |
| 116 | - $label = __('Hooks', 'blackbar'); |
|
| 117 | - if (class_exists('Debug_Bar_Slow_Actions')) { |
|
| 116 | + $label = __( 'Hooks', 'blackbar' ); |
|
| 117 | + if( class_exists( 'Debug_Bar_Slow_Actions' ) ) { |
|
| 118 | 118 | return $label; |
| 119 | 119 | } |
| 120 | 120 | $this->entries(); // calculates the totalTime |
| 121 | - if ($this->totalTime > 0) { |
|
| 122 | - $info = sprintf('<span class="glbb-link-info">(<span class="glbb-actions-time">%.2f</span> ms)</span>', $this->totalTime); |
|
| 123 | - $label = sprintf('%s %s', $label, $info); |
|
| 121 | + if( $this->totalTime > 0 ) { |
|
| 122 | + $info = sprintf( '<span class="glbb-link-info">(<span class="glbb-actions-time">%.2f</span> ms)</span>', $this->totalTime ); |
|
| 123 | + $label = sprintf( '%s %s', $label, $info ); |
|
| 124 | 124 | } |
| 125 | 125 | return $label; |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | public function render(): void |
| 129 | 129 | { |
| 130 | - $this->app->render('panels/actions', ['actions' => $this]); |
|
| 130 | + $this->app->render( 'panels/actions', [ 'actions' => $this ] ); |
|
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | public function startTimer(): void |
| 134 | 134 | { |
| 135 | 135 | $action = current_filter(); |
| 136 | - if (!isset($this->hooks[$action])) { |
|
| 137 | - $this->hooks[$action] = [ |
|
| 138 | - 'callbacks' => [], |
|
| 136 | + if( !isset( $this->hooks[ $action ] ) ) { |
|
| 137 | + $this->hooks[ $action ] = [ |
|
| 138 | + 'callbacks' => [ ], |
|
| 139 | 139 | 'count' => 0, |
| 140 | - 'stack' => [], |
|
| 141 | - 'time' => [], |
|
| 140 | + 'stack' => [ ], |
|
| 141 | + 'time' => [ ], |
|
| 142 | 142 | ]; |
| 143 | - add_action($action, [$this, 'stopTimer'], 9999); // @phpstan-ignore-line |
|
| 143 | + add_action( $action, [ $this, 'stopTimer' ], 9999 ); // @phpstan-ignore-line |
|
| 144 | 144 | } |
| 145 | - ++$this->hooks[$action]['count']; |
|
| 146 | - array_push($this->hooks[$action]['stack'], ['start' => microtime(true)]); |
|
| 145 | + ++$this->hooks[ $action ][ 'count' ]; |
|
| 146 | + array_push( $this->hooks[ $action ][ 'stack' ], [ 'start' => microtime( true ) ] ); |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | /** |
| 150 | 150 | * @param mixed $filteredValue |
| 151 | 151 | * @return mixed |
| 152 | 152 | */ |
| 153 | - public function stopTimer($filteredValue = null) |
|
| 153 | + public function stopTimer( $filteredValue = null ) |
|
| 154 | 154 | { |
| 155 | - $time = array_pop($this->hooks[current_filter()]['stack']); |
|
| 156 | - $time['stop'] = microtime(true); |
|
| 157 | - array_push($this->hooks[current_filter()]['time'], $time); |
|
| 155 | + $time = array_pop( $this->hooks[ current_filter() ][ 'stack' ] ); |
|
| 156 | + $time[ 'stop' ] = microtime( true ); |
|
| 157 | + array_push( $this->hooks[ current_filter() ][ 'time' ], $time ); |
|
| 158 | 158 | return $filteredValue; // In case this was a filter. |
| 159 | 159 | } |
| 160 | 160 | |
| 161 | - public function totalTimeForHook(array $data): float |
|
| 161 | + public function totalTimeForHook( array $data ): float |
|
| 162 | 162 | { |
| 163 | 163 | $total = 0; |
| 164 | - foreach ($data['time'] as $time) { |
|
| 165 | - $total += ($time['stop'] - $time['start']) * 1000; |
|
| 164 | + foreach( $data[ 'time' ] as $time ) { |
|
| 165 | + $total += ( $time[ 'stop' ] - $time[ 'start' ] ) * 1000; |
|
| 166 | 166 | } |
| 167 | 167 | return (float) $total; |
| 168 | 168 | } |
| 169 | 169 | |
| 170 | - protected function sortByTime(array $a, array $b): int |
|
| 170 | + protected function sortByTime( array $a, array $b ): int |
|
| 171 | 171 | { |
| 172 | - if ($a['total'] !== $b['total']) { |
|
| 173 | - return ($a['total'] > $b['total']) ? -1 : 1; |
|
| 172 | + if( $a[ 'total' ] !== $b[ 'total' ] ) { |
|
| 173 | + return ( $a[ 'total' ] > $b[ 'total' ] ) ? -1 : 1; |
|
| 174 | 174 | } |
| 175 | 175 | return 0; |
| 176 | 176 | } |
@@ -58,9 +58,11 @@ discard block |
||
| 58 | 58 | } |
| 59 | 59 | } |
| 60 | 60 | $this->hooks[$action]['callbacks'][$priority][] = sprintf('%s::%s', $object, $method); |
| 61 | - } elseif (is_object($callback['function'])) { |
|
| 61 | + } |
|
| 62 | + elseif (is_object($callback['function'])) { |
|
| 62 | 63 | $this->hooks[$action]['callbacks'][$priority][] = get_class($callback['function']); |
| 63 | - } else { |
|
| 64 | + } |
|
| 65 | + else { |
|
| 64 | 66 | $this->hooks[$action]['callbacks'][$priority][] = $callback['function']; |
| 65 | 67 | } |
| 66 | 68 | ++$this->hooks[$action]['callbacks_count']; |
@@ -84,7 +86,8 @@ discard block |
||
| 84 | 86 | $this->totalActions += $data['count']; |
| 85 | 87 | $this->callbacksForHook($action); |
| 86 | 88 | } |
| 87 | - $this->hooks = array_filter($this->hooks, function ($hook) { |
|
| 89 | + $this->hooks = array_filter($this->hooks, function ($hook) |
|
| 90 | + { |
|
| 88 | 91 | return !empty($hook['callbacks_count']); // skip blackbar callbacks |
| 89 | 92 | }); |
| 90 | 93 | uasort($this->hooks, [$this, 'sortByTime']); |
@@ -4,113 +4,113 @@ |
||
| 4 | 4 | |
| 5 | 5 | class Controller |
| 6 | 6 | { |
| 7 | - /** |
|
| 8 | - * @var Application |
|
| 9 | - */ |
|
| 10 | - protected $app; |
|
| 7 | + /** |
|
| 8 | + * @var Application |
|
| 9 | + */ |
|
| 10 | + protected $app; |
|
| 11 | 11 | |
| 12 | - public function __construct(Application $app) |
|
| 13 | - { |
|
| 14 | - $this->app = $app; |
|
| 15 | - } |
|
| 12 | + public function __construct(Application $app) |
|
| 13 | + { |
|
| 14 | + $this->app = $app; |
|
| 15 | + } |
|
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * @action admin_enqueue_scripts |
|
| 19 | - * @action wp_enqueue_scripts |
|
| 20 | - */ |
|
| 21 | - public function enqueueAssets(): void |
|
| 22 | - { |
|
| 23 | - wp_enqueue_script(Application::ID, $this->app->url('assets/main.js')); |
|
| 24 | - wp_enqueue_style(Application::ID, $this->app->url('assets/main.css'), ['dashicons']); |
|
| 25 | - wp_enqueue_style(Application::ID.'-syntax', $this->app->url('assets/syntax.css')); |
|
| 26 | - } |
|
| 17 | + /** |
|
| 18 | + * @action admin_enqueue_scripts |
|
| 19 | + * @action wp_enqueue_scripts |
|
| 20 | + */ |
|
| 21 | + public function enqueueAssets(): void |
|
| 22 | + { |
|
| 23 | + wp_enqueue_script(Application::ID, $this->app->url('assets/main.js')); |
|
| 24 | + wp_enqueue_style(Application::ID, $this->app->url('assets/main.css'), ['dashicons']); |
|
| 25 | + wp_enqueue_style(Application::ID.'-syntax', $this->app->url('assets/syntax.css')); |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * @param string $classes |
|
| 30 | - * @action admin_body_class |
|
| 31 | - */ |
|
| 32 | - public function filterBodyClasses($classes): string |
|
| 33 | - { |
|
| 34 | - return trim((string) $classes.' '.Application::ID); |
|
| 35 | - } |
|
| 28 | + /** |
|
| 29 | + * @param string $classes |
|
| 30 | + * @action admin_body_class |
|
| 31 | + */ |
|
| 32 | + public function filterBodyClasses($classes): string |
|
| 33 | + { |
|
| 34 | + return trim((string) $classes.' '.Application::ID); |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * @action all |
|
| 39 | - */ |
|
| 40 | - public function initActions(): void |
|
| 41 | - { |
|
| 42 | - if (!class_exists('Debug_Bar_Slow_Actions')) { |
|
| 43 | - $this->app->actions->startTimer(); |
|
| 44 | - } |
|
| 45 | - } |
|
| 37 | + /** |
|
| 38 | + * @action all |
|
| 39 | + */ |
|
| 40 | + public function initActions(): void |
|
| 41 | + { |
|
| 42 | + if (!class_exists('Debug_Bar_Slow_Actions')) { |
|
| 43 | + $this->app->actions->startTimer(); |
|
| 44 | + } |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * @action all |
|
| 49 | - */ |
|
| 50 | - public function initConsole(): void |
|
| 51 | - { |
|
| 52 | - if (Application::CONSOLE_HOOK !== func_get_arg(0)) { |
|
| 53 | - return; |
|
| 54 | - } |
|
| 55 | - $args = array_pad(func_get_args(), 4, ''); |
|
| 56 | - $args = array_combine(['hook', 'message', 'errno', 'location'], $args); |
|
| 57 | - $args = array_map('sanitize_textarea_field', $args); |
|
| 58 | - $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 4); |
|
| 59 | - $entry = array_pop($backtrace); // get the fourth backtrace entry |
|
| 60 | - if (empty(trim($args['location'])) && array_key_exists('file', $entry)) { |
|
| 61 | - $path = explode(ABSPATH, $entry['file']); |
|
| 62 | - $args['location'] = sprintf('%s:%s', array_pop($path), $entry['line']); |
|
| 63 | - } |
|
| 64 | - $this->app->console->store($args['message'], $args['errno'], $args['location']); |
|
| 65 | - } |
|
| 47 | + /** |
|
| 48 | + * @action all |
|
| 49 | + */ |
|
| 50 | + public function initConsole(): void |
|
| 51 | + { |
|
| 52 | + if (Application::CONSOLE_HOOK !== func_get_arg(0)) { |
|
| 53 | + return; |
|
| 54 | + } |
|
| 55 | + $args = array_pad(func_get_args(), 4, ''); |
|
| 56 | + $args = array_combine(['hook', 'message', 'errno', 'location'], $args); |
|
| 57 | + $args = array_map('sanitize_textarea_field', $args); |
|
| 58 | + $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 4); |
|
| 59 | + $entry = array_pop($backtrace); // get the fourth backtrace entry |
|
| 60 | + if (empty(trim($args['location'])) && array_key_exists('file', $entry)) { |
|
| 61 | + $path = explode(ABSPATH, $entry['file']); |
|
| 62 | + $args['location'] = sprintf('%s:%s', array_pop($path), $entry['line']); |
|
| 63 | + } |
|
| 64 | + $this->app->console->store($args['message'], $args['errno'], $args['location']); |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * @action all |
|
| 69 | - */ |
|
| 70 | - public function initProfiler(): void |
|
| 71 | - { |
|
| 72 | - $hook = func_get_arg(0); |
|
| 73 | - $name = func_num_args() > 1 ? func_get_arg(1) : 'Timer'; |
|
| 74 | - $microtime = microtime(true); |
|
| 75 | - if ('timer:start' === $hook) { |
|
| 76 | - $this->app->profiler->start($name); |
|
| 77 | - } elseif ('timer:stop' === $hook) { |
|
| 78 | - $this->app->profiler->stop($name); |
|
| 79 | - } elseif ('blackbar/profiler/noise' === $hook) { |
|
| 80 | - $this->app->profiler->setNoise($microtime); |
|
| 81 | - } elseif ('blackbar/profiler/start' === $hook) { |
|
| 82 | - $this->app->profiler->setStart($microtime); |
|
| 83 | - } elseif ('blackbar/profiler/stop' === $hook) { |
|
| 84 | - $this->app->profiler->setStop($microtime); |
|
| 85 | - } |
|
| 86 | - } |
|
| 67 | + /** |
|
| 68 | + * @action all |
|
| 69 | + */ |
|
| 70 | + public function initProfiler(): void |
|
| 71 | + { |
|
| 72 | + $hook = func_get_arg(0); |
|
| 73 | + $name = func_num_args() > 1 ? func_get_arg(1) : 'Timer'; |
|
| 74 | + $microtime = microtime(true); |
|
| 75 | + if ('timer:start' === $hook) { |
|
| 76 | + $this->app->profiler->start($name); |
|
| 77 | + } elseif ('timer:stop' === $hook) { |
|
| 78 | + $this->app->profiler->stop($name); |
|
| 79 | + } elseif ('blackbar/profiler/noise' === $hook) { |
|
| 80 | + $this->app->profiler->setNoise($microtime); |
|
| 81 | + } elseif ('blackbar/profiler/start' === $hook) { |
|
| 82 | + $this->app->profiler->setStart($microtime); |
|
| 83 | + } elseif ('blackbar/profiler/stop' === $hook) { |
|
| 84 | + $this->app->profiler->setStop($microtime); |
|
| 85 | + } |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | - /** |
|
| 89 | - * @action plugins_loaded |
|
| 90 | - */ |
|
| 91 | - public function registerLanguages(): void |
|
| 92 | - { |
|
| 93 | - load_plugin_textdomain(Application::ID, false, |
|
| 94 | - plugin_basename($this->app->path()).'/languages/' |
|
| 95 | - ); |
|
| 96 | - } |
|
| 88 | + /** |
|
| 89 | + * @action plugins_loaded |
|
| 90 | + */ |
|
| 91 | + public function registerLanguages(): void |
|
| 92 | + { |
|
| 93 | + load_plugin_textdomain(Application::ID, false, |
|
| 94 | + plugin_basename($this->app->path()).'/languages/' |
|
| 95 | + ); |
|
| 96 | + } |
|
| 97 | 97 | |
| 98 | - /** |
|
| 99 | - * @action admin_footer |
|
| 100 | - * @action wp_footer |
|
| 101 | - */ |
|
| 102 | - public function renderBar(): void |
|
| 103 | - { |
|
| 104 | - do_action('blackbar/profiler/stop'); // stop profiler |
|
| 105 | - $this->app->render('debug-bar', [ |
|
| 106 | - 'modules' => [ // order is intentional |
|
| 107 | - $this->app->console, |
|
| 108 | - $this->app->profiler, |
|
| 109 | - $this->app->queries, |
|
| 110 | - $this->app->actions, |
|
| 111 | - $this->app->templates, |
|
| 112 | - $this->app->globals, |
|
| 113 | - ], |
|
| 114 | - ]); |
|
| 115 | - } |
|
| 98 | + /** |
|
| 99 | + * @action admin_footer |
|
| 100 | + * @action wp_footer |
|
| 101 | + */ |
|
| 102 | + public function renderBar(): void |
|
| 103 | + { |
|
| 104 | + do_action('blackbar/profiler/stop'); // stop profiler |
|
| 105 | + $this->app->render('debug-bar', [ |
|
| 106 | + 'modules' => [ // order is intentional |
|
| 107 | + $this->app->console, |
|
| 108 | + $this->app->profiler, |
|
| 109 | + $this->app->queries, |
|
| 110 | + $this->app->actions, |
|
| 111 | + $this->app->templates, |
|
| 112 | + $this->app->globals, |
|
| 113 | + ], |
|
| 114 | + ]); |
|
| 115 | + } |
|
| 116 | 116 | } |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | */ |
| 10 | 10 | protected $app; |
| 11 | 11 | |
| 12 | - public function __construct(Application $app) |
|
| 12 | + public function __construct( Application $app ) |
|
| 13 | 13 | { |
| 14 | 14 | $this->app = $app; |
| 15 | 15 | } |
@@ -20,18 +20,18 @@ discard block |
||
| 20 | 20 | */ |
| 21 | 21 | public function enqueueAssets(): void |
| 22 | 22 | { |
| 23 | - wp_enqueue_script(Application::ID, $this->app->url('assets/main.js')); |
|
| 24 | - wp_enqueue_style(Application::ID, $this->app->url('assets/main.css'), ['dashicons']); |
|
| 25 | - wp_enqueue_style(Application::ID.'-syntax', $this->app->url('assets/syntax.css')); |
|
| 23 | + wp_enqueue_script( Application::ID, $this->app->url( 'assets/main.js' ) ); |
|
| 24 | + wp_enqueue_style( Application::ID, $this->app->url( 'assets/main.css' ), [ 'dashicons' ] ); |
|
| 25 | + wp_enqueue_style( Application::ID . '-syntax', $this->app->url( 'assets/syntax.css' ) ); |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | /** |
| 29 | 29 | * @param string $classes |
| 30 | 30 | * @action admin_body_class |
| 31 | 31 | */ |
| 32 | - public function filterBodyClasses($classes): string |
|
| 32 | + public function filterBodyClasses( $classes ): string |
|
| 33 | 33 | { |
| 34 | - return trim((string) $classes.' '.Application::ID); |
|
| 34 | + return trim( (string) $classes . ' ' . Application::ID ); |
|
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | /** |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | */ |
| 40 | 40 | public function initActions(): void |
| 41 | 41 | { |
| 42 | - if (!class_exists('Debug_Bar_Slow_Actions')) { |
|
| 42 | + if( !class_exists( 'Debug_Bar_Slow_Actions' ) ) { |
|
| 43 | 43 | $this->app->actions->startTimer(); |
| 44 | 44 | } |
| 45 | 45 | } |
@@ -49,19 +49,19 @@ discard block |
||
| 49 | 49 | */ |
| 50 | 50 | public function initConsole(): void |
| 51 | 51 | { |
| 52 | - if (Application::CONSOLE_HOOK !== func_get_arg(0)) { |
|
| 52 | + if( Application::CONSOLE_HOOK !== func_get_arg( 0 ) ) { |
|
| 53 | 53 | return; |
| 54 | 54 | } |
| 55 | - $args = array_pad(func_get_args(), 4, ''); |
|
| 56 | - $args = array_combine(['hook', 'message', 'errno', 'location'], $args); |
|
| 57 | - $args = array_map('sanitize_textarea_field', $args); |
|
| 58 | - $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 4); |
|
| 59 | - $entry = array_pop($backtrace); // get the fourth backtrace entry |
|
| 60 | - if (empty(trim($args['location'])) && array_key_exists('file', $entry)) { |
|
| 61 | - $path = explode(ABSPATH, $entry['file']); |
|
| 62 | - $args['location'] = sprintf('%s:%s', array_pop($path), $entry['line']); |
|
| 55 | + $args = array_pad( func_get_args(), 4, '' ); |
|
| 56 | + $args = array_combine( [ 'hook', 'message', 'errno', 'location' ], $args ); |
|
| 57 | + $args = array_map( 'sanitize_textarea_field', $args ); |
|
| 58 | + $backtrace = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS, 4 ); |
|
| 59 | + $entry = array_pop( $backtrace ); // get the fourth backtrace entry |
|
| 60 | + if( empty( trim( $args[ 'location' ] ) ) && array_key_exists( 'file', $entry ) ) { |
|
| 61 | + $path = explode( ABSPATH, $entry[ 'file' ] ); |
|
| 62 | + $args[ 'location' ] = sprintf( '%s:%s', array_pop( $path ), $entry[ 'line' ] ); |
|
| 63 | 63 | } |
| 64 | - $this->app->console->store($args['message'], $args['errno'], $args['location']); |
|
| 64 | + $this->app->console->store( $args[ 'message' ], $args[ 'errno' ], $args[ 'location' ] ); |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | /** |
@@ -69,19 +69,19 @@ discard block |
||
| 69 | 69 | */ |
| 70 | 70 | public function initProfiler(): void |
| 71 | 71 | { |
| 72 | - $hook = func_get_arg(0); |
|
| 73 | - $name = func_num_args() > 1 ? func_get_arg(1) : 'Timer'; |
|
| 74 | - $microtime = microtime(true); |
|
| 75 | - if ('timer:start' === $hook) { |
|
| 76 | - $this->app->profiler->start($name); |
|
| 77 | - } elseif ('timer:stop' === $hook) { |
|
| 78 | - $this->app->profiler->stop($name); |
|
| 79 | - } elseif ('blackbar/profiler/noise' === $hook) { |
|
| 80 | - $this->app->profiler->setNoise($microtime); |
|
| 81 | - } elseif ('blackbar/profiler/start' === $hook) { |
|
| 82 | - $this->app->profiler->setStart($microtime); |
|
| 83 | - } elseif ('blackbar/profiler/stop' === $hook) { |
|
| 84 | - $this->app->profiler->setStop($microtime); |
|
| 72 | + $hook = func_get_arg( 0 ); |
|
| 73 | + $name = func_num_args() > 1 ? func_get_arg( 1 ) : 'Timer'; |
|
| 74 | + $microtime = microtime( true ); |
|
| 75 | + if( 'timer:start' === $hook ) { |
|
| 76 | + $this->app->profiler->start( $name ); |
|
| 77 | + } elseif( 'timer:stop' === $hook ) { |
|
| 78 | + $this->app->profiler->stop( $name ); |
|
| 79 | + } elseif( 'blackbar/profiler/noise' === $hook ) { |
|
| 80 | + $this->app->profiler->setNoise( $microtime ); |
|
| 81 | + } elseif( 'blackbar/profiler/start' === $hook ) { |
|
| 82 | + $this->app->profiler->setStart( $microtime ); |
|
| 83 | + } elseif( 'blackbar/profiler/stop' === $hook ) { |
|
| 84 | + $this->app->profiler->setStop( $microtime ); |
|
| 85 | 85 | } |
| 86 | 86 | } |
| 87 | 87 | |
@@ -90,8 +90,8 @@ discard block |
||
| 90 | 90 | */ |
| 91 | 91 | public function registerLanguages(): void |
| 92 | 92 | { |
| 93 | - load_plugin_textdomain(Application::ID, false, |
|
| 94 | - plugin_basename($this->app->path()).'/languages/' |
|
| 93 | + load_plugin_textdomain( Application::ID, false, |
|
| 94 | + plugin_basename( $this->app->path() ) . '/languages/' |
|
| 95 | 95 | ); |
| 96 | 96 | } |
| 97 | 97 | |
@@ -101,8 +101,8 @@ discard block |
||
| 101 | 101 | */ |
| 102 | 102 | public function renderBar(): void |
| 103 | 103 | { |
| 104 | - do_action('blackbar/profiler/stop'); // stop profiler |
|
| 105 | - $this->app->render('debug-bar', [ |
|
| 104 | + do_action( 'blackbar/profiler/stop' ); // stop profiler |
|
| 105 | + $this->app->render( 'debug-bar', [ |
|
| 106 | 106 | 'modules' => [ // order is intentional |
| 107 | 107 | $this->app->console, |
| 108 | 108 | $this->app->profiler, |
@@ -111,6 +111,6 @@ discard block |
||
| 111 | 111 | $this->app->templates, |
| 112 | 112 | $this->app->globals, |
| 113 | 113 | ], |
| 114 | - ]); |
|
| 114 | + ] ); |
|
| 115 | 115 | } |
| 116 | 116 | } |
@@ -74,13 +74,17 @@ |
||
| 74 | 74 | $microtime = microtime(true); |
| 75 | 75 | if ('timer:start' === $hook) { |
| 76 | 76 | $this->app->profiler->start($name); |
| 77 | - } elseif ('timer:stop' === $hook) { |
|
| 77 | + } |
|
| 78 | + elseif ('timer:stop' === $hook) { |
|
| 78 | 79 | $this->app->profiler->stop($name); |
| 79 | - } elseif ('blackbar/profiler/noise' === $hook) { |
|
| 80 | + } |
|
| 81 | + elseif ('blackbar/profiler/noise' === $hook) { |
|
| 80 | 82 | $this->app->profiler->setNoise($microtime); |
| 81 | - } elseif ('blackbar/profiler/start' === $hook) { |
|
| 83 | + } |
|
| 84 | + elseif ('blackbar/profiler/start' === $hook) { |
|
| 82 | 85 | $this->app->profiler->setStart($microtime); |
| 83 | - } elseif ('blackbar/profiler/stop' === $hook) { |
|
| 86 | + } |
|
| 87 | + elseif ('blackbar/profiler/stop' === $hook) { |
|
| 84 | 88 | $this->app->profiler->setStop($microtime); |
| 85 | 89 | } |
| 86 | 90 | } |
@@ -7,160 +7,160 @@ |
||
| 7 | 7 | */ |
| 8 | 8 | class Dump |
| 9 | 9 | { |
| 10 | - public $depth; |
|
| 11 | - public $ignore; |
|
| 10 | + public $depth; |
|
| 11 | + public $ignore; |
|
| 12 | 12 | |
| 13 | - protected $level = 0; |
|
| 14 | - protected $result = []; |
|
| 15 | - protected $stack = []; |
|
| 13 | + protected $level = 0; |
|
| 14 | + protected $result = []; |
|
| 15 | + protected $stack = []; |
|
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * @param mixed $value |
|
| 19 | - * @param int $depth |
|
| 20 | - * @return string |
|
| 21 | - */ |
|
| 22 | - public function dump($value, $depth = 3, array $ignore = []) |
|
| 23 | - { |
|
| 24 | - $this->depth = $depth; |
|
| 25 | - $this->ignore = $ignore; |
|
| 26 | - $this->reset(); |
|
| 27 | - $this->inspect($value); |
|
| 28 | - $result = rtrim(implode('', $this->result), "\n"); |
|
| 29 | - $this->reset(); |
|
| 30 | - return $result; |
|
| 31 | - } |
|
| 17 | + /** |
|
| 18 | + * @param mixed $value |
|
| 19 | + * @param int $depth |
|
| 20 | + * @return string |
|
| 21 | + */ |
|
| 22 | + public function dump($value, $depth = 3, array $ignore = []) |
|
| 23 | + { |
|
| 24 | + $this->depth = $depth; |
|
| 25 | + $this->ignore = $ignore; |
|
| 26 | + $this->reset(); |
|
| 27 | + $this->inspect($value); |
|
| 28 | + $result = rtrim(implode('', $this->result), "\n"); |
|
| 29 | + $this->reset(); |
|
| 30 | + return $result; |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * @param string $key |
|
| 35 | - * @return string |
|
| 36 | - */ |
|
| 37 | - protected function formatKey($key) |
|
| 38 | - { |
|
| 39 | - $result = []; |
|
| 40 | - $result[] = str_repeat(' ', $this->level * 4).'['; |
|
| 41 | - if (is_string($key) && "\0" === $key[0]) { |
|
| 42 | - $keyParts = explode("\0", $key); |
|
| 43 | - $result[] = $keyParts[2].(('*' === $keyParts[1]) ? ':protected' : ':private'); |
|
| 44 | - } else { |
|
| 45 | - $result[] = $key; |
|
| 46 | - } |
|
| 47 | - $result[] = '] => '; |
|
| 48 | - return implode('', $result); |
|
| 49 | - } |
|
| 33 | + /** |
|
| 34 | + * @param string $key |
|
| 35 | + * @return string |
|
| 36 | + */ |
|
| 37 | + protected function formatKey($key) |
|
| 38 | + { |
|
| 39 | + $result = []; |
|
| 40 | + $result[] = str_repeat(' ', $this->level * 4).'['; |
|
| 41 | + if (is_string($key) && "\0" === $key[0]) { |
|
| 42 | + $keyParts = explode("\0", $key); |
|
| 43 | + $result[] = $keyParts[2].(('*' === $keyParts[1]) ? ':protected' : ':private'); |
|
| 44 | + } else { |
|
| 45 | + $result[] = $key; |
|
| 46 | + } |
|
| 47 | + $result[] = '] => '; |
|
| 48 | + return implode('', $result); |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * @param mixed $subject |
|
| 53 | - * @return void |
|
| 54 | - */ |
|
| 55 | - protected function inspect($subject) |
|
| 56 | - { |
|
| 57 | - ++$this->level; |
|
| 58 | - if ($subject instanceof \Closure) { |
|
| 59 | - $this->inspectClosure($subject); |
|
| 60 | - } elseif (is_object($subject)) { |
|
| 61 | - $this->inspectObject($subject); |
|
| 62 | - } elseif (is_array($subject)) { |
|
| 63 | - $this->inspectArray($subject); |
|
| 64 | - } else { |
|
| 65 | - $this->inspectPrimitive($subject); |
|
| 66 | - } |
|
| 67 | - --$this->level; |
|
| 68 | - } |
|
| 51 | + /** |
|
| 52 | + * @param mixed $subject |
|
| 53 | + * @return void |
|
| 54 | + */ |
|
| 55 | + protected function inspect($subject) |
|
| 56 | + { |
|
| 57 | + ++$this->level; |
|
| 58 | + if ($subject instanceof \Closure) { |
|
| 59 | + $this->inspectClosure($subject); |
|
| 60 | + } elseif (is_object($subject)) { |
|
| 61 | + $this->inspectObject($subject); |
|
| 62 | + } elseif (is_array($subject)) { |
|
| 63 | + $this->inspectArray($subject); |
|
| 64 | + } else { |
|
| 65 | + $this->inspectPrimitive($subject); |
|
| 66 | + } |
|
| 67 | + --$this->level; |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * @return void |
|
| 72 | - */ |
|
| 73 | - protected function inspectArray(array $subject) |
|
| 74 | - { |
|
| 75 | - if ($this->level > $this->depth) { |
|
| 76 | - $this->result[] = "Nested Array\n"; |
|
| 77 | - return; |
|
| 78 | - } |
|
| 79 | - if (empty($subject)) { |
|
| 80 | - $this->result[] = "Array ()\n"; |
|
| 81 | - return; |
|
| 82 | - } |
|
| 83 | - $this->result[] = "Array (\n"; |
|
| 84 | - foreach ($subject as $key => $val) { |
|
| 85 | - if (false === $this->isIgnoredKey($key)) { |
|
| 86 | - $this->result[] = str_repeat(' ', $this->level * 4).'['.$key.'] => '; |
|
| 87 | - $this->inspect($val); |
|
| 88 | - } |
|
| 89 | - } |
|
| 90 | - $this->result[] = str_repeat(' ', ($this->level - 1) * 4).")\n"; |
|
| 91 | - } |
|
| 70 | + /** |
|
| 71 | + * @return void |
|
| 72 | + */ |
|
| 73 | + protected function inspectArray(array $subject) |
|
| 74 | + { |
|
| 75 | + if ($this->level > $this->depth) { |
|
| 76 | + $this->result[] = "Nested Array\n"; |
|
| 77 | + return; |
|
| 78 | + } |
|
| 79 | + if (empty($subject)) { |
|
| 80 | + $this->result[] = "Array ()\n"; |
|
| 81 | + return; |
|
| 82 | + } |
|
| 83 | + $this->result[] = "Array (\n"; |
|
| 84 | + foreach ($subject as $key => $val) { |
|
| 85 | + if (false === $this->isIgnoredKey($key)) { |
|
| 86 | + $this->result[] = str_repeat(' ', $this->level * 4).'['.$key.'] => '; |
|
| 87 | + $this->inspect($val); |
|
| 88 | + } |
|
| 89 | + } |
|
| 90 | + $this->result[] = str_repeat(' ', ($this->level - 1) * 4).")\n"; |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - /** |
|
| 94 | - * @return void |
|
| 95 | - */ |
|
| 96 | - protected function inspectClosure(\Closure $subject) |
|
| 97 | - { |
|
| 98 | - $reflection = new \ReflectionFunction($subject); |
|
| 99 | - $params = array_map(function ($param) { |
|
| 100 | - return ($param->isPassedByReference() ? '&$' : '$').$param->name; |
|
| 101 | - }, $reflection->getParameters()); |
|
| 102 | - $this->result[] = 'Closure ('.implode(', ', $params).') { ... }'."\n"; |
|
| 103 | - } |
|
| 93 | + /** |
|
| 94 | + * @return void |
|
| 95 | + */ |
|
| 96 | + protected function inspectClosure(\Closure $subject) |
|
| 97 | + { |
|
| 98 | + $reflection = new \ReflectionFunction($subject); |
|
| 99 | + $params = array_map(function ($param) { |
|
| 100 | + return ($param->isPassedByReference() ? '&$' : '$').$param->name; |
|
| 101 | + }, $reflection->getParameters()); |
|
| 102 | + $this->result[] = 'Closure ('.implode(', ', $params).') { ... }'."\n"; |
|
| 103 | + } |
|
| 104 | 104 | |
| 105 | - /** |
|
| 106 | - * @param object $subject |
|
| 107 | - * @return void |
|
| 108 | - */ |
|
| 109 | - protected function inspectObject($subject) |
|
| 110 | - { |
|
| 111 | - $classname = get_class($subject); |
|
| 112 | - if ($this->level > $this->depth) { |
|
| 113 | - $this->result[] = 'Nested '.$classname." Object\n"; |
|
| 114 | - return; |
|
| 115 | - } |
|
| 116 | - if ($subject instanceof \ArrayObject) { |
|
| 117 | - $this->result[] = $classname." ArrayObject (\n"; |
|
| 118 | - } else { |
|
| 119 | - $this->result[] = $classname." Object (\n"; |
|
| 120 | - $subject = (array) $subject; |
|
| 121 | - } |
|
| 122 | - foreach ($subject as $key => $val) { |
|
| 123 | - if (false === $this->isIgnoredKey($key)) { |
|
| 124 | - $this->result[] = $this->formatKey($key); |
|
| 125 | - $this->inspect($val); |
|
| 126 | - } |
|
| 127 | - } |
|
| 128 | - $this->result[] = str_repeat(' ', ($this->level - 1) * 4).")\n"; |
|
| 129 | - } |
|
| 105 | + /** |
|
| 106 | + * @param object $subject |
|
| 107 | + * @return void |
|
| 108 | + */ |
|
| 109 | + protected function inspectObject($subject) |
|
| 110 | + { |
|
| 111 | + $classname = get_class($subject); |
|
| 112 | + if ($this->level > $this->depth) { |
|
| 113 | + $this->result[] = 'Nested '.$classname." Object\n"; |
|
| 114 | + return; |
|
| 115 | + } |
|
| 116 | + if ($subject instanceof \ArrayObject) { |
|
| 117 | + $this->result[] = $classname." ArrayObject (\n"; |
|
| 118 | + } else { |
|
| 119 | + $this->result[] = $classname." Object (\n"; |
|
| 120 | + $subject = (array) $subject; |
|
| 121 | + } |
|
| 122 | + foreach ($subject as $key => $val) { |
|
| 123 | + if (false === $this->isIgnoredKey($key)) { |
|
| 124 | + $this->result[] = $this->formatKey($key); |
|
| 125 | + $this->inspect($val); |
|
| 126 | + } |
|
| 127 | + } |
|
| 128 | + $this->result[] = str_repeat(' ', ($this->level - 1) * 4).")\n"; |
|
| 129 | + } |
|
| 130 | 130 | |
| 131 | - /** |
|
| 132 | - * @param mixed $subject |
|
| 133 | - * @return void |
|
| 134 | - */ |
|
| 135 | - protected function inspectPrimitive($subject) |
|
| 136 | - { |
|
| 137 | - if (true === $subject) { |
|
| 138 | - $subject = '(bool) true'; |
|
| 139 | - } elseif (false === $subject) { |
|
| 140 | - $subject = '(bool) false'; |
|
| 141 | - } elseif (null === $subject) { |
|
| 142 | - $subject = '(null)'; |
|
| 143 | - } |
|
| 144 | - $this->result[] = $subject."\n"; |
|
| 145 | - } |
|
| 131 | + /** |
|
| 132 | + * @param mixed $subject |
|
| 133 | + * @return void |
|
| 134 | + */ |
|
| 135 | + protected function inspectPrimitive($subject) |
|
| 136 | + { |
|
| 137 | + if (true === $subject) { |
|
| 138 | + $subject = '(bool) true'; |
|
| 139 | + } elseif (false === $subject) { |
|
| 140 | + $subject = '(bool) false'; |
|
| 141 | + } elseif (null === $subject) { |
|
| 142 | + $subject = '(null)'; |
|
| 143 | + } |
|
| 144 | + $this->result[] = $subject."\n"; |
|
| 145 | + } |
|
| 146 | 146 | |
| 147 | - /** |
|
| 148 | - * @param string $key |
|
| 149 | - * @return bool |
|
| 150 | - */ |
|
| 151 | - protected function isIgnoredKey($key) |
|
| 152 | - { |
|
| 153 | - return in_array($key, $this->ignore); |
|
| 154 | - } |
|
| 147 | + /** |
|
| 148 | + * @param string $key |
|
| 149 | + * @return bool |
|
| 150 | + */ |
|
| 151 | + protected function isIgnoredKey($key) |
|
| 152 | + { |
|
| 153 | + return in_array($key, $this->ignore); |
|
| 154 | + } |
|
| 155 | 155 | |
| 156 | - /** |
|
| 157 | - * @return void |
|
| 158 | - */ |
|
| 159 | - protected function reset() |
|
| 160 | - { |
|
| 161 | - $this->level = 0; |
|
| 162 | - $this->result = []; |
|
| 163 | - $this->stack = []; |
|
| 164 | - } |
|
| 156 | + /** |
|
| 157 | + * @return void |
|
| 158 | + */ |
|
| 159 | + protected function reset() |
|
| 160 | + { |
|
| 161 | + $this->level = 0; |
|
| 162 | + $this->result = []; |
|
| 163 | + $this->stack = []; |
|
| 164 | + } |
|
| 165 | 165 | } |
| 166 | 166 | |
@@ -11,21 +11,21 @@ discard block |
||
| 11 | 11 | public $ignore; |
| 12 | 12 | |
| 13 | 13 | protected $level = 0; |
| 14 | - protected $result = []; |
|
| 15 | - protected $stack = []; |
|
| 14 | + protected $result = [ ]; |
|
| 15 | + protected $stack = [ ]; |
|
| 16 | 16 | |
| 17 | 17 | /** |
| 18 | 18 | * @param mixed $value |
| 19 | 19 | * @param int $depth |
| 20 | 20 | * @return string |
| 21 | 21 | */ |
| 22 | - public function dump($value, $depth = 3, array $ignore = []) |
|
| 22 | + public function dump( $value, $depth = 3, array $ignore = [ ] ) |
|
| 23 | 23 | { |
| 24 | 24 | $this->depth = $depth; |
| 25 | 25 | $this->ignore = $ignore; |
| 26 | 26 | $this->reset(); |
| 27 | - $this->inspect($value); |
|
| 28 | - $result = rtrim(implode('', $this->result), "\n"); |
|
| 27 | + $this->inspect( $value ); |
|
| 28 | + $result = rtrim( implode( '', $this->result ), "\n" ); |
|
| 29 | 29 | $this->reset(); |
| 30 | 30 | return $result; |
| 31 | 31 | } |
@@ -34,35 +34,35 @@ discard block |
||
| 34 | 34 | * @param string $key |
| 35 | 35 | * @return string |
| 36 | 36 | */ |
| 37 | - protected function formatKey($key) |
|
| 37 | + protected function formatKey( $key ) |
|
| 38 | 38 | { |
| 39 | - $result = []; |
|
| 40 | - $result[] = str_repeat(' ', $this->level * 4).'['; |
|
| 41 | - if (is_string($key) && "\0" === $key[0]) { |
|
| 42 | - $keyParts = explode("\0", $key); |
|
| 43 | - $result[] = $keyParts[2].(('*' === $keyParts[1]) ? ':protected' : ':private'); |
|
| 39 | + $result = [ ]; |
|
| 40 | + $result[ ] = str_repeat( ' ', $this->level * 4 ) . '['; |
|
| 41 | + if( is_string( $key ) && "\0" === $key[ 0 ] ) { |
|
| 42 | + $keyParts = explode( "\0", $key ); |
|
| 43 | + $result[ ] = $keyParts[ 2 ] . ( ( '*' === $keyParts[ 1 ] ) ? ':protected' : ':private' ); |
|
| 44 | 44 | } else { |
| 45 | - $result[] = $key; |
|
| 45 | + $result[ ] = $key; |
|
| 46 | 46 | } |
| 47 | - $result[] = '] => '; |
|
| 48 | - return implode('', $result); |
|
| 47 | + $result[ ] = '] => '; |
|
| 48 | + return implode( '', $result ); |
|
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | /** |
| 52 | 52 | * @param mixed $subject |
| 53 | 53 | * @return void |
| 54 | 54 | */ |
| 55 | - protected function inspect($subject) |
|
| 55 | + protected function inspect( $subject ) |
|
| 56 | 56 | { |
| 57 | 57 | ++$this->level; |
| 58 | - if ($subject instanceof \Closure) { |
|
| 59 | - $this->inspectClosure($subject); |
|
| 60 | - } elseif (is_object($subject)) { |
|
| 61 | - $this->inspectObject($subject); |
|
| 62 | - } elseif (is_array($subject)) { |
|
| 63 | - $this->inspectArray($subject); |
|
| 58 | + if( $subject instanceof \Closure ) { |
|
| 59 | + $this->inspectClosure( $subject ); |
|
| 60 | + } elseif( is_object( $subject ) ) { |
|
| 61 | + $this->inspectObject( $subject ); |
|
| 62 | + } elseif( is_array( $subject ) ) { |
|
| 63 | + $this->inspectArray( $subject ); |
|
| 64 | 64 | } else { |
| 65 | - $this->inspectPrimitive($subject); |
|
| 65 | + $this->inspectPrimitive( $subject ); |
|
| 66 | 66 | } |
| 67 | 67 | --$this->level; |
| 68 | 68 | } |
@@ -70,87 +70,87 @@ discard block |
||
| 70 | 70 | /** |
| 71 | 71 | * @return void |
| 72 | 72 | */ |
| 73 | - protected function inspectArray(array $subject) |
|
| 73 | + protected function inspectArray( array $subject ) |
|
| 74 | 74 | { |
| 75 | - if ($this->level > $this->depth) { |
|
| 76 | - $this->result[] = "Nested Array\n"; |
|
| 75 | + if( $this->level > $this->depth ) { |
|
| 76 | + $this->result[ ] = "Nested Array\n"; |
|
| 77 | 77 | return; |
| 78 | 78 | } |
| 79 | - if (empty($subject)) { |
|
| 80 | - $this->result[] = "Array ()\n"; |
|
| 79 | + if( empty( $subject ) ) { |
|
| 80 | + $this->result[ ] = "Array ()\n"; |
|
| 81 | 81 | return; |
| 82 | 82 | } |
| 83 | - $this->result[] = "Array (\n"; |
|
| 84 | - foreach ($subject as $key => $val) { |
|
| 85 | - if (false === $this->isIgnoredKey($key)) { |
|
| 86 | - $this->result[] = str_repeat(' ', $this->level * 4).'['.$key.'] => '; |
|
| 87 | - $this->inspect($val); |
|
| 83 | + $this->result[ ] = "Array (\n"; |
|
| 84 | + foreach( $subject as $key => $val ) { |
|
| 85 | + if( false === $this->isIgnoredKey( $key ) ) { |
|
| 86 | + $this->result[ ] = str_repeat( ' ', $this->level * 4 ) . '[' . $key . '] => '; |
|
| 87 | + $this->inspect( $val ); |
|
| 88 | 88 | } |
| 89 | 89 | } |
| 90 | - $this->result[] = str_repeat(' ', ($this->level - 1) * 4).")\n"; |
|
| 90 | + $this->result[ ] = str_repeat( ' ', ( $this->level - 1 ) * 4 ) . ")\n"; |
|
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | /** |
| 94 | 94 | * @return void |
| 95 | 95 | */ |
| 96 | - protected function inspectClosure(\Closure $subject) |
|
| 96 | + protected function inspectClosure( \Closure $subject ) |
|
| 97 | 97 | { |
| 98 | - $reflection = new \ReflectionFunction($subject); |
|
| 99 | - $params = array_map(function ($param) { |
|
| 100 | - return ($param->isPassedByReference() ? '&$' : '$').$param->name; |
|
| 101 | - }, $reflection->getParameters()); |
|
| 102 | - $this->result[] = 'Closure ('.implode(', ', $params).') { ... }'."\n"; |
|
| 98 | + $reflection = new \ReflectionFunction( $subject ); |
|
| 99 | + $params = array_map( function( $param ) { |
|
| 100 | + return ( $param->isPassedByReference() ? '&$' : '$' ) . $param->name; |
|
| 101 | + }, $reflection->getParameters() ); |
|
| 102 | + $this->result[ ] = 'Closure (' . implode( ', ', $params ) . ') { ... }' . "\n"; |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | /** |
| 106 | 106 | * @param object $subject |
| 107 | 107 | * @return void |
| 108 | 108 | */ |
| 109 | - protected function inspectObject($subject) |
|
| 109 | + protected function inspectObject( $subject ) |
|
| 110 | 110 | { |
| 111 | - $classname = get_class($subject); |
|
| 112 | - if ($this->level > $this->depth) { |
|
| 113 | - $this->result[] = 'Nested '.$classname." Object\n"; |
|
| 111 | + $classname = get_class( $subject ); |
|
| 112 | + if( $this->level > $this->depth ) { |
|
| 113 | + $this->result[ ] = 'Nested ' . $classname . " Object\n"; |
|
| 114 | 114 | return; |
| 115 | 115 | } |
| 116 | - if ($subject instanceof \ArrayObject) { |
|
| 117 | - $this->result[] = $classname." ArrayObject (\n"; |
|
| 116 | + if( $subject instanceof \ArrayObject ) { |
|
| 117 | + $this->result[ ] = $classname . " ArrayObject (\n"; |
|
| 118 | 118 | } else { |
| 119 | - $this->result[] = $classname." Object (\n"; |
|
| 119 | + $this->result[ ] = $classname . " Object (\n"; |
|
| 120 | 120 | $subject = (array) $subject; |
| 121 | 121 | } |
| 122 | - foreach ($subject as $key => $val) { |
|
| 123 | - if (false === $this->isIgnoredKey($key)) { |
|
| 124 | - $this->result[] = $this->formatKey($key); |
|
| 125 | - $this->inspect($val); |
|
| 122 | + foreach( $subject as $key => $val ) { |
|
| 123 | + if( false === $this->isIgnoredKey( $key ) ) { |
|
| 124 | + $this->result[ ] = $this->formatKey( $key ); |
|
| 125 | + $this->inspect( $val ); |
|
| 126 | 126 | } |
| 127 | 127 | } |
| 128 | - $this->result[] = str_repeat(' ', ($this->level - 1) * 4).")\n"; |
|
| 128 | + $this->result[ ] = str_repeat( ' ', ( $this->level - 1 ) * 4 ) . ")\n"; |
|
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | /** |
| 132 | 132 | * @param mixed $subject |
| 133 | 133 | * @return void |
| 134 | 134 | */ |
| 135 | - protected function inspectPrimitive($subject) |
|
| 135 | + protected function inspectPrimitive( $subject ) |
|
| 136 | 136 | { |
| 137 | - if (true === $subject) { |
|
| 137 | + if( true === $subject ) { |
|
| 138 | 138 | $subject = '(bool) true'; |
| 139 | - } elseif (false === $subject) { |
|
| 139 | + } elseif( false === $subject ) { |
|
| 140 | 140 | $subject = '(bool) false'; |
| 141 | - } elseif (null === $subject) { |
|
| 141 | + } elseif( null === $subject ) { |
|
| 142 | 142 | $subject = '(null)'; |
| 143 | 143 | } |
| 144 | - $this->result[] = $subject."\n"; |
|
| 144 | + $this->result[ ] = $subject . "\n"; |
|
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | /** |
| 148 | 148 | * @param string $key |
| 149 | 149 | * @return bool |
| 150 | 150 | */ |
| 151 | - protected function isIgnoredKey($key) |
|
| 151 | + protected function isIgnoredKey( $key ) |
|
| 152 | 152 | { |
| 153 | - return in_array($key, $this->ignore); |
|
| 153 | + return in_array( $key, $this->ignore ); |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | /** |
@@ -159,8 +159,8 @@ discard block |
||
| 159 | 159 | protected function reset() |
| 160 | 160 | { |
| 161 | 161 | $this->level = 0; |
| 162 | - $this->result = []; |
|
| 163 | - $this->stack = []; |
|
| 162 | + $this->result = [ ]; |
|
| 163 | + $this->stack = [ ]; |
|
| 164 | 164 | } |
| 165 | 165 | } |
| 166 | 166 | |
@@ -41,7 +41,8 @@ discard block |
||
| 41 | 41 | if (is_string($key) && "\0" === $key[0]) { |
| 42 | 42 | $keyParts = explode("\0", $key); |
| 43 | 43 | $result[] = $keyParts[2].(('*' === $keyParts[1]) ? ':protected' : ':private'); |
| 44 | - } else { |
|
| 44 | + } |
|
| 45 | + else { |
|
| 45 | 46 | $result[] = $key; |
| 46 | 47 | } |
| 47 | 48 | $result[] = '] => '; |
@@ -57,11 +58,14 @@ discard block |
||
| 57 | 58 | ++$this->level; |
| 58 | 59 | if ($subject instanceof \Closure) { |
| 59 | 60 | $this->inspectClosure($subject); |
| 60 | - } elseif (is_object($subject)) { |
|
| 61 | + } |
|
| 62 | + elseif (is_object($subject)) { |
|
| 61 | 63 | $this->inspectObject($subject); |
| 62 | - } elseif (is_array($subject)) { |
|
| 64 | + } |
|
| 65 | + elseif (is_array($subject)) { |
|
| 63 | 66 | $this->inspectArray($subject); |
| 64 | - } else { |
|
| 67 | + } |
|
| 68 | + else { |
|
| 65 | 69 | $this->inspectPrimitive($subject); |
| 66 | 70 | } |
| 67 | 71 | --$this->level; |
@@ -96,7 +100,8 @@ discard block |
||
| 96 | 100 | protected function inspectClosure(\Closure $subject) |
| 97 | 101 | { |
| 98 | 102 | $reflection = new \ReflectionFunction($subject); |
| 99 | - $params = array_map(function ($param) { |
|
| 103 | + $params = array_map(function ($param) |
|
| 104 | + { |
|
| 100 | 105 | return ($param->isPassedByReference() ? '&$' : '$').$param->name; |
| 101 | 106 | }, $reflection->getParameters()); |
| 102 | 107 | $this->result[] = 'Closure ('.implode(', ', $params).') { ... }'."\n"; |
@@ -115,7 +120,8 @@ discard block |
||
| 115 | 120 | } |
| 116 | 121 | if ($subject instanceof \ArrayObject) { |
| 117 | 122 | $this->result[] = $classname." ArrayObject (\n"; |
| 118 | - } else { |
|
| 123 | + } |
|
| 124 | + else { |
|
| 119 | 125 | $this->result[] = $classname." Object (\n"; |
| 120 | 126 | $subject = (array) $subject; |
| 121 | 127 | } |
@@ -136,9 +142,11 @@ discard block |
||
| 136 | 142 | { |
| 137 | 143 | if (true === $subject) { |
| 138 | 144 | $subject = '(bool) true'; |
| 139 | - } elseif (false === $subject) { |
|
| 145 | + } |
|
| 146 | + elseif (false === $subject) { |
|
| 140 | 147 | $subject = '(bool) false'; |
| 141 | - } elseif (null === $subject) { |
|
| 148 | + } |
|
| 149 | + elseif (null === $subject) { |
|
| 142 | 150 | $subject = '(null)'; |
| 143 | 151 | } |
| 144 | 152 | $this->result[] = $subject."\n"; |
@@ -1,14 +1,14 @@ discard block |
||
| 1 | -<?php defined('WPINC') || die; ?> |
|
| 1 | +<?php defined( 'WPINC' ) || die; ?> |
|
| 2 | 2 | |
| 3 | 3 | <div id="glbb"> |
| 4 | - <?php foreach ($modules as $module) : /* Ensure that the console entries are loaded last */ ?> |
|
| 5 | - <?php if (!$module->isVisible() || 'glbb-console' === $module->id()) continue; ?> |
|
| 4 | + <?php foreach( $modules as $module ) : /* Ensure that the console entries are loaded last */ ?> |
|
| 5 | + <?php if( !$module->isVisible() || 'glbb-console' === $module->id() ) continue; ?> |
|
| 6 | 6 | <div id="<?= $module->id(); ?>" class="glbb-panel glbb-hidden"> |
| 7 | 7 | <?php $module->render(); ?> |
| 8 | 8 | </div> |
| 9 | 9 | <?php endforeach; ?> |
| 10 | - <?php foreach ($modules as $module) : /* Ensure that the console entries are loaded last */ ?> |
|
| 11 | - <?php if (!$module->isVisible() || 'glbb-console' !== $module->id()) continue; ?> |
|
| 10 | + <?php foreach( $modules as $module ) : /* Ensure that the console entries are loaded last */ ?> |
|
| 11 | + <?php if( !$module->isVisible() || 'glbb-console' !== $module->id() ) continue; ?> |
|
| 12 | 12 | <div id="<?= $module->id(); ?>" class="glbb-panel glbb-hidden"> |
| 13 | 13 | <?php $module->render(); ?> |
| 14 | 14 | </div> |
@@ -16,19 +16,19 @@ discard block |
||
| 16 | 16 | <div class="glbb-panel-links"> |
| 17 | 17 | <a href="#" class="dashicons-before glbb-toggle"> |
| 18 | 18 | <span class="screen-reader-text"> |
| 19 | - <?= esc_html__('Toggle', 'blackbar'); ?> |
|
| 19 | + <?= esc_html__( 'Toggle', 'blackbar' ); ?> |
|
| 20 | 20 | </span> |
| 21 | 21 | </a> |
| 22 | - <?php foreach ($modules as $module) : ?> |
|
| 23 | - <?php if (!$module->isVisible()) continue; ?> |
|
| 24 | - <a href="#" data-panel="<?= esc_attr($module->id()); ?>" class="dashicons-before <?= $module->id(); ?>"> |
|
| 22 | + <?php foreach( $modules as $module ) : ?> |
|
| 23 | + <?php if( !$module->isVisible() ) continue; ?> |
|
| 24 | + <a href="#" data-panel="<?= esc_attr( $module->id() ); ?>" class="dashicons-before <?= $module->id(); ?>"> |
|
| 25 | 25 | <span><?= $module->label(); ?></span> |
| 26 | 26 | </a> |
| 27 | 27 | <?php endforeach; ?> |
| 28 | 28 | <div> |
| 29 | 29 | <a href="#" class="dashicons-before glbb-close"> |
| 30 | 30 | <span class="screen-reader-text"> |
| 31 | - <?= esc_html__('Close', 'blackbar'); ?> |
|
| 31 | + <?= esc_html__( 'Close', 'blackbar' ); ?> |
|
| 32 | 32 | </span> |
| 33 | 33 | </a> |
| 34 | 34 | </div> |
@@ -2,13 +2,19 @@ discard block |
||
| 2 | 2 | |
| 3 | 3 | <div id="glbb"> |
| 4 | 4 | <?php foreach ($modules as $module) : /* Ensure that the console entries are loaded last */ ?> |
| 5 | - <?php if (!$module->isVisible() || 'glbb-console' === $module->id()) continue; ?> |
|
| 5 | + <?php if (!$module->isVisible() || 'glbb-console' === $module->id()) { |
|
| 6 | + continue; |
|
| 7 | +} |
|
| 8 | +?> |
|
| 6 | 9 | <div id="<?= $module->id(); ?>" class="glbb-panel glbb-hidden"> |
| 7 | 10 | <?php $module->render(); ?> |
| 8 | 11 | </div> |
| 9 | 12 | <?php endforeach; ?> |
| 10 | 13 | <?php foreach ($modules as $module) : /* Ensure that the console entries are loaded last */ ?> |
| 11 | - <?php if (!$module->isVisible() || 'glbb-console' !== $module->id()) continue; ?> |
|
| 14 | + <?php if (!$module->isVisible() || 'glbb-console' !== $module->id()) { |
|
| 15 | + continue; |
|
| 16 | +} |
|
| 17 | +?> |
|
| 12 | 18 | <div id="<?= $module->id(); ?>" class="glbb-panel glbb-hidden"> |
| 13 | 19 | <?php $module->render(); ?> |
| 14 | 20 | </div> |
@@ -20,7 +26,10 @@ discard block |
||
| 20 | 26 | </span> |
| 21 | 27 | </a> |
| 22 | 28 | <?php foreach ($modules as $module) : ?> |
| 23 | - <?php if (!$module->isVisible()) continue; ?> |
|
| 29 | + <?php if (!$module->isVisible()) { |
|
| 30 | + continue; |
|
| 31 | +} |
|
| 32 | +?> |
|
| 24 | 33 | <a href="#" data-panel="<?= esc_attr($module->id()); ?>" class="dashicons-before <?= $module->id(); ?>"> |
| 25 | 34 | <span><?= $module->label(); ?></span> |
| 26 | 35 | </a> |