@@ -6,79 +6,79 @@ |
||
| 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 | - if (is_admin() && $screen = get_current_screen()) { |
|
| 30 | - $reflection = new \ReflectionClass($screen); |
|
| 31 | - $properties = $reflection->getProperties(\ReflectionProperty::IS_PUBLIC); |
|
| 32 | - $values = []; |
|
| 33 | - foreach ($properties as $property) { |
|
| 34 | - $values[$property->getName()] = $property->getValue($screen); |
|
| 35 | - } |
|
| 36 | - $this->entries[] = [ |
|
| 37 | - 'name' => 'WP_Screen', |
|
| 38 | - 'value' => var_export($values, true), |
|
| 39 | - ]; |
|
| 40 | - } |
|
| 41 | - $this->entries[] = [ |
|
| 42 | - 'name' => '$_GET', |
|
| 43 | - 'value' => var_export($_GET, true), |
|
| 44 | - ]; |
|
| 45 | - $this->entries[] = [ |
|
| 46 | - 'name' => '$_SERVER', |
|
| 47 | - 'value' => var_export($_SERVER, true), |
|
| 48 | - ]; |
|
| 49 | - $this->entries[] = [ |
|
| 50 | - 'name' => '$_COOKIE', |
|
| 51 | - 'value' => var_export($_COOKIE, true), |
|
| 52 | - ]; |
|
| 53 | - $this->entries[] = [ |
|
| 54 | - 'name' => '$_SESSION', |
|
| 55 | - 'value' => var_export(isset($_SESSION) ? $_SESSION : [], true), |
|
| 56 | - ]; |
|
| 57 | - return $this->entries; |
|
| 58 | - } |
|
| 24 | + public function entries(): array |
|
| 25 | + { |
|
| 26 | + if (!empty($this->entries)) { |
|
| 27 | + return $this->entries; |
|
| 28 | + } |
|
| 29 | + if (is_admin() && $screen = get_current_screen()) { |
|
| 30 | + $reflection = new \ReflectionClass($screen); |
|
| 31 | + $properties = $reflection->getProperties(\ReflectionProperty::IS_PUBLIC); |
|
| 32 | + $values = []; |
|
| 33 | + foreach ($properties as $property) { |
|
| 34 | + $values[$property->getName()] = $property->getValue($screen); |
|
| 35 | + } |
|
| 36 | + $this->entries[] = [ |
|
| 37 | + 'name' => 'WP_Screen', |
|
| 38 | + 'value' => var_export($values, true), |
|
| 39 | + ]; |
|
| 40 | + } |
|
| 41 | + $this->entries[] = [ |
|
| 42 | + 'name' => '$_GET', |
|
| 43 | + 'value' => var_export($_GET, true), |
|
| 44 | + ]; |
|
| 45 | + $this->entries[] = [ |
|
| 46 | + 'name' => '$_SERVER', |
|
| 47 | + 'value' => var_export($_SERVER, true), |
|
| 48 | + ]; |
|
| 49 | + $this->entries[] = [ |
|
| 50 | + 'name' => '$_COOKIE', |
|
| 51 | + 'value' => var_export($_COOKIE, true), |
|
| 52 | + ]; |
|
| 53 | + $this->entries[] = [ |
|
| 54 | + 'name' => '$_SESSION', |
|
| 55 | + 'value' => var_export(isset($_SESSION) ? $_SESSION : [], true), |
|
| 56 | + ]; |
|
| 57 | + return $this->entries; |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - public function hasEntries(): bool |
|
| 61 | - { |
|
| 62 | - return !empty($this->entries()); |
|
| 63 | - } |
|
| 60 | + public function hasEntries(): bool |
|
| 61 | + { |
|
| 62 | + return !empty($this->entries()); |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - public function id(): string |
|
| 66 | - { |
|
| 67 | - return 'glbb-globals'; |
|
| 68 | - } |
|
| 65 | + public function id(): string |
|
| 66 | + { |
|
| 67 | + return 'glbb-globals'; |
|
| 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 | - return __('Globals', 'blackbar'); |
|
| 78 | - } |
|
| 75 | + public function label(): string |
|
| 76 | + { |
|
| 77 | + return __('Globals', 'blackbar'); |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - public function render(): void |
|
| 81 | - { |
|
| 82 | - $this->app->render('panels/globals', ['globals' => $this]); |
|
| 83 | - } |
|
| 80 | + public function render(): void |
|
| 81 | + { |
|
| 82 | + $this->app->render('panels/globals', ['globals' => $this]); |
|
| 83 | + } |
|
| 84 | 84 | } |
@@ -6,64 +6,64 @@ |
||
| 6 | 6 | |
| 7 | 7 | class Templates 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 | - if (class_exists('\GeminiLabs\Castor\Facades\Development') |
|
| 30 | - && class_exists('\GeminiLabs\Castor\Helpers\Development') |
|
| 31 | - && method_exists('\GeminiLabs\Castor\Helpers\Development', 'templatePaths')) { // @phpstan-ignore-line |
|
| 32 | - $this->entries = \GeminiLabs\Castor\Facades\Development::templatePaths(); |
|
| 33 | - } else { |
|
| 34 | - $files = array_values(array_filter(get_included_files(), function ($file) { |
|
| 35 | - $bool = false !== strpos($file, '/themes/') && false === strpos($file, '/functions.php'); |
|
| 36 | - return (bool) apply_filters('blackbar/templates/file', $bool, $file); |
|
| 37 | - })); |
|
| 38 | - $this->entries = array_map(function ($file) { |
|
| 39 | - return str_replace(trailingslashit(WP_CONTENT_DIR), '', $file); |
|
| 40 | - }, $files); |
|
| 41 | - } |
|
| 42 | - return $this->entries; |
|
| 43 | - } |
|
| 24 | + public function entries(): array |
|
| 25 | + { |
|
| 26 | + if (!empty($this->entries)) { |
|
| 27 | + return $this->entries; |
|
| 28 | + } |
|
| 29 | + if (class_exists('\GeminiLabs\Castor\Facades\Development') |
|
| 30 | + && class_exists('\GeminiLabs\Castor\Helpers\Development') |
|
| 31 | + && method_exists('\GeminiLabs\Castor\Helpers\Development', 'templatePaths')) { // @phpstan-ignore-line |
|
| 32 | + $this->entries = \GeminiLabs\Castor\Facades\Development::templatePaths(); |
|
| 33 | + } else { |
|
| 34 | + $files = array_values(array_filter(get_included_files(), function ($file) { |
|
| 35 | + $bool = false !== strpos($file, '/themes/') && false === strpos($file, '/functions.php'); |
|
| 36 | + return (bool) apply_filters('blackbar/templates/file', $bool, $file); |
|
| 37 | + })); |
|
| 38 | + $this->entries = array_map(function ($file) { |
|
| 39 | + return str_replace(trailingslashit(WP_CONTENT_DIR), '', $file); |
|
| 40 | + }, $files); |
|
| 41 | + } |
|
| 42 | + return $this->entries; |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - public function hasEntries(): bool |
|
| 46 | - { |
|
| 47 | - return !empty($this->entries()); |
|
| 48 | - } |
|
| 45 | + public function hasEntries(): bool |
|
| 46 | + { |
|
| 47 | + return !empty($this->entries()); |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - public function id(): string |
|
| 51 | - { |
|
| 52 | - return 'glbb-templates'; |
|
| 53 | - } |
|
| 50 | + public function id(): string |
|
| 51 | + { |
|
| 52 | + return 'glbb-templates'; |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - public function isVisible(): bool |
|
| 56 | - { |
|
| 57 | - return !is_admin(); |
|
| 58 | - } |
|
| 55 | + public function isVisible(): bool |
|
| 56 | + { |
|
| 57 | + return !is_admin(); |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - public function label(): string |
|
| 61 | - { |
|
| 62 | - return __('Templates', 'blackbar'); |
|
| 63 | - } |
|
| 60 | + public function label(): string |
|
| 61 | + { |
|
| 62 | + return __('Templates', 'blackbar'); |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - public function render(): void |
|
| 66 | - { |
|
| 67 | - $this->app->render('panels/templates', ['templates' => $this]); |
|
| 68 | - } |
|
| 65 | + public function render(): void |
|
| 66 | + { |
|
| 67 | + $this->app->render('panels/templates', ['templates' => $this]); |
|
| 68 | + } |
|
| 69 | 69 | } |
@@ -6,132 +6,132 @@ |
||
| 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 $timers; |
|
| 29 | - |
|
| 30 | - public function __construct(Application $app) |
|
| 31 | - { |
|
| 32 | - $this->app = $app; |
|
| 33 | - $this->noise = (float) 0; // This is the time that WordPress takes to execute the all hook. |
|
| 34 | - $this->start = (float) 0; |
|
| 35 | - $this->stop = (float) 0; |
|
| 36 | - $this->timers = []; |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - public function entries(): array |
|
| 40 | - { |
|
| 41 | - $entries = []; |
|
| 42 | - foreach ($this->timers as $timer) { |
|
| 43 | - $entries[] = [ |
|
| 44 | - 'memory' => $this->getMemoryString($timer), |
|
| 45 | - 'name' => $this->getNameString($timer), |
|
| 46 | - 'time' => $this->getTimeString($timer), |
|
| 47 | - ]; |
|
| 48 | - } |
|
| 49 | - return $entries; |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - public function getMeasure(): array |
|
| 53 | - { |
|
| 54 | - return $this->timers; |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - public function getMemoryString(array $timer): string |
|
| 58 | - { |
|
| 59 | - return (string) round($this->normalize($timer)['memory'] / 1000); |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - public function getNameString(array $timer): string |
|
| 63 | - { |
|
| 64 | - return $this->normalize($timer)['name']; |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - public function getTimeString(array $timer): string |
|
| 68 | - { |
|
| 69 | - $timer = $this->normalize($timer); |
|
| 70 | - $index = array_search($timer['name'], array_column($this->timers, 'name')); |
|
| 71 | - $start = $this->start + ($index * $this->noise); |
|
| 72 | - return number_format(round(($timer['time'] - $start) * 1000, 4), 4); |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - public function getTotalTime(): float |
|
| 76 | - { |
|
| 77 | - $totalNoise = (count($this->timers) - 1) * $this->noise; |
|
| 78 | - return $this->stop - $this->start - $totalNoise; |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - public function hasEntries(): bool |
|
| 82 | - { |
|
| 83 | - return !empty($this->timers); |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - public function id(): string |
|
| 87 | - { |
|
| 88 | - return 'glbb-profiler'; |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - public function isVisible(): bool |
|
| 92 | - { |
|
| 93 | - return true; |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - public function label(): string |
|
| 97 | - { |
|
| 98 | - $label = __('Profiler', 'blackbar'); |
|
| 99 | - $time = number_format($this->getTotalTime() * 1000, 0); |
|
| 100 | - if ($time > 0) { |
|
| 101 | - $label .= sprintf(' (%s %s)', $time, __('ms', 'blackbar')); |
|
| 102 | - } |
|
| 103 | - return $label; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - public function render(): void |
|
| 107 | - { |
|
| 108 | - $this->app->render('panels/profiler', ['profiler' => $this]); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - public function trace(string $name): void |
|
| 112 | - { |
|
| 113 | - $microtime = microtime(true); // float |
|
| 114 | - if (!$this->start) { |
|
| 115 | - $this->start = $microtime; |
|
| 116 | - } |
|
| 117 | - if ('blackbar/profiler/noise' === $name) { |
|
| 118 | - $this->noise = $microtime - $this->start; |
|
| 119 | - return; |
|
| 120 | - } |
|
| 121 | - $this->timers[] = [ |
|
| 122 | - 'memory' => memory_get_peak_usage(), |
|
| 123 | - 'name' => $name, |
|
| 124 | - 'time' => $microtime, |
|
| 125 | - ]; |
|
| 126 | - $this->stop = $microtime; |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - protected function normalize(array $timer): array |
|
| 130 | - { |
|
| 131 | - return wp_parse_args($timer, [ |
|
| 132 | - 'memory' => 0, |
|
| 133 | - 'name' => '', |
|
| 134 | - 'time' => (float) 0, |
|
| 135 | - ]); |
|
| 136 | - } |
|
| 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 $timers; |
|
| 29 | + |
|
| 30 | + public function __construct(Application $app) |
|
| 31 | + { |
|
| 32 | + $this->app = $app; |
|
| 33 | + $this->noise = (float) 0; // This is the time that WordPress takes to execute the all hook. |
|
| 34 | + $this->start = (float) 0; |
|
| 35 | + $this->stop = (float) 0; |
|
| 36 | + $this->timers = []; |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + public function entries(): array |
|
| 40 | + { |
|
| 41 | + $entries = []; |
|
| 42 | + foreach ($this->timers as $timer) { |
|
| 43 | + $entries[] = [ |
|
| 44 | + 'memory' => $this->getMemoryString($timer), |
|
| 45 | + 'name' => $this->getNameString($timer), |
|
| 46 | + 'time' => $this->getTimeString($timer), |
|
| 47 | + ]; |
|
| 48 | + } |
|
| 49 | + return $entries; |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + public function getMeasure(): array |
|
| 53 | + { |
|
| 54 | + return $this->timers; |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + public function getMemoryString(array $timer): string |
|
| 58 | + { |
|
| 59 | + return (string) round($this->normalize($timer)['memory'] / 1000); |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + public function getNameString(array $timer): string |
|
| 63 | + { |
|
| 64 | + return $this->normalize($timer)['name']; |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + public function getTimeString(array $timer): string |
|
| 68 | + { |
|
| 69 | + $timer = $this->normalize($timer); |
|
| 70 | + $index = array_search($timer['name'], array_column($this->timers, 'name')); |
|
| 71 | + $start = $this->start + ($index * $this->noise); |
|
| 72 | + return number_format(round(($timer['time'] - $start) * 1000, 4), 4); |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + public function getTotalTime(): float |
|
| 76 | + { |
|
| 77 | + $totalNoise = (count($this->timers) - 1) * $this->noise; |
|
| 78 | + return $this->stop - $this->start - $totalNoise; |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + public function hasEntries(): bool |
|
| 82 | + { |
|
| 83 | + return !empty($this->timers); |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + public function id(): string |
|
| 87 | + { |
|
| 88 | + return 'glbb-profiler'; |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + public function isVisible(): bool |
|
| 92 | + { |
|
| 93 | + return true; |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + public function label(): string |
|
| 97 | + { |
|
| 98 | + $label = __('Profiler', 'blackbar'); |
|
| 99 | + $time = number_format($this->getTotalTime() * 1000, 0); |
|
| 100 | + if ($time > 0) { |
|
| 101 | + $label .= sprintf(' (%s %s)', $time, __('ms', 'blackbar')); |
|
| 102 | + } |
|
| 103 | + return $label; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + public function render(): void |
|
| 107 | + { |
|
| 108 | + $this->app->render('panels/profiler', ['profiler' => $this]); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + public function trace(string $name): void |
|
| 112 | + { |
|
| 113 | + $microtime = microtime(true); // float |
|
| 114 | + if (!$this->start) { |
|
| 115 | + $this->start = $microtime; |
|
| 116 | + } |
|
| 117 | + if ('blackbar/profiler/noise' === $name) { |
|
| 118 | + $this->noise = $microtime - $this->start; |
|
| 119 | + return; |
|
| 120 | + } |
|
| 121 | + $this->timers[] = [ |
|
| 122 | + 'memory' => memory_get_peak_usage(), |
|
| 123 | + 'name' => $name, |
|
| 124 | + 'time' => $microtime, |
|
| 125 | + ]; |
|
| 126 | + $this->stop = $microtime; |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + protected function normalize(array $timer): array |
|
| 130 | + { |
|
| 131 | + return wp_parse_args($timer, [ |
|
| 132 | + 'memory' => 0, |
|
| 133 | + 'name' => '', |
|
| 134 | + 'time' => (float) 0, |
|
| 135 | + ]); |
|
| 136 | + } |
|
| 137 | 137 | } |
@@ -6,142 +6,142 @@ |
||
| 6 | 6 | |
| 7 | 7 | class Console implements Module |
| 8 | 8 | { |
| 9 | - public const ERROR_CODES = [ |
|
| 10 | - E_ERROR => 'error', // 1 |
|
| 11 | - E_WARNING => 'warning', // 2 |
|
| 12 | - E_NOTICE => 'notice', // 8 |
|
| 13 | - E_STRICT => 'strict', // 2048 |
|
| 14 | - E_DEPRECATED => 'deprecated', // 8192 |
|
| 15 | - ]; |
|
| 9 | + public const ERROR_CODES = [ |
|
| 10 | + E_ERROR => 'error', // 1 |
|
| 11 | + E_WARNING => 'warning', // 2 |
|
| 12 | + E_NOTICE => 'notice', // 8 |
|
| 13 | + E_STRICT => 'strict', // 2048 |
|
| 14 | + E_DEPRECATED => 'deprecated', // 8192 |
|
| 15 | + ]; |
|
| 16 | 16 | |
| 17 | - public const MAPPED_ERROR_CODES = [ |
|
| 18 | - 'debug' => 0, |
|
| 19 | - 'info' => E_NOTICE, |
|
| 20 | - 'deprecated' => E_DEPRECATED, // 8192 |
|
| 21 | - 'error' => E_ERROR, // 1 |
|
| 22 | - 'notice' => E_NOTICE, // 8 |
|
| 23 | - 'strict' => E_STRICT, // 2048 |
|
| 24 | - 'warning' => E_WARNING, // 2 |
|
| 25 | - 'critical' => E_ERROR, // 1 |
|
| 26 | - 'alert' => E_ERROR, // 1 |
|
| 27 | - 'emergency' => E_ERROR, // 1 |
|
| 28 | - ]; |
|
| 17 | + public const MAPPED_ERROR_CODES = [ |
|
| 18 | + 'debug' => 0, |
|
| 19 | + 'info' => E_NOTICE, |
|
| 20 | + 'deprecated' => E_DEPRECATED, // 8192 |
|
| 21 | + 'error' => E_ERROR, // 1 |
|
| 22 | + 'notice' => E_NOTICE, // 8 |
|
| 23 | + 'strict' => E_STRICT, // 2048 |
|
| 24 | + 'warning' => E_WARNING, // 2 |
|
| 25 | + 'critical' => E_ERROR, // 1 |
|
| 26 | + 'alert' => E_ERROR, // 1 |
|
| 27 | + 'emergency' => E_ERROR, // 1 |
|
| 28 | + ]; |
|
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * @var Application |
|
| 32 | - */ |
|
| 33 | - protected $app; |
|
| 34 | - /** |
|
| 35 | - * @var array |
|
| 36 | - */ |
|
| 37 | - protected $entries; |
|
| 30 | + /** |
|
| 31 | + * @var Application |
|
| 32 | + */ |
|
| 33 | + protected $app; |
|
| 34 | + /** |
|
| 35 | + * @var array |
|
| 36 | + */ |
|
| 37 | + protected $entries; |
|
| 38 | 38 | |
| 39 | - public function __construct(Application $app) |
|
| 40 | - { |
|
| 41 | - $this->app = $app; |
|
| 42 | - $this->entries = []; |
|
| 43 | - } |
|
| 39 | + public function __construct(Application $app) |
|
| 40 | + { |
|
| 41 | + $this->app = $app; |
|
| 42 | + $this->entries = []; |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - public function entries(): array |
|
| 46 | - { |
|
| 47 | - $entries = []; |
|
| 48 | - foreach ($this->entries as $entry) { |
|
| 49 | - $entry['name'] = ucfirst($entry['errname']); |
|
| 50 | - if ($entry['count'] > 1) { |
|
| 51 | - $entry['message'] = sprintf('(%s) %s', $entry['count'], $entry['message']); |
|
| 52 | - } |
|
| 53 | - $entries[] = $entry; |
|
| 54 | - } |
|
| 55 | - return $entries; |
|
| 56 | - } |
|
| 45 | + public function entries(): array |
|
| 46 | + { |
|
| 47 | + $entries = []; |
|
| 48 | + foreach ($this->entries as $entry) { |
|
| 49 | + $entry['name'] = ucfirst($entry['errname']); |
|
| 50 | + if ($entry['count'] > 1) { |
|
| 51 | + $entry['message'] = sprintf('(%s) %s', $entry['count'], $entry['message']); |
|
| 52 | + } |
|
| 53 | + $entries[] = $entry; |
|
| 54 | + } |
|
| 55 | + return $entries; |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - public function hasEntries(): bool |
|
| 59 | - { |
|
| 60 | - return !empty($this->entries); |
|
| 61 | - } |
|
| 58 | + public function hasEntries(): bool |
|
| 59 | + { |
|
| 60 | + return !empty($this->entries); |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - public function id(): string |
|
| 64 | - { |
|
| 65 | - return 'glbb-console'; |
|
| 66 | - } |
|
| 63 | + public function id(): string |
|
| 64 | + { |
|
| 65 | + return 'glbb-console'; |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - public function isVisible(): bool |
|
| 69 | - { |
|
| 70 | - return true; |
|
| 71 | - } |
|
| 68 | + public function isVisible(): bool |
|
| 69 | + { |
|
| 70 | + return true; |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - public function label(): string |
|
| 74 | - { |
|
| 75 | - $class = ''; |
|
| 76 | - $entryCount = count($this->entries); |
|
| 77 | - $errorCount = 0; |
|
| 78 | - $label = __('Console', 'blackbar'); |
|
| 79 | - foreach ($this->entries as $entry) { |
|
| 80 | - if (in_array($entry['errno'], [E_WARNING])) { |
|
| 81 | - $class = 'glbb-warning'; |
|
| 82 | - } |
|
| 83 | - if (in_array($entry['errno'], [E_ERROR])) { |
|
| 84 | - ++$errorCount; |
|
| 85 | - } |
|
| 86 | - } |
|
| 87 | - if ($errorCount > 0) { |
|
| 88 | - $class = 'glbb-error'; |
|
| 89 | - $label = sprintf('%s (%d, %d!)', $label, $entryCount, $errorCount); |
|
| 90 | - } elseif ($entryCount > 0) { |
|
| 91 | - $label = sprintf('%s (%d)', $label, $entryCount); |
|
| 92 | - } |
|
| 93 | - return sprintf('<span class="%s">%s</span>', $class, $label); |
|
| 94 | - } |
|
| 73 | + public function label(): string |
|
| 74 | + { |
|
| 75 | + $class = ''; |
|
| 76 | + $entryCount = count($this->entries); |
|
| 77 | + $errorCount = 0; |
|
| 78 | + $label = __('Console', 'blackbar'); |
|
| 79 | + foreach ($this->entries as $entry) { |
|
| 80 | + if (in_array($entry['errno'], [E_WARNING])) { |
|
| 81 | + $class = 'glbb-warning'; |
|
| 82 | + } |
|
| 83 | + if (in_array($entry['errno'], [E_ERROR])) { |
|
| 84 | + ++$errorCount; |
|
| 85 | + } |
|
| 86 | + } |
|
| 87 | + if ($errorCount > 0) { |
|
| 88 | + $class = 'glbb-error'; |
|
| 89 | + $label = sprintf('%s (%d, %d!)', $label, $entryCount, $errorCount); |
|
| 90 | + } elseif ($entryCount > 0) { |
|
| 91 | + $label = sprintf('%s (%d)', $label, $entryCount); |
|
| 92 | + } |
|
| 93 | + return sprintf('<span class="%s">%s</span>', $class, $label); |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | - public function render(): void |
|
| 97 | - { |
|
| 98 | - $this->app->render('panels/console', ['console' => $this]); |
|
| 99 | - } |
|
| 96 | + public function render(): void |
|
| 97 | + { |
|
| 98 | + $this->app->render('panels/console', ['console' => $this]); |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | - public function store(string $message, string $errno = '', string $location = ''): void |
|
| 102 | - { |
|
| 103 | - if (is_numeric($errno)) { |
|
| 104 | - // entry likely stored by set_error_handler() |
|
| 105 | - $errname = 'Unknown'; |
|
| 106 | - if (array_key_exists((int) $errno, static::ERROR_CODES)) { |
|
| 107 | - $errname = static::ERROR_CODES[$errno]; |
|
| 108 | - } |
|
| 109 | - } else { |
|
| 110 | - // entry likely stored by filter hook |
|
| 111 | - $errname = 'Debug'; |
|
| 112 | - if (array_key_exists($errno, static::MAPPED_ERROR_CODES)) { |
|
| 113 | - $errname = $errno; |
|
| 114 | - $errno = static::MAPPED_ERROR_CODES[$errno]; |
|
| 115 | - } |
|
| 116 | - } |
|
| 117 | - $errname = strtolower($errname); |
|
| 118 | - $hash = md5($errno.$errname.$message.$location); |
|
| 119 | - if (array_key_exists($hash, $this->entries)) { |
|
| 120 | - ++$this->entries[$hash]['count']; |
|
| 121 | - } else { |
|
| 122 | - $this->entries[$hash] = [ |
|
| 123 | - 'count' => 0, |
|
| 124 | - 'errname' => $errname, |
|
| 125 | - 'errno' => (int) $errno, |
|
| 126 | - 'message' => $this->normalizeMessage($message, $location), |
|
| 127 | - ]; |
|
| 128 | - }; |
|
| 129 | - } |
|
| 101 | + public function store(string $message, string $errno = '', string $location = ''): void |
|
| 102 | + { |
|
| 103 | + if (is_numeric($errno)) { |
|
| 104 | + // entry likely stored by set_error_handler() |
|
| 105 | + $errname = 'Unknown'; |
|
| 106 | + if (array_key_exists((int) $errno, static::ERROR_CODES)) { |
|
| 107 | + $errname = static::ERROR_CODES[$errno]; |
|
| 108 | + } |
|
| 109 | + } else { |
|
| 110 | + // entry likely stored by filter hook |
|
| 111 | + $errname = 'Debug'; |
|
| 112 | + if (array_key_exists($errno, static::MAPPED_ERROR_CODES)) { |
|
| 113 | + $errname = $errno; |
|
| 114 | + $errno = static::MAPPED_ERROR_CODES[$errno]; |
|
| 115 | + } |
|
| 116 | + } |
|
| 117 | + $errname = strtolower($errname); |
|
| 118 | + $hash = md5($errno.$errname.$message.$location); |
|
| 119 | + if (array_key_exists($hash, $this->entries)) { |
|
| 120 | + ++$this->entries[$hash]['count']; |
|
| 121 | + } else { |
|
| 122 | + $this->entries[$hash] = [ |
|
| 123 | + 'count' => 0, |
|
| 124 | + 'errname' => $errname, |
|
| 125 | + 'errno' => (int) $errno, |
|
| 126 | + 'message' => $this->normalizeMessage($message, $location), |
|
| 127 | + ]; |
|
| 128 | + }; |
|
| 129 | + } |
|
| 130 | 130 | |
| 131 | - protected function normalizeMessage($message, string $location): string |
|
| 132 | - { |
|
| 133 | - if ($message instanceof \DateTime) { |
|
| 134 | - $message = $message->format('Y-m-d H:i:s'); |
|
| 135 | - } elseif (is_object($message) || is_array($message)) { |
|
| 136 | - $message = print_r(json_decode(json_encode($message)), true); |
|
| 137 | - } else { |
|
| 138 | - $message = esc_html(trim((string) $message)); |
|
| 139 | - } |
|
| 140 | - $location = trim($location); |
|
| 141 | - if (!empty($location)) { |
|
| 142 | - $location = str_replace([WP_CONTENT_DIR, ABSPATH], '', $location); |
|
| 143 | - $location = sprintf('[%s] ', $location); |
|
| 144 | - } |
|
| 145 | - return $location.$message; |
|
| 146 | - } |
|
| 131 | + protected function normalizeMessage($message, string $location): string |
|
| 132 | + { |
|
| 133 | + if ($message instanceof \DateTime) { |
|
| 134 | + $message = $message->format('Y-m-d H:i:s'); |
|
| 135 | + } elseif (is_object($message) || is_array($message)) { |
|
| 136 | + $message = print_r(json_decode(json_encode($message)), true); |
|
| 137 | + } else { |
|
| 138 | + $message = esc_html(trim((string) $message)); |
|
| 139 | + } |
|
| 140 | + $location = trim($location); |
|
| 141 | + if (!empty($location)) { |
|
| 142 | + $location = str_replace([WP_CONTENT_DIR, ABSPATH], '', $location); |
|
| 143 | + $location = sprintf('[%s] ', $location); |
|
| 144 | + } |
|
| 145 | + return $location.$message; |
|
| 146 | + } |
|
| 147 | 147 | } |
@@ -6,162 +6,162 @@ |
||
| 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, array $data): void |
|
| 40 | - { |
|
| 41 | - global $wp_filter; |
|
| 42 | - if (!array_key_exists($action, $this->hooks)) { |
|
| 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, array $data): void |
|
| 40 | + { |
|
| 41 | + global $wp_filter; |
|
| 42 | + if (!array_key_exists($action, $this->hooks)) { |
|
| 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 | - foreach ($this->hooks as $action => $data) { |
|
| 80 | - $total = $this->totalTimeForHook($data); |
|
| 81 | - $this->hooks[$action]['total'] = $total; |
|
| 82 | - $this->totalTime += $total; |
|
| 83 | - $this->totalActions += $data['count']; |
|
| 84 | - $this->callbacksForHook($action, $data); |
|
| 85 | - } |
|
| 86 | - uasort($this->hooks, [$this, 'sortByTime']); |
|
| 87 | - $this->entries = array_slice($this->hooks, 0, 50); // return the 50 slowest actions |
|
| 88 | - return $this->entries; |
|
| 89 | - } |
|
| 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 | + foreach ($this->hooks as $action => $data) { |
|
| 80 | + $total = $this->totalTimeForHook($data); |
|
| 81 | + $this->hooks[$action]['total'] = $total; |
|
| 82 | + $this->totalTime += $total; |
|
| 83 | + $this->totalActions += $data['count']; |
|
| 84 | + $this->callbacksForHook($action, $data); |
|
| 85 | + } |
|
| 86 | + uasort($this->hooks, [$this, 'sortByTime']); |
|
| 87 | + $this->entries = array_slice($this->hooks, 0, 50); // return the 50 slowest actions |
|
| 88 | + return $this->entries; |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | - public function hasEntries(): bool |
|
| 92 | - { |
|
| 93 | - return !empty($this->entries()); |
|
| 94 | - } |
|
| 91 | + public function hasEntries(): bool |
|
| 92 | + { |
|
| 93 | + return !empty($this->entries()); |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | - public function id(): string |
|
| 97 | - { |
|
| 98 | - return 'glbb-actions'; |
|
| 99 | - } |
|
| 96 | + public function id(): string |
|
| 97 | + { |
|
| 98 | + return 'glbb-actions'; |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | - public function isVisible(): bool |
|
| 102 | - { |
|
| 103 | - return true; |
|
| 104 | - } |
|
| 101 | + public function isVisible(): bool |
|
| 102 | + { |
|
| 103 | + return true; |
|
| 104 | + } |
|
| 105 | 105 | |
| 106 | - public function label(): string |
|
| 107 | - { |
|
| 108 | - $label = __('Hooks', 'blackbar'); |
|
| 109 | - if (class_exists('Debug_Bar_Slow_Actions')) { |
|
| 110 | - return $label; |
|
| 111 | - } |
|
| 112 | - $this->entries(); // calculates the totalTime |
|
| 113 | - if ($this->totalTime > 0) { |
|
| 114 | - $label = sprintf('%s (%.2f %s)', $label, $this->totalTime, __('ms', 'blackbar')); |
|
| 115 | - } |
|
| 116 | - return $label; |
|
| 117 | - } |
|
| 106 | + public function label(): string |
|
| 107 | + { |
|
| 108 | + $label = __('Hooks', 'blackbar'); |
|
| 109 | + if (class_exists('Debug_Bar_Slow_Actions')) { |
|
| 110 | + return $label; |
|
| 111 | + } |
|
| 112 | + $this->entries(); // calculates the totalTime |
|
| 113 | + if ($this->totalTime > 0) { |
|
| 114 | + $label = sprintf('%s (%.2f %s)', $label, $this->totalTime, __('ms', 'blackbar')); |
|
| 115 | + } |
|
| 116 | + return $label; |
|
| 117 | + } |
|
| 118 | 118 | |
| 119 | - public function render(): void |
|
| 120 | - { |
|
| 121 | - $this->app->render('panels/actions', ['actions' => $this]); |
|
| 122 | - } |
|
| 119 | + public function render(): void |
|
| 120 | + { |
|
| 121 | + $this->app->render('panels/actions', ['actions' => $this]); |
|
| 122 | + } |
|
| 123 | 123 | |
| 124 | - public function startTimer(): void |
|
| 125 | - { |
|
| 126 | - if (!isset($this->hooks[current_filter()])) { |
|
| 127 | - $this->hooks[current_filter()] = [ |
|
| 128 | - 'callbacks' => [], |
|
| 129 | - 'count' => 0, |
|
| 130 | - 'stack' => [], |
|
| 131 | - 'time' => [], |
|
| 132 | - ]; |
|
| 133 | - add_action(current_filter(), [$this, 'stopTimer'], 9999); // @phpstan-ignore-line |
|
| 134 | - } |
|
| 135 | - ++$this->hooks[current_filter()]['count']; |
|
| 136 | - array_push($this->hooks[current_filter()]['stack'], ['start' => microtime(true)]); |
|
| 137 | - } |
|
| 124 | + public function startTimer(): void |
|
| 125 | + { |
|
| 126 | + if (!isset($this->hooks[current_filter()])) { |
|
| 127 | + $this->hooks[current_filter()] = [ |
|
| 128 | + 'callbacks' => [], |
|
| 129 | + 'count' => 0, |
|
| 130 | + 'stack' => [], |
|
| 131 | + 'time' => [], |
|
| 132 | + ]; |
|
| 133 | + add_action(current_filter(), [$this, 'stopTimer'], 9999); // @phpstan-ignore-line |
|
| 134 | + } |
|
| 135 | + ++$this->hooks[current_filter()]['count']; |
|
| 136 | + array_push($this->hooks[current_filter()]['stack'], ['start' => microtime(true)]); |
|
| 137 | + } |
|
| 138 | 138 | |
| 139 | - /** |
|
| 140 | - * @param mixed $filteredValue |
|
| 141 | - * @return mixed |
|
| 142 | - */ |
|
| 143 | - public function stopTimer($filteredValue = null) |
|
| 144 | - { |
|
| 145 | - $time = array_pop($this->hooks[current_filter()]['stack']); |
|
| 146 | - $time['stop'] = microtime(true); |
|
| 147 | - array_push($this->hooks[current_filter()]['time'], $time); |
|
| 148 | - return $filteredValue; // In case this was a filter. |
|
| 149 | - } |
|
| 139 | + /** |
|
| 140 | + * @param mixed $filteredValue |
|
| 141 | + * @return mixed |
|
| 142 | + */ |
|
| 143 | + public function stopTimer($filteredValue = null) |
|
| 144 | + { |
|
| 145 | + $time = array_pop($this->hooks[current_filter()]['stack']); |
|
| 146 | + $time['stop'] = microtime(true); |
|
| 147 | + array_push($this->hooks[current_filter()]['time'], $time); |
|
| 148 | + return $filteredValue; // In case this was a filter. |
|
| 149 | + } |
|
| 150 | 150 | |
| 151 | - public function totalTimeForHook(array $data): float |
|
| 152 | - { |
|
| 153 | - $total = 0; |
|
| 154 | - foreach ($data['time'] as $time) { |
|
| 155 | - $total += ($time['stop'] - $time['start']) * 1000; |
|
| 156 | - } |
|
| 157 | - return (float) $total; |
|
| 158 | - } |
|
| 151 | + public function totalTimeForHook(array $data): float |
|
| 152 | + { |
|
| 153 | + $total = 0; |
|
| 154 | + foreach ($data['time'] as $time) { |
|
| 155 | + $total += ($time['stop'] - $time['start']) * 1000; |
|
| 156 | + } |
|
| 157 | + return (float) $total; |
|
| 158 | + } |
|
| 159 | 159 | |
| 160 | - protected function sortByTime(array $a, array $b): int |
|
| 161 | - { |
|
| 162 | - if ($a['total'] !== $b['total']) { |
|
| 163 | - return ($a['total'] > $b['total']) ? -1 : 1; |
|
| 164 | - } |
|
| 165 | - return 0; |
|
| 166 | - } |
|
| 160 | + protected function sortByTime(array $a, array $b): int |
|
| 161 | + { |
|
| 162 | + if ($a['total'] !== $b['total']) { |
|
| 163 | + return ($a['total'] > $b['total']) ? -1 : 1; |
|
| 164 | + } |
|
| 165 | + return 0; |
|
| 166 | + } |
|
| 167 | 167 | } |
@@ -4,102 +4,102 @@ |
||
| 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_text_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_text_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 | - if (Application::PROFILER_HOOK === func_get_arg(0)) { |
|
| 73 | - $this->app->profiler->trace(func_get_arg(1)); |
|
| 74 | - } |
|
| 75 | - } |
|
| 67 | + /** |
|
| 68 | + * @action all |
|
| 69 | + */ |
|
| 70 | + public function initProfiler(): void |
|
| 71 | + { |
|
| 72 | + if (Application::PROFILER_HOOK === func_get_arg(0)) { |
|
| 73 | + $this->app->profiler->trace(func_get_arg(1)); |
|
| 74 | + } |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * @action plugins_loaded |
|
| 79 | - */ |
|
| 80 | - public function registerLanguages(): void |
|
| 81 | - { |
|
| 82 | - load_plugin_textdomain(Application::ID, false, |
|
| 83 | - plugin_basename($this->app->path()).'/languages/' |
|
| 84 | - ); |
|
| 85 | - } |
|
| 77 | + /** |
|
| 78 | + * @action plugins_loaded |
|
| 79 | + */ |
|
| 80 | + public function registerLanguages(): void |
|
| 81 | + { |
|
| 82 | + load_plugin_textdomain(Application::ID, false, |
|
| 83 | + plugin_basename($this->app->path()).'/languages/' |
|
| 84 | + ); |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | - /** |
|
| 88 | - * @action admin_footer |
|
| 89 | - * @action wp_footer |
|
| 90 | - */ |
|
| 91 | - public function renderBar(): void |
|
| 92 | - { |
|
| 93 | - apply_filters('debug', 'Profiler Stopped'); |
|
| 94 | - $this->app->render('debug-bar', [ |
|
| 95 | - 'modules' => [ // order is intentional |
|
| 96 | - $this->app->console, |
|
| 97 | - $this->app->profiler, |
|
| 98 | - $this->app->queries, |
|
| 99 | - $this->app->actions, |
|
| 100 | - $this->app->templates, |
|
| 101 | - $this->app->globals, |
|
| 102 | - ], |
|
| 103 | - ]); |
|
| 104 | - } |
|
| 87 | + /** |
|
| 88 | + * @action admin_footer |
|
| 89 | + * @action wp_footer |
|
| 90 | + */ |
|
| 91 | + public function renderBar(): void |
|
| 92 | + { |
|
| 93 | + apply_filters('debug', 'Profiler Stopped'); |
|
| 94 | + $this->app->render('debug-bar', [ |
|
| 95 | + 'modules' => [ // order is intentional |
|
| 96 | + $this->app->console, |
|
| 97 | + $this->app->profiler, |
|
| 98 | + $this->app->queries, |
|
| 99 | + $this->app->actions, |
|
| 100 | + $this->app->templates, |
|
| 101 | + $this->app->globals, |
|
| 102 | + ], |
|
| 103 | + ]); |
|
| 104 | + } |
|
| 105 | 105 | } |