Skip to content

Commit cabdee9

Browse files
authored
Merge branch '5.x' into js-dom-safe-rendering
2 parents a1f744f + f0b0c17 commit cabdee9

14 files changed

Lines changed: 83 additions & 29 deletions

File tree

phpstan-baseline.neon

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
parameters:
22
ignoreErrors:
3-
-
4-
message: '#^Method DebugKit\\Mailer\\Transport\\DebugKitTransport\:\:send\(\) should return array\{headers\: string, message\: string\} but returns array\{headers\: non\-empty\-array\<string, string\>, message\: array\{text\: string, html\: string\}\}\.$#'
5-
identifier: return.type
6-
count: 1
7-
path: src/Mailer/Transport/DebugKitTransport.php
8-
93
-
104
message: '#^Parameter \#1 \$request of method DebugKit\\ToolbarService\:\:saveData\(\) expects Cake\\Http\\ServerRequest, Psr\\Http\\Message\\ServerRequestInterface given\.$#'
115
identifier: argument.type

psalm-baseline.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111
</ImpureMethodCall>
1212
</file>
1313
<file src="src/Mailer/Transport/DebugKitTransport.php">
14-
<InvalidReturnStatement>
15-
<code><![CDATA[$result]]></code>
16-
</InvalidReturnStatement>
1714
<NullArgument>
1815
<code><![CDATA[$this->emailLog]]></code>
1916
</NullArgument>

src/Controller/ToolbarController.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ public function clearCache(): void
4646
if (!$name) {
4747
throw new NotFoundException('Invalid cache engine name.');
4848
}
49+
if (!Cache::getConfig($name)) {
50+
throw new NotFoundException(sprintf('Unknown cache engine "%s".', $name));
51+
}
4952
$success = Cache::clear($name);
5053
$message = $success ?
5154
sprintf('%s cache cleared.', $name) :

src/Mailer/Transport/DebugKitTransport.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Cake\Core\App;
88
use Cake\Mailer\AbstractTransport;
99
use Cake\Mailer\Message;
10+
use InvalidArgumentException;
1011

1112
/**
1213
* Debug Transport class, useful for emulating the email sending process and inspecting
@@ -37,6 +38,11 @@ class DebugKitTransport extends AbstractTransport
3738
*/
3839
public function __construct(array $config = [], ?AbstractTransport $originalTransport = null)
3940
{
41+
if (!isset($config['debugKitLog']) || !$config['debugKitLog'] instanceof ArrayObject) {
42+
throw new InvalidArgumentException(
43+
'DebugKitTransport requires a `debugKitLog` config entry of type `ArrayObject`.',
44+
);
45+
}
4046
$this->emailLog = $config['debugKitLog'];
4147

4248
if ($originalTransport !== null) {
@@ -62,7 +68,17 @@ public function __construct(array $config = [], ?AbstractTransport $originalTran
6268
}
6369

6470
/**
65-
* @inheritDoc
71+
* Capture the message into the in-memory email log and optionally forward
72+
* to a wrapped real transport.
73+
*
74+
* Overrides the parent return shape: DebugKit stores the headers as an
75+
* associative array (so the panel can render rows) and splits the body
76+
* into text/html parts. Callers that consume this transport's return
77+
* value directly must account for this richer shape.
78+
*
79+
* @param \Cake\Mailer\Message $message The message to capture.
80+
* @return array
81+
* @phpstan-return array{headers: array<string, string>, message: array{text: string, html: string}}|array<string, mixed>
6682
*/
6783
public function send(Message $message): array
6884
{

src/Panel/RequestPanel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function shutdown(EventInterface $event): void
5454
'query' => Debugger::exportVarAsNodes($request->getQueryParams(), $maxDepth),
5555
'data' => Debugger::exportVarAsNodes($request->getData(), $maxDepth),
5656
'cookie' => Debugger::exportVarAsNodes($request->getCookieParams(), $maxDepth),
57-
'get' => Debugger::exportVarAsNodes($_GET, $maxDepth),
57+
'get' => Debugger::exportVarAsNodes($request->getQueryParams(), $maxDepth),
5858
'session' => Debugger::exportVarAsNodes($request->getSession()->read(), $maxDepth),
5959
'matchedRoute' => $request->getParam('_matchedRoute'),
6060
'headers' => [

src/ToolbarService.php

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -291,33 +291,39 @@ public function saveData(ServerRequest $request, ResponseInterface $response): R
291291
foreach ($this->registry->loaded() as $name) {
292292
$panel = $this->registry->{$name};
293293
$data = null;
294+
$handlerInstalled = false;
294295
try {
295296
$data = $panel->data();
296297

297-
// Set error handler to catch warnings/errors during serialization
298-
set_error_handler(function ($errno, $errstr) use ($name): void {
299-
throw new Exception("Serialization error in panel '{$name}': {$errstr}");
300-
});
298+
// Catch only warnings/notices raised during serialization; fatals
299+
// and exceptions in __sleep/__serialize already surface as throws.
300+
set_error_handler(
301+
function ($errno, $errstr) use ($name): bool {
302+
throw new Exception("Serialization error in panel '{$name}': {$errstr}");
303+
},
304+
E_WARNING | E_NOTICE | E_USER_WARNING | E_USER_NOTICE,
305+
);
306+
$handlerInstalled = true;
301307

302308
$content = serialize($data);
303-
304-
restore_error_handler();
305309
} catch (Exception $e) {
306-
restore_error_handler();
307-
308310
$errorMessage = sprintf(
309311
'Failed to serialize data for panel "%s": %s',
310312
$name,
311313
$e->getMessage(),
312314
);
313315

314316
Log::warning($errorMessage);
315-
Log::debug('Panel data type: ' . gettype($data ?? null));
317+
Log::debug('Panel data type: ' . gettype($data));
316318

317319
$content = serialize([
318320
'error' => $errorMessage,
319321
'panel' => $name,
320322
]);
323+
} finally {
324+
if ($handlerInstalled) {
325+
restore_error_handler();
326+
}
321327
}
322328
$row->panels[] = $requests->Panels->newEntity([
323329
'panel' => $name,

src/View/Helper/CredentialsHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function filter(mixed $in): mixed
5959
$link = $this->Html->tag('a', '******', [
6060
'class' => 'filtered-credentials',
6161
'title' => h($credentials),
62-
'onclick' => 'this.innerHTML = this.title',
62+
'onclick' => 'this.textContent = this.title',
6363
]);
6464

6565
return h($protocol) . $link . '@' . h($tail);

templates/element/packages_panel.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,11 @@
5454
</thead>
5555
<tbody>
5656
<?php foreach ($packages as $package) : ?>
57-
<?php extract($package); ?>
57+
<?php
58+
$name = (string)($package['name'] ?? '');
59+
$version = (string)($package['version'] ?? '');
60+
$description = (string)($package['description'] ?? '');
61+
?>
5862
<tr>
5963
<td title="<?= h($description) ?>">
6064
<a href="https://packagist.org/packages/<?= h($name) ?>"
@@ -85,7 +89,11 @@ class="c-packages-panel__link">
8589
</thead>
8690
<tbody>
8791
<?php foreach ($devPackages as $package) : ?>
88-
<?php extract($package); ?>
92+
<?php
93+
$name = (string)($package['name'] ?? '');
94+
$version = (string)($package['version'] ?? '');
95+
$description = (string)($package['description'] ?? '');
96+
?>
8997
<tr>
9098
<td title="<?= h($description) ?>">
9199
<a href="https://packagist.org/packages/<?= h($name) ?>"

templates/element/request_panel.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
*/
2929

3030
use Cake\Error\Debugger;
31+
use function Cake\Core\h;
3132

3233
?>
3334
<div class="c-request-panel">
@@ -36,8 +37,8 @@
3637
<p class="c-flash c-flash--warning">
3738
<?= sprintf(
3839
'Headers already sent at file %s and line %d.',
39-
$headers['file'],
40-
$headers['line']
40+
h($headers['file']),
41+
(int)$headers['line']
4142
) ?>
4243
</p>
4344
<?php endif; ?>

templates/element/routes_panel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
<button type="button" class="o-button js-toggle-plugin-route <?=
4646
strpos($pluginName, 'DebugKit') === 0 ? ' is-active' : '' ?>"
4747
data-plugin=".c-routes-panel__route-entry--plugin-<?= $parsedName ?>">
48-
<?= $pluginName ?>
48+
<?= h($pluginName) ?>
4949
</button>
5050
<?php endforeach; ?>
5151
</div>

0 commit comments

Comments
 (0)