Skip to content

Commit 7a44fd7

Browse files
authored
Merge pull request #963 from cakephp/5.next-plugins-panel
5.next: add Plugins Panel
2 parents facf109 + a7c81b7 commit 7a44fd7

File tree

9 files changed

+140
-11
lines changed

9 files changed

+140
-11
lines changed

composer.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"source": "https://github.com/cakephp/debug_kit"
2424
},
2525
"require": {
26-
"cakephp/cakephp": "^5.0",
26+
"cakephp/cakephp": "dev-5.next as 5.1.0",
2727
"composer/composer": "^2.0",
2828
"doctrine/sql-formatter": "^1.1.3"
2929
},
@@ -66,5 +66,7 @@
6666
"allow-plugins": {
6767
"dealerdirect/phpcodesniffer-composer-installer": true
6868
}
69-
}
69+
},
70+
"minimum-stability": "dev",
71+
"prefer-stable": true
7072
}

psalm-baseline.xml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<files psalm-version="5.10.0@a5effd2d2dddd1a7ea7a0f6a051ce63ff979e356">
2+
<files psalm-version="5.13.1@086b94371304750d1c673315321a55d15fc59015">
33
<file src="src/DebugInclude.php">
44
<PossiblyNullArrayOffset>
55
<code><![CDATA[$this->_composerPaths]]></code>
@@ -40,6 +40,14 @@
4040
<code>new $class($this, $config)</code>
4141
</UnsafeInstantiation>
4242
</file>
43+
<file src="src/Panel/PluginsPanel.php">
44+
<InternalClass>
45+
<code>PluginConfig::getAppConfig()</code>
46+
</InternalClass>
47+
<InternalMethod>
48+
<code>PluginConfig::getAppConfig()</code>
49+
</InternalMethod>
50+
</file>
4351
<file src="src/Panel/SqlLogPanel.php">
4452
<UndefinedInterfaceMethod>
4553
<code>genericInstances</code>

src/Panel/PluginsPanel.php

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
/**
5+
* CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
6+
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
7+
*
8+
* Licensed under The MIT License
9+
* Redistributions of files must retain the above copyright notice.
10+
*
11+
* @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
12+
* @link https://cakephp.org CakePHP(tm) Project
13+
* @license https://www.opensource.org/licenses/mit-license.php MIT License
14+
*/
15+
namespace DebugKit\Panel;
16+
17+
use Cake\Core\Plugin;
18+
use Cake\Core\PluginConfig;
19+
use DebugKit\DebugPanel;
20+
21+
/**
22+
* Provides debug information on the available plugins.
23+
*/
24+
class PluginsPanel extends DebugPanel
25+
{
26+
/**
27+
* @inheritDoc
28+
*/
29+
public function initialize(): void
30+
{
31+
$loadedPluginsCollection = Plugin::getCollection();
32+
$config = PluginConfig::getAppConfig();
33+
34+
$this->_data['hasEmptyAppConfig'] = empty($config);
35+
$plugins = [];
36+
37+
foreach ($config as $pluginName => $options) {
38+
$plugins[$pluginName] = [
39+
'isLoaded' => $loadedPluginsCollection->has($pluginName),
40+
'onlyDebug' => $options['onlyDebug'] ?? false,
41+
'onlyCli' => $options['onlyCli'] ?? false,
42+
'optional' => $options['optional'] ?? false,
43+
];
44+
}
45+
46+
$this->_data['plugins'] = $plugins;
47+
}
48+
49+
/**
50+
* Get summary data for the plugins panel.
51+
*
52+
* @return string
53+
*/
54+
public function summary(): string
55+
{
56+
if (!isset($this->_data['plugins'])) {
57+
return '0';
58+
}
59+
60+
return (string)count($this->_data['plugins']);
61+
}
62+
}

src/ToolbarService.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class ToolbarService
6868
'DebugKit.Packages' => true,
6969
'DebugKit.Mail' => true,
7070
'DebugKit.Deprecations' => true,
71+
'DebugKit.Plugins' => true,
7172
],
7273
'forceEnable' => false,
7374
'safeTld' => [],
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
/**
3+
* CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
4+
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
5+
*
6+
* Licensed under The MIT License
7+
* Redistributions of files must retain the above copyright notice.
8+
*
9+
* @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
10+
* @link https://cakephp.org CakePHP(tm) Project
11+
* @since DebugKit 0.1
12+
* @license https://www.opensource.org/licenses/mit-license.php MIT License
13+
*/
14+
/**
15+
* @var \DebugKit\View\AjaxView $this
16+
* @var bool $hasEmptyAppConfig
17+
* @var array $plugins
18+
*/
19+
use function Cake\Core\h;
20+
?>
21+
<div class="c-plugins-panel">
22+
<?php
23+
$msg = 'This table shows all available plugins and your plugin configuration in';
24+
$msg .= ' <strong>config/plugins.php</strong><br>';
25+
printf('<p class="c-flash c-flash--info">%s</p>', $msg);
26+
?>
27+
<section>
28+
<table class="c-debug-table">
29+
<thead>
30+
<tr>
31+
<th>Plugin</th>
32+
<th>Is Loaded</th>
33+
<th>Only Debug</th>
34+
<th>Only CLI</th>
35+
<th>Optional</th>
36+
</tr>
37+
</thead>
38+
<tbody>
39+
<?php foreach ($plugins as $pluginName => $pluginConfig) : ?>
40+
<tr>
41+
<td><?= h($pluginName) ?></td>
42+
<td><?= $pluginConfig['isLoaded'] ? $this->Html->image('DebugKit./img/cake-red.svg') : '' ?></td>
43+
<td><?= $pluginConfig['onlyDebug'] ? $this->Html->image('DebugKit./img/cake-red.svg') : '' ?></td>
44+
<td><?= $pluginConfig['onlyCli'] ? $this->Html->image('DebugKit./img/cake-red.svg') : '' ?></td>
45+
<td><?= $pluginConfig['optional'] ? $this->Html->image('DebugKit./img/cake-red.svg') : '' ?></td>
46+
</tr>
47+
<?php endforeach; ?>
48+
</tbody>
49+
</table>
50+
</section>
51+
</div>

tests/TestCase/Middleware/DebugKitMiddlewareTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,10 @@ public function testInvokeSaveData()
121121
$this->assertSame(200, $result->status_code);
122122
$this->assertGreaterThan(1, $result->panels);
123123

124-
$this->assertSame('SqlLog', $result->panels[11]->panel);
125-
$this->assertSame('DebugKit.sql_log_panel', $result->panels[11]->element);
126-
$this->assertNotNull($result->panels[11]->summary);
127-
$this->assertSame('Sql Log', $result->panels[11]->title);
124+
$this->assertSame('SqlLog', $result->panels[12]->panel);
125+
$this->assertSame('DebugKit.sql_log_panel', $result->panels[12]->element);
126+
$this->assertNotNull($result->panels[12]->summary);
127+
$this->assertSame('Sql Log', $result->panels[12]->title);
128128

129129
$timeStamp = filectime(Plugin::path('DebugKit') . 'webroot' . DS . 'js' . DS . 'main.js');
130130

tests/TestCase/ToolbarServiceTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -250,10 +250,10 @@ public function testSaveData()
250250
$this->assertSame(200, $result->status_code);
251251
$this->assertGreaterThan(1, $result->panels);
252252

253-
$this->assertSame('SqlLog', $result->panels[11]->panel);
254-
$this->assertSame('DebugKit.sql_log_panel', $result->panels[11]->element);
255-
$this->assertSame('0', $result->panels[11]->summary);
256-
$this->assertSame('Sql Log', $result->panels[11]->title);
253+
$this->assertSame('SqlLog', $result->panels[12]->panel);
254+
$this->assertSame('DebugKit.sql_log_panel', $result->panels[12]->element);
255+
$this->assertSame('0', $result->panels[12]->summary);
256+
$this->assertSame('Sql Log', $result->panels[12]->title);
257257
}
258258

259259
/**

webroot/css/style.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,10 @@ strong {
676676
border-left: 1px solid var(--mail-border);
677677
}
678678

679+
.c-plugins-panel img {
680+
height: 18px;
681+
}
682+
679683
.u-text-center {
680684
text-align: center;
681685
}

webroot/img/cake-red.svg

Lines changed: 1 addition & 0 deletions
Loading

0 commit comments

Comments
 (0)