Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

5.next: add Plugins Panel #963

Merged
merged 5 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down Expand Up @@ -66,5 +66,7 @@
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
},
"minimum-stability": "dev",
"prefer-stable": true
}
10 changes: 9 additions & 1 deletion psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="5.10.0@a5effd2d2dddd1a7ea7a0f6a051ce63ff979e356">
<files psalm-version="5.13.1@086b94371304750d1c673315321a55d15fc59015">
<file src="src/DebugInclude.php">
<PossiblyNullArrayOffset>
<code><![CDATA[$this->_composerPaths]]></code>
Expand Down Expand Up @@ -40,6 +40,14 @@
<code>new $class($this, $config)</code>
</UnsafeInstantiation>
</file>
<file src="src/Panel/PluginsPanel.php">
<InternalClass>
<code>PluginConfig::getAppConfig()</code>
</InternalClass>
<InternalMethod>
<code>PluginConfig::getAppConfig()</code>
</InternalMethod>
</file>
<file src="src/Panel/SqlLogPanel.php">
<UndefinedInterfaceMethod>
<code>genericInstances</code>
Expand Down
62 changes: 62 additions & 0 deletions src/Panel/PluginsPanel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php
declare(strict_types=1);

/**
* CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
* @link https://cakephp.org CakePHP(tm) Project
* @license https://www.opensource.org/licenses/mit-license.php MIT License
*/
namespace DebugKit\Panel;

use Cake\Core\Plugin;
use Cake\Core\PluginConfig;
use DebugKit\DebugPanel;

/**
* Provides debug information on the available plugins.
*/
class PluginsPanel extends DebugPanel
{
/**
* @inheritDoc
*/
public function initialize(): void
{
$loadedPluginsCollection = Plugin::getCollection();
$config = PluginConfig::getAppConfig();

$this->_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
{
if (!isset($this->_data['plugins'])) {
return '0';
}

return (string)count($this->_data['plugins']);
}
}
1 change: 1 addition & 0 deletions src/ToolbarService.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class ToolbarService
'DebugKit.Packages' => true,
'DebugKit.Mail' => true,
'DebugKit.Deprecations' => true,
'DebugKit.Plugins' => true,
],
'forceEnable' => false,
'safeTld' => [],
Expand Down
50 changes: 50 additions & 0 deletions templates/element/plugins_panel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php
/**
* CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
* @link https://cakephp.org CakePHP(tm) Project
* @since DebugKit 0.1
* @license https://www.opensource.org/licenses/mit-license.php MIT License
*/
/**
* @var \DebugKit\View\AjaxView $this
* @var bool $hasEmptyAppConfig
* @var array $plugins
*/
?>
<div class="c-plugins-panel">
<?php
$msg = 'This table shows all available plugins and your plugin configuration in';
$msg .= ' <strong>config/plugins.php</strong><br>';
printf('<p class="c-flash c-flash--info">%s</p>', $msg);
?>
<section>
<table class="c-debug-table">
<thead>
<tr>
<th><?= __d('debug_kit', 'Plugin') ?></th>
<th><?= __d('debug_kit', 'Is Loaded') ?></th>
<th><?= __d('debug_kit', 'Only Debug') ?></th>
<th><?= __d('debug_kit', 'Only CLI') ?></th>
<th><?= __d('debug_kit', 'Optional') ?></th>
LordSimal marked this conversation as resolved.
Show resolved Hide resolved
</tr>
</thead>
<tbody>
<?php foreach ($plugins as $pluginName => $pluginConfig) : ?>
<tr>
<td><?= $pluginName ?></td>
LordSimal marked this conversation as resolved.
Show resolved Hide resolved
<td><?= $pluginConfig['isLoaded'] ? $this->Html->image('DebugKit./img/cake-red.svg') : '' ?></td>
<td><?= $pluginConfig['onlyDebug'] ? $this->Html->image('DebugKit./img/cake-red.svg') : '' ?></td>
<td><?= $pluginConfig['onlyCli'] ? $this->Html->image('DebugKit./img/cake-red.svg') : '' ?></td>
<td><?= $pluginConfig['optional'] ? $this->Html->image('DebugKit./img/cake-red.svg') : '' ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</section>
</div>
8 changes: 4 additions & 4 deletions tests/TestCase/Middleware/DebugKitMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
8 changes: 4 additions & 4 deletions tests/TestCase/ToolbarServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
4 changes: 4 additions & 0 deletions webroot/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,10 @@ strong {
border-left: 1px solid var(--mail-border);
}

.c-plugins-panel img {
height: 18px;
}

.u-text-center {
text-align: center;
}
Expand Down
1 change: 1 addition & 0 deletions webroot/img/cake-red.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading