Skip to content

Commit 3389f33

Browse files
committed
add Plugins Panel
1 parent facf109 commit 3389f33

6 files changed

Lines changed: 118 additions & 2 deletions

File tree

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
}

src/Panel/PluginsPanel.php

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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+
return (string)count($this->_data['plugins']);
57+
}
58+
}

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: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
?>
20+
<div class="c-plugins-panel">
21+
<?php
22+
$msg = 'This table shows all available plugins and your plugin configuration in';
23+
$msg .= ' <strong>config/plugins.php</strong><br>';
24+
printf('<p class="c-flash c-flash--info">%s</p>', $msg);
25+
?>
26+
<section>
27+
<table class="c-debug-table">
28+
<thead>
29+
<tr>
30+
<th><?= __d('debug_kit', 'Plugin') ?></th>
31+
<th><?= __d('debug_kit', 'Is Loaded') ?></th>
32+
<th><?= __d('debug_kit', 'Only Debug') ?></th>
33+
<th><?= __d('debug_kit', 'Only CLI') ?></th>
34+
<th><?= __d('debug_kit', 'Optional') ?></th>
35+
</tr>
36+
</thead>
37+
<tbody>
38+
<?php foreach ($plugins as $pluginName => $pluginConfig) : ?>
39+
<tr>
40+
<td><?= $pluginName ?></td>
41+
<td><?= $pluginConfig['isLoaded'] ? $this->Html->image('DebugKit./img/cake-red.svg') : '' ?></td>
42+
<td><?= $pluginConfig['onlyDebug'] ? $this->Html->image('DebugKit./img/cake-red.svg') : '' ?></td>
43+
<td><?= $pluginConfig['onlyCli'] ? $this->Html->image('DebugKit./img/cake-red.svg') : '' ?></td>
44+
<td><?= $pluginConfig['optional'] ? $this->Html->image('DebugKit./img/cake-red.svg') : '' ?></td>
45+
</tr>
46+
<?php endforeach; ?>
47+
</tbody>
48+
</table>
49+
</section>
50+
</div>

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)