From 3389f3305d4d5cc0f27fb59f8f087016e25f1d3d Mon Sep 17 00:00:00 2001 From: Kevin Pfeifer Date: Thu, 19 Oct 2023 11:20:06 +0200 Subject: [PATCH 1/5] add Plugins Panel --- composer.json | 6 ++- src/Panel/PluginsPanel.php | 58 +++++++++++++++++++++++++++++ src/ToolbarService.php | 1 + templates/element/plugins_panel.php | 50 +++++++++++++++++++++++++ webroot/css/style.css | 4 ++ webroot/img/cake-red.svg | 1 + 6 files changed, 118 insertions(+), 2 deletions(-) create mode 100644 src/Panel/PluginsPanel.php create mode 100644 templates/element/plugins_panel.php create mode 100644 webroot/img/cake-red.svg diff --git a/composer.json b/composer.json index 7a21b3d5c..df951dd2d 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ "source": "https://github.com/cakephp/debug_kit" }, "require": { - "cakephp/cakephp": "^5.0", + "cakephp/cakephp": "dev-5.next as 5.1.0", "composer/composer": "^2.0", "doctrine/sql-formatter": "^1.1.3" }, @@ -66,5 +66,7 @@ "allow-plugins": { "dealerdirect/phpcodesniffer-composer-installer": true } - } + }, + "minimum-stability": "dev", + "prefer-stable": true } diff --git a/src/Panel/PluginsPanel.php b/src/Panel/PluginsPanel.php new file mode 100644 index 000000000..ab6562244 --- /dev/null +++ b/src/Panel/PluginsPanel.php @@ -0,0 +1,58 @@ +_data['hasEmptyAppConfig'] = empty($config); + $plugins = []; + + foreach ($config as $pluginName => $options) { + $plugins[$pluginName] = [ + 'isLoaded' => $loadedPluginsCollection->has($pluginName), + 'onlyDebug' => $options['onlyDebug'] ?? false, + 'onlyCli' => $options['onlyCli'] ?? false, + 'optional' => $options['optional'] ?? false, + ]; + } + + $this->_data['plugins'] = $plugins; + } + + /** + * Get summary data for the plugins panel. + * + * @return string + */ + public function summary(): string + { + return (string)count($this->_data['plugins']); + } +} diff --git a/src/ToolbarService.php b/src/ToolbarService.php index 578f22b7e..64113cd64 100644 --- a/src/ToolbarService.php +++ b/src/ToolbarService.php @@ -68,6 +68,7 @@ class ToolbarService 'DebugKit.Packages' => true, 'DebugKit.Mail' => true, 'DebugKit.Deprecations' => true, + 'DebugKit.Plugins' => true, ], 'forceEnable' => false, 'safeTld' => [], diff --git a/templates/element/plugins_panel.php b/templates/element/plugins_panel.php new file mode 100644 index 000000000..83b8d958c --- /dev/null +++ b/templates/element/plugins_panel.php @@ -0,0 +1,50 @@ + +
+ config/plugins.php
'; + printf('

%s

', $msg); + ?> +
+ + + + + + + + + + + + $pluginConfig) : ?> + + + + + + + + + +
Html->image('DebugKit./img/cake-red.svg') : '' ?>Html->image('DebugKit./img/cake-red.svg') : '' ?>Html->image('DebugKit./img/cake-red.svg') : '' ?>Html->image('DebugKit./img/cake-red.svg') : '' ?>
+
+
diff --git a/webroot/css/style.css b/webroot/css/style.css index ce5224b43..d57fee96e 100644 --- a/webroot/css/style.css +++ b/webroot/css/style.css @@ -676,6 +676,10 @@ strong { border-left: 1px solid var(--mail-border); } +.c-plugins-panel img { + height: 18px; +} + .u-text-center { text-align: center; } diff --git a/webroot/img/cake-red.svg b/webroot/img/cake-red.svg new file mode 100644 index 000000000..d3daf55c7 --- /dev/null +++ b/webroot/img/cake-red.svg @@ -0,0 +1 @@ + From 0b4b6b7d28da0dc2d7a33e9eb93ec68991a9ffd9 Mon Sep 17 00:00:00 2001 From: Kevin Pfeifer Date: Thu, 19 Oct 2023 11:22:43 +0200 Subject: [PATCH 2/5] fix stan --- psalm-baseline.xml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 64cd47585..c659942de 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1,5 +1,5 @@ - + _composerPaths]]> @@ -40,6 +40,14 @@ new $class($this, $config) + + + PluginConfig::getAppConfig() + + + PluginConfig::getAppConfig() + + genericInstances From 7b325f804f8a896b902dcc54d06f1262db39e9f2 Mon Sep 17 00:00:00 2001 From: Kevin Pfeifer Date: Thu, 19 Oct 2023 11:31:09 +0200 Subject: [PATCH 3/5] fix other tests --- src/Panel/PluginsPanel.php | 4 ++++ tests/TestCase/Middleware/DebugKitMiddlewareTest.php | 8 ++++---- tests/TestCase/ToolbarServiceTest.php | 8 ++++---- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/Panel/PluginsPanel.php b/src/Panel/PluginsPanel.php index ab6562244..b8011740e 100644 --- a/src/Panel/PluginsPanel.php +++ b/src/Panel/PluginsPanel.php @@ -53,6 +53,10 @@ public function initialize(): void */ public function summary(): string { + if (!isset($this->_data['plugins'])) { + return '0'; + } + return (string)count($this->_data['plugins']); } } diff --git a/tests/TestCase/Middleware/DebugKitMiddlewareTest.php b/tests/TestCase/Middleware/DebugKitMiddlewareTest.php index fad52934f..97a14f493 100644 --- a/tests/TestCase/Middleware/DebugKitMiddlewareTest.php +++ b/tests/TestCase/Middleware/DebugKitMiddlewareTest.php @@ -121,10 +121,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('SqlLog', $result->panels[12]->panel); + $this->assertSame('DebugKit.sql_log_panel', $result->panels[12]->element); + $this->assertNotNull($result->panels[12]->summary); + $this->assertSame('Sql Log', $result->panels[12]->title); $timeStamp = filectime(Plugin::path('DebugKit') . 'webroot' . DS . 'js' . DS . 'main.js'); diff --git a/tests/TestCase/ToolbarServiceTest.php b/tests/TestCase/ToolbarServiceTest.php index d9283ff40..5bda2582c 100644 --- a/tests/TestCase/ToolbarServiceTest.php +++ b/tests/TestCase/ToolbarServiceTest.php @@ -250,10 +250,10 @@ 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('SqlLog', $result->panels[12]->panel); + $this->assertSame('DebugKit.sql_log_panel', $result->panels[12]->element); + $this->assertSame('0', $result->panels[12]->summary); + $this->assertSame('Sql Log', $result->panels[12]->title); } /** From 611f0d259d2cd5381a7e705f1a407bfe34a8a38b Mon Sep 17 00:00:00 2001 From: Kevin Pfeifer Date: Sat, 21 Oct 2023 12:46:48 +0200 Subject: [PATCH 4/5] remove template localizations --- templates/element/plugins_panel.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/templates/element/plugins_panel.php b/templates/element/plugins_panel.php index 83b8d958c..c5bb3757d 100644 --- a/templates/element/plugins_panel.php +++ b/templates/element/plugins_panel.php @@ -27,11 +27,11 @@ - - - - - + + + + + From a7c81b788d3f2cc94765c809e0d0cd1178222d03 Mon Sep 17 00:00:00 2001 From: Kevin Pfeifer Date: Mon, 23 Oct 2023 10:59:45 +0200 Subject: [PATCH 5/5] add h() call around pluginName --- templates/element/plugins_panel.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/templates/element/plugins_panel.php b/templates/element/plugins_panel.php index c5bb3757d..f76067c80 100644 --- a/templates/element/plugins_panel.php +++ b/templates/element/plugins_panel.php @@ -16,6 +16,7 @@ * @var bool $hasEmptyAppConfig * @var array $plugins */ +use function Cake\Core\h; ?>
$pluginConfig) : ?>
- +
PluginIs LoadedOnly DebugOnly CLIOptional
Html->image('DebugKit./img/cake-red.svg') : '' ?> Html->image('DebugKit./img/cake-red.svg') : '' ?> Html->image('DebugKit./img/cake-red.svg') : '' ?>