diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 33f87ec6..cc4000ce 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -80,6 +80,12 @@ $vendorName + + + $pluginName + $vendorName + + $pluginName diff --git a/src/Panel/EnvironmentPanel.php b/src/Panel/EnvironmentPanel.php index 33d9a89e..28b7decb 100644 --- a/src/Panel/EnvironmentPanel.php +++ b/src/Panel/EnvironmentPanel.php @@ -15,7 +15,9 @@ namespace DebugKit\Panel; use Cake\Core\Configure; +use Cake\Error\Debugger; use Cake\Event\EventInterface; +use DebugKit\DebugInclude; use DebugKit\DebugPanel; /** @@ -23,6 +25,21 @@ */ class EnvironmentPanel extends DebugPanel { + /** + * instance of DebugInclude + * + * @var \DebugKit\DebugInclude + */ + protected DebugInclude $_debug; + + /** + * construct + */ + public function __construct() + { + $this->_debug = new DebugInclude(); + } + /** * Get necessary data about environment to pass back to controller * @@ -75,6 +92,10 @@ protected function _prepare(): array $var = get_defined_constants(true); $return['app'] = array_diff_key($var['user'], $return['cake'], $hiddenCakeConstants); + // Included files data + $return['includePaths'] = $this->_debug->includePaths(); + $return['includedFiles'] = $this->prepareIncludedFiles(); + return $return; } @@ -88,4 +109,57 @@ public function shutdown(EventInterface $event): void { $this->_data = $this->_prepare(); } + + /** + * Build the list of files segmented by app, cake, plugins, vendor and other + * + * @return array + */ + protected function prepareIncludedFiles(): array + { + $return = ['cake' => [], 'app' => [], 'plugins' => [], 'vendor' => [], 'other' => []]; + + foreach (get_included_files() as $file) { + /** @var string|false $pluginName */ + $pluginName = $this->_debug->getPluginName($file); + + if ($pluginName) { + $return['plugins'][$pluginName][$this->_debug->getFileType($file)][] = $this->_debug->niceFileName( + $file, + 'plugin', + $pluginName + ); + } elseif ($this->_debug->isAppFile($file)) { + $return['app'][$this->_debug->getFileType($file)][] = $this->_debug->niceFileName($file, 'app'); + } elseif ($this->_debug->isCakeFile($file)) { + $return['cake'][$this->_debug->getFileType($file)][] = $this->_debug->niceFileName($file, 'cake'); + } else { + /** @var string|false $vendorName */ + $vendorName = $this->_debug->getComposerPackageName($file); + + if ($vendorName) { + $return['vendor'][$vendorName][] = $this->_debug->niceFileName($file, 'vendor', $vendorName); + } else { + $return['other'][] = $this->_debug->niceFileName($file, 'root'); + } + } + } + + $return['paths'] = $this->_debug->includePaths(); + + ksort($return['app']); + ksort($return['cake']); + ksort($return['plugins']); + ksort($return['vendor']); + + foreach ($return['plugins'] as &$plugin) { + ksort($plugin); + } + + foreach ($return as $k => $v) { + $return[$k] = Debugger::exportVarAsNodes($v); + } + + return $return; + } } diff --git a/src/Panel/IncludePanel.php b/src/Panel/IncludePanel.php index a0d52a7c..c2ef94b9 100644 --- a/src/Panel/IncludePanel.php +++ b/src/Panel/IncludePanel.php @@ -19,6 +19,7 @@ use Cake\Utility\Hash; use DebugKit\DebugInclude; use DebugKit\DebugPanel; +use function Cake\Core\deprecationWarning; /** * Provides a list of included files for the current request @@ -38,6 +39,10 @@ class IncludePanel extends DebugPanel public function __construct() { $this->_debug = new DebugInclude(); + deprecationWarning( + '5.1.0', + 'Include panel is deprecated. Remove it from your panel configuration, and use Environment Panel instead.' + ); } /** diff --git a/src/Panel/RequestPanel.php b/src/Panel/RequestPanel.php index d4b6ad36..ad8bc3fa 100644 --- a/src/Panel/RequestPanel.php +++ b/src/Panel/RequestPanel.php @@ -55,6 +55,7 @@ public function shutdown(EventInterface $event): void 'data' => Debugger::exportVarAsNodes($request->getData(), $maxDepth), 'cookie' => Debugger::exportVarAsNodes($request->getCookieParams(), $maxDepth), 'get' => Debugger::exportVarAsNodes($_GET, $maxDepth), + 'session' => Debugger::exportVarAsNodes($request->getSession()->read(), $maxDepth), 'matchedRoute' => $request->getParam('_matchedRoute'), 'headers' => [ 'response' => headers_sent($file, $line), diff --git a/src/Panel/SessionPanel.php b/src/Panel/SessionPanel.php index ae4a1879..511db5ab 100644 --- a/src/Panel/SessionPanel.php +++ b/src/Panel/SessionPanel.php @@ -18,6 +18,7 @@ use Cake\Error\Debugger; use Cake\Event\EventInterface; use DebugKit\DebugPanel; +use function Cake\Core\deprecationWarning; /** * Provides debug information on the Session contents. @@ -32,6 +33,10 @@ class SessionPanel extends DebugPanel */ public function shutdown(EventInterface $event): void { + deprecationWarning( + '5.1.0', + 'SessionPanel is deprecated. Remove it from your panel list, and use Request panel instead.' + ); /** @var \Cake\Controller\Controller $controller */ $controller = $event->getSubject(); $request = $controller->getRequest(); diff --git a/src/ToolbarService.php b/src/ToolbarService.php index fdb6ca93..35cd0bcd 100644 --- a/src/ToolbarService.php +++ b/src/ToolbarService.php @@ -55,14 +55,12 @@ class ToolbarService protected array $_defaultConfig = [ 'panels' => [ 'DebugKit.Cache' => true, - 'DebugKit.Session' => true, 'DebugKit.Request' => true, 'DebugKit.SqlLog' => true, 'DebugKit.Timer' => true, 'DebugKit.Log' => true, 'DebugKit.Variables' => true, 'DebugKit.Environment' => true, - 'DebugKit.Include' => true, 'DebugKit.History' => true, 'DebugKit.Routes' => true, 'DebugKit.Packages' => true, diff --git a/templates/element/environment_panel.php b/templates/element/environment_panel.php index bd78a8e8..2eb4d2a6 100644 --- a/templates/element/environment_panel.php +++ b/templates/element/environment_panel.php @@ -1,4 +1,6 @@ Toolbar + * @var \DebugKit\View\Helper\CredentialsHelper $this->Credentials */ - -use function Cake\Core\h; ?> -

Application Constants

@@ -126,4 +130,12 @@ PHP environment unavailable.
+ +

Included Files

+ +

Include Paths

+ Toolbar->dumpNodes($includePaths) ?> + +

Included Files

+ Toolbar->dumpNodes($includedFiles) ?> diff --git a/templates/element/request_panel.php b/templates/element/request_panel.php index 81a51d58..d036b01f 100644 --- a/templates/element/request_panel.php +++ b/templates/element/request_panel.php @@ -56,7 +56,7 @@

- [Plugin].[Prefix]/[Controller]::[action] + Route path grammar: [Plugin].[Prefix]/[Controller]::[action]

Attributes

@@ -93,6 +93,13 @@

No Cookie data.

+

Session

+ + Toolbar->dumpNode($session) ?> + +

No Session data.

+ +

Matched Route

Toolbar->dumpNode(Debugger::exportVarAsNodes(['template' => $matchedRoute])) ?>

diff --git a/tests/TestCase/Middleware/DebugKitMiddlewareTest.php b/tests/TestCase/Middleware/DebugKitMiddlewareTest.php index 4cdc4951..113f0aef 100644 --- a/tests/TestCase/Middleware/DebugKitMiddlewareTest.php +++ b/tests/TestCase/Middleware/DebugKitMiddlewareTest.php @@ -126,10 +126,10 @@ public function testInvokeSaveData() $this->assertSame(200, $result->status_code); $this->assertGreaterThan(1, $result->panels); - $this->assertSame('SqlLog', $result->panels[11]->panel); - $this->assertSame('DebugKit.sql_log_panel', $result->panels[11]->element); - $this->assertNotNull($result->panels[11]->summary); - $this->assertSame('Sql Log', $result->panels[11]->title); + $this->assertSame('Timer', $result->panels[10]->panel); + $this->assertSame('DebugKit.timer_panel', $result->panels[10]->element); + $this->assertNotNull($result->panels[10]->summary); + $this->assertSame('Timer', $result->panels[10]->title); $timeStamp = filectime(Plugin::path('DebugKit') . 'webroot' . DS . 'js' . DS . 'inject-iframe.js'); diff --git a/tests/TestCase/Panel/EnvironmentPanelTest.php b/tests/TestCase/Panel/EnvironmentPanelTest.php index 8fc88a14..3e6a10fb 100644 --- a/tests/TestCase/Panel/EnvironmentPanelTest.php +++ b/tests/TestCase/Panel/EnvironmentPanelTest.php @@ -65,7 +65,7 @@ public function testShutdown() $this->panel->shutdown($event); $output = $this->panel->data(); $this->assertIsArray($output); - $this->assertSame(['php', 'ini', 'cake', 'app'], array_keys($output)); + $this->assertSame(['php', 'ini', 'cake', 'app', 'includePaths', 'includedFiles'], array_keys($output)); $this->assertSame('mysql://user:password@localhost/my_db', $output['php']['TEST_URL_1']); } } diff --git a/tests/TestCase/Panel/RequestPanelTest.php b/tests/TestCase/Panel/RequestPanelTest.php index 2a680bbd..1382b49c 100644 --- a/tests/TestCase/Panel/RequestPanelTest.php +++ b/tests/TestCase/Panel/RequestPanelTest.php @@ -64,6 +64,10 @@ public function testShutdownSkipAttributes() $data = $this->panel->data(); $this->assertArrayHasKey('attributes', $data); + $this->assertArrayHasKey('session', $data); + $this->assertArrayHasKey('params', $data); + $this->assertArrayHasKey('data', $data); + $this->assertArrayHasKey('cookie', $data); $this->assertEquals('string', $data['attributes']['ok']->getType()); $this->assertStringContainsString('Could not serialize `closure`', $data['attributes']['closure']->getValue()); } diff --git a/tests/TestCase/ToolbarServiceTest.php b/tests/TestCase/ToolbarServiceTest.php index cc46989f..f45bbb9b 100644 --- a/tests/TestCase/ToolbarServiceTest.php +++ b/tests/TestCase/ToolbarServiceTest.php @@ -256,10 +256,13 @@ public function testSaveData() $this->assertSame(200, $result->status_code); $this->assertGreaterThan(1, $result->panels); - $this->assertSame('SqlLog', $result->panels[11]->panel); - $this->assertSame('DebugKit.sql_log_panel', $result->panels[11]->element); - $this->assertSame('0', $result->panels[11]->summary); - $this->assertSame('Sql Log', $result->panels[11]->title); + $this->assertSame('Timer', $result->panels[10]->panel); + $this->assertSame('DebugKit.timer_panel', $result->panels[10]->element); + $this->assertMatchesRegularExpression( + '/\d+\.\d+\s[ms]+\s+\/\s+\d+\.\d+\s+[mbMB]+/', + $result->panels[10]->summary + ); + $this->assertSame('Timer', $result->panels[10]->title); } /** diff --git a/webroot/css/style.css b/webroot/css/style.css index e294e96d..8c0433ac 100644 --- a/webroot/css/style.css +++ b/webroot/css/style.css @@ -238,6 +238,10 @@ strong { -webkit-animation: spin 4s linear infinite; animation: spin 4s linear infinite; } +.o-help { + color: var(--checkbox-label); + font-size: 14px; +} @-webkit-keyframes spin { 100% {