@@ -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 | } |
@@ -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 | } |
@@ -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 | } |
@@ -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 | |