Skip to content

Commit 41b26f6

Browse files
committed
Merge IncludePanel into Environment panel
1 parent 82e48d0 commit 41b26f6

6 files changed

Lines changed: 96 additions & 9 deletions

File tree

src/Panel/EnvironmentPanel.php

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,31 @@
1515
namespace DebugKit\Panel;
1616

1717
use Cake\Core\Configure;
18+
use Cake\Error\Debugger;
1819
use Cake\Event\EventInterface;
20+
use DebugKit\DebugInclude;
1921
use DebugKit\DebugPanel;
2022

2123
/**
2224
* Provides information about your PHP and CakePHP environment to assist with debugging.
2325
*/
2426
class EnvironmentPanel extends DebugPanel
2527
{
28+
/**
29+
* instance of DebugInclude
30+
*
31+
* @var \DebugKit\DebugInclude
32+
*/
33+
protected DebugInclude $_debug;
34+
35+
/**
36+
* construct
37+
*/
38+
public function __construct()
39+
{
40+
$this->_debug = new DebugInclude();
41+
}
42+
2643
/**
2744
* Get necessary data about environment to pass back to controller
2845
*
@@ -75,6 +92,10 @@ protected function _prepare(): array
7592
$var = get_defined_constants(true);
7693
$return['app'] = array_diff_key($var['user'], $return['cake'], $hiddenCakeConstants);
7794

95+
// Included files data
96+
$return['includePaths'] = $this->_debug->includePaths();
97+
$return['includedFiles'] = $this->prepareIncludedFiles();
98+
7899
return $return;
79100
}
80101

@@ -88,4 +109,57 @@ public function shutdown(EventInterface $event): void
88109
{
89110
$this->_data = $this->_prepare();
90111
}
112+
113+
/**
114+
* Build the list of files segmented by app, cake, plugins, vendor and other
115+
*
116+
* @return array
117+
*/
118+
protected function prepareIncludedFiles(): array
119+
{
120+
$return = ['cake' => [], 'app' => [], 'plugins' => [], 'vendor' => [], 'other' => []];
121+
122+
foreach (get_included_files() as $file) {
123+
/** @var string|false $pluginName */
124+
$pluginName = $this->_debug->getPluginName($file);
125+
126+
if ($pluginName) {
127+
$return['plugins'][$pluginName][$this->_debug->getFileType($file)][] = $this->_debug->niceFileName(
128+
$file,
129+
'plugin',
130+
$pluginName
131+
);
132+
} elseif ($this->_debug->isAppFile($file)) {
133+
$return['app'][$this->_debug->getFileType($file)][] = $this->_debug->niceFileName($file, 'app');
134+
} elseif ($this->_debug->isCakeFile($file)) {
135+
$return['cake'][$this->_debug->getFileType($file)][] = $this->_debug->niceFileName($file, 'cake');
136+
} else {
137+
/** @var string|false $vendorName */
138+
$vendorName = $this->_debug->getComposerPackageName($file);
139+
140+
if ($vendorName) {
141+
$return['vendor'][$vendorName][] = $this->_debug->niceFileName($file, 'vendor', $vendorName);
142+
} else {
143+
$return['other'][] = $this->_debug->niceFileName($file, 'root');
144+
}
145+
}
146+
}
147+
148+
$return['paths'] = $this->_debug->includePaths();
149+
150+
ksort($return['app']);
151+
ksort($return['cake']);
152+
ksort($return['plugins']);
153+
ksort($return['vendor']);
154+
155+
foreach ($return['plugins'] as &$plugin) {
156+
ksort($plugin);
157+
}
158+
159+
foreach ($return as $k => $v) {
160+
$return[$k] = Debugger::exportVarAsNodes($v);
161+
}
162+
163+
return $return;
164+
}
91165
}

src/Panel/IncludePanel.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Cake\Utility\Hash;
2020
use DebugKit\DebugInclude;
2121
use DebugKit\DebugPanel;
22+
use function Cake\Core\deprecationWarning;
2223

2324
/**
2425
* Provides a list of included files for the current request
@@ -38,6 +39,7 @@ class IncludePanel extends DebugPanel
3839
public function __construct()
3940
{
4041
$this->_debug = new DebugInclude();
42+
deprecationWarning('5.1.0', 'Include panel is deprecated. Remove it from your panel configuration, and use Environment Panel instead.');
4143
}
4244

4345
/**

src/ToolbarService.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ class ToolbarService
6161
'DebugKit.Log' => true,
6262
'DebugKit.Variables' => true,
6363
'DebugKit.Environment' => true,
64-
'DebugKit.Include' => true,
6564
'DebugKit.History' => true,
6665
'DebugKit.Routes' => true,
6766
'DebugKit.Packages' => true,

templates/element/environment_panel.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
declare(strict_types=1);
3+
24
/**
35
* Environment Panel Element
46
*
@@ -15,17 +17,19 @@
1517
* @license https://www.opensource.org/licenses/mit-license.php MIT License
1618
*/
1719
use Cake\Error\Debugger;
20+
use function Cake\Core\h;
1821

1922
/**
2023
* @var \DebugKit\View\AjaxView $this
2124
* @var array $app
2225
* @var array $cake
2326
* @var array $php
27+
* @var array $includedFiles
28+
* @var array $includePaths
29+
* @var \DebugKit\View\Helper\ToolbarHelper $this->Toolbar
30+
* @var \DebugKit\View\Helper\CredentialsHelper $this->Credentials
2431
*/
25-
26-
use function Cake\Core\h;
2732
?>
28-
2933
<div class="c-environment-panel">
3034
<h2>Application Constants</h2>
3135

@@ -126,4 +130,12 @@
126130
PHP environment unavailable.
127131
</div>
128132
<?php endif; ?>
133+
134+
<h2>Included Files</h2>
135+
136+
<h4>Include Paths</h4>
137+
<?= $this->Toolbar->dumpNodes($includePaths) ?>
138+
139+
<h4>Included Files</h4>
140+
<?= $this->Toolbar->dumpNodes($includedFiles) ?>
129141
</div>

tests/TestCase/Panel/EnvironmentPanelTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function testShutdown()
6565
$this->panel->shutdown($event);
6666
$output = $this->panel->data();
6767
$this->assertIsArray($output);
68-
$this->assertSame(['php', 'ini', 'cake', 'app'], array_keys($output));
68+
$this->assertSame(['php', 'ini', 'cake', 'app', 'includePaths', 'includedFiles'], array_keys($output));
6969
$this->assertSame('mysql://user:password@localhost/my_db', $output['php']['TEST_URL_1']);
7070
}
7171
}

tests/TestCase/ToolbarServiceTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,13 +256,13 @@ public function testSaveData()
256256
$this->assertSame(200, $result->status_code);
257257
$this->assertGreaterThan(1, $result->panels);
258258

259-
$this->assertSame('Timer', $result->panels[11]->panel);
260-
$this->assertSame('DebugKit.timer_panel', $result->panels[11]->element);
259+
$this->assertSame('Timer', $result->panels[10]->panel);
260+
$this->assertSame('DebugKit.timer_panel', $result->panels[10]->element);
261261
$this->assertMatchesRegularExpression(
262262
'/\d+\.\d+\s[ms]+\s+\/\s+\d+\.\d+\s+[mbMB]+/',
263-
$result->panels[11]->summary
263+
$result->panels[10]->summary
264264
);
265-
$this->assertSame('Timer', $result->panels[11]->title);
265+
$this->assertSame('Timer', $result->panels[10]->title);
266266
}
267267

268268
/**

0 commit comments

Comments
 (0)