diff --git a/CHANGELOG.md b/CHANGELOG.md index 357c267..610824a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/DebugBar/ResponseListener.php b/src/DebugBar/ResponseListener.php index bc11acf..37de5f7 100644 --- a/src/DebugBar/ResponseListener.php +++ b/src/DebugBar/ResponseListener.php @@ -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 @@ -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; } diff --git a/tests/Unit/DebugBar/ResponseListenerTest.php b/tests/Unit/DebugBar/ResponseListenerTest.php index de22ca2..55b91f2 100644 --- a/tests/Unit/DebugBar/ResponseListenerTest.php +++ b/tests/Unit/DebugBar/ResponseListenerTest.php @@ -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('hi'); + + $listener->handle($response); + + $this->assertStringContainsString('phalcon-debugbar-data', $response->getContent()); + } + public function testIgnoresNonResponsePayloads(): void { $listener = $this->listener(true);