Skip to content

Commit 5116f54

Browse files
authored
Merge pull request #1006 from cakephp/merge-request-session
Merge request & session and environment & include panels
2 parents a38d33e + 2c1d828 commit 5116f54

File tree

13 files changed

+134
-15
lines changed

13 files changed

+134
-15
lines changed

psalm-baseline.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@
8080
<code>$vendorName</code>
8181
</RiskyTruthyFalsyComparison>
8282
</file>
83+
<file src="src/Panel/EnvironmentPanel.php">
84+
<RiskyTruthyFalsyComparison>
85+
<code>$pluginName</code>
86+
<code>$vendorName</code>
87+
</RiskyTruthyFalsyComparison>
88+
</file>
8389
<file src="src/Panel/IncludePanel.php">
8490
<RiskyTruthyFalsyComparison>
8591
<code>$pluginName</code>

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: 5 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,10 @@ class IncludePanel extends DebugPanel
3839
public function __construct()
3940
{
4041
$this->_debug = new DebugInclude();
42+
deprecationWarning(
43+
'5.1.0',
44+
'Include panel is deprecated. Remove it from your panel configuration, and use Environment Panel instead.'
45+
);
4146
}
4247

4348
/**

src/Panel/RequestPanel.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public function shutdown(EventInterface $event): void
5555
'data' => Debugger::exportVarAsNodes($request->getData(), $maxDepth),
5656
'cookie' => Debugger::exportVarAsNodes($request->getCookieParams(), $maxDepth),
5757
'get' => Debugger::exportVarAsNodes($_GET, $maxDepth),
58+
'session' => Debugger::exportVarAsNodes($request->getSession()->read(), $maxDepth),
5859
'matchedRoute' => $request->getParam('_matchedRoute'),
5960
'headers' => [
6061
'response' => headers_sent($file, $line),

src/Panel/SessionPanel.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Cake\Error\Debugger;
1919
use Cake\Event\EventInterface;
2020
use DebugKit\DebugPanel;
21+
use function Cake\Core\deprecationWarning;
2122

2223
/**
2324
* Provides debug information on the Session contents.
@@ -32,6 +33,10 @@ class SessionPanel extends DebugPanel
3233
*/
3334
public function shutdown(EventInterface $event): void
3435
{
36+
deprecationWarning(
37+
'5.1.0',
38+
'SessionPanel is deprecated. Remove it from your panel list, and use Request panel instead.'
39+
);
3540
/** @var \Cake\Controller\Controller $controller */
3641
$controller = $event->getSubject();
3742
$request = $controller->getRequest();

src/ToolbarService.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,12 @@ class ToolbarService
5555
protected array $_defaultConfig = [
5656
'panels' => [
5757
'DebugKit.Cache' => true,
58-
'DebugKit.Session' => true,
5958
'DebugKit.Request' => true,
6059
'DebugKit.SqlLog' => true,
6160
'DebugKit.Timer' => true,
6261
'DebugKit.Log' => true,
6362
'DebugKit.Variables' => true,
6463
'DebugKit.Environment' => true,
65-
'DebugKit.Include' => true,
6664
'DebugKit.History' => true,
6765
'DebugKit.Routes' => true,
6866
'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>

templates/element/request_panel.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
<code><?php echo h($routePath); ?></code>
5757
</div>
5858
<p>
59-
<i>[Plugin].[Prefix]/[Controller]::[action]</i>
59+
<i class="o-help">Route path grammar: [Plugin].[Prefix]/[Controller]::[action]</i>
6060
</p>
6161

6262
<h4>Attributes</h4>
@@ -93,6 +93,13 @@
9393
<p class="c-flash c-flash--info">No Cookie data.</p>
9494
<?php endif; ?>
9595

96+
<h4>Session</h4>
97+
<?php if (isset($session)) : ?>
98+
<?= $this->Toolbar->dumpNode($session) ?>
99+
<?php else : ?>
100+
<p class="c-flash c-flash--info">No Session data.</p>
101+
<?php endif; ?>
102+
96103
<?php if (!empty($matchedRoute)) : ?>
97104
<h4>Matched Route</h4>
98105
<p><?= $this->Toolbar->dumpNode(Debugger::exportVarAsNodes(['template' => $matchedRoute])) ?></p>

tests/TestCase/Middleware/DebugKitMiddlewareTest.php

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

129-
$this->assertSame('SqlLog', $result->panels[11]->panel);
130-
$this->assertSame('DebugKit.sql_log_panel', $result->panels[11]->element);
131-
$this->assertNotNull($result->panels[11]->summary);
132-
$this->assertSame('Sql Log', $result->panels[11]->title);
129+
$this->assertSame('Timer', $result->panels[10]->panel);
130+
$this->assertSame('DebugKit.timer_panel', $result->panels[10]->element);
131+
$this->assertNotNull($result->panels[10]->summary);
132+
$this->assertSame('Timer', $result->panels[10]->title);
133133

134134
$timeStamp = filectime(Plugin::path('DebugKit') . 'webroot' . DS . 'js' . DS . 'inject-iframe.js');
135135

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
}

0 commit comments

Comments
 (0)