|
| 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 | +} |
0 commit comments