Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ All notable changes to `phalcon/debugbar` are documented here. The format is bas
metadata sidecars. History requires an explicit absolute writable path and is
disabled by default. Storage creation is serialized and capped across browser
identities, with least-recently-updated eviction.
- `ResponseListener::handle()` runs the injection step with a `ResponseInterface` and no event. The MVC listener calls it, so MVC behavior does not change. [#39](https://github.com/phalcon/debugbar/issues/39)

### Fixed

Expand Down
8 changes: 7 additions & 1 deletion src/DebugBar/ResponseListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
/**
* The `application:beforeSendResponse` listener. On the event it runs the access
* gate, aggregates the bar, sets the diagnostic headers, and - for an injectable
* HTML response - renders and splices the bar in.
* HTML response - renders and splices the bar in. `handle()` does the same work
* with no event.
*
* @phpstan-import-type request_context from DebugBarTypes
* @phpstan-import-type payload from DebugBarTypes
Expand All @@ -58,6 +59,11 @@ public function __invoke(EventInterface $event, mixed $source, mixed $response):
return;
}

$this->handle($response);
}

public function handle(ResponseInterface $response): void
{
if ($this->historyEndpoint?->matches()) {
return;
}
Expand Down
12 changes: 12 additions & 0 deletions tests/Unit/DebugBar/ResponseListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,18 @@ function (string $name, string $value, array $options) use (&$call): bool {
$this->assertFalse(is_dir($path));
}

public function testHandleInjectsWithoutAnEvent(): void
{
$listener = $this->listener(false);

$response = new Response();
$response->setContent('<html><body>hi</body></html>');

$listener->handle($response);

$this->assertStringContainsString('phalcon-debugbar-data', $response->getContent());
}

public function testIgnoresNonResponsePayloads(): void
{
$listener = $this->listener(true);
Expand Down
Loading