Skip to content

Commit d7bef45

Browse files
committed
refactor: simplify toolbar disable logic and remove unnecessary flags
1 parent b7072c1 commit d7bef45

File tree

1 file changed

+5
-18
lines changed

1 file changed

+5
-18
lines changed

system/Debug/Toolbar.php

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,6 @@ class Toolbar
4242
*/
4343
protected $config;
4444

45-
/**
46-
* Indicates if the current request is a custom AJAX-like request
47-
* (HTMX, Unpoly, Turbo, etc.) that expects clean HTML fragments.
48-
*/
49-
protected bool $isDisabled = false;
50-
5145
/**
5246
* Collectors to be used and displayed.
5347
*
@@ -389,9 +383,7 @@ public function prepare(?RequestInterface $request = null, ?ResponseInterface $r
389383
return;
390384
}
391385

392-
$config = config(ToolbarConfig::class);
393-
394-
$toolbar = service('toolbar', $config);
386+
$toolbar = service('toolbar', $this->config);
395387
$stats = $app->getPerformanceStats();
396388
$data = $toolbar->run(
397389
$stats['startTime'],
@@ -413,14 +405,10 @@ public function prepare(?RequestInterface $request = null, ?ResponseInterface $r
413405

414406
$format = $response->getHeaderLine('content-type');
415407

416-
if ($this->shouldDisableToolbar($request, $config->disableOnHeaders)) {
417-
$this->isDisabled = true;
418-
}
419-
420408
// Non-HTML formats should not include the debugbar
421409
// then we send headers saying where to find the debug data
422410
// for this response
423-
if ($this->isDisabled || ! str_contains($format, 'html')) {
411+
if ($this->shouldDisableToolbar($request) || ! str_contains($format, 'html')) {
424412
$response->setHeader('Debugbar-Time', "{$time}")
425413
->setHeader('Debugbar-Link', site_url("?debugbar_time={$time}"));
426414

@@ -560,14 +548,13 @@ protected function format(string $data, string $format = 'html'): string
560548
* Determine if the toolbar should be disabled based on the request headers.
561549
*
562550
* This method allows checking both the presence of headers and their expected values.
563-
*
564-
* @param array<string, string|null> $headersToDisableToolbar
551+
* Useful for AJAX, HTMX, Unpoly, Turbo, etc., where partial HTML responses are expected.
565552
*
566553
* @return bool True if any header condition matches; false otherwise.
567554
*/
568-
private function shouldDisableToolbar(IncomingRequest $request, array $headersToDisableToolbar): bool
555+
private function shouldDisableToolbar(IncomingRequest $request): bool
569556
{
570-
foreach ($headersToDisableToolbar as $headerName => $expectedValue) {
557+
foreach ($this->config->disableOnHeaders as $headerName => $expectedValue) {
571558
if (! $request->hasHeader($headerName)) {
572559
continue; // header not present, skip
573560
}

0 commit comments

Comments
 (0)