diff --git a/src/Stack/UrlMap.php b/src/Stack/UrlMap.php index 261b562..67d346d 100644 --- a/src/Stack/UrlMap.php +++ b/src/Stack/UrlMap.php @@ -2,8 +2,10 @@ namespace Stack; -use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpKernel\HttpKernelInterface; +use Symfony\Component\HttpKernel\TerminableInterface; /** * URL Map Middleware, which maps kernels to paths @@ -12,7 +14,7 @@ * * @author Christoph Hochstrasser */ -class UrlMap implements HttpKernelInterface +class UrlMap implements HttpKernelInterface, TerminableInterface { const ATTR_PREFIX = "stack.url_map.prefix"; @@ -69,4 +71,17 @@ public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQ return $this->app->handle($request, $type, $catch); } + + public function terminate(Request $request, Response $response) + { + foreach ($this->map as $path => $app) { + if ($app instanceof TerminableInterface) { + $app->terminate($request, $response); + } + } + + if ($this->app instanceof TerminableInterface) { + $this->app->terminate($request, $response); + } + } } diff --git a/tests/functional/UrlMapTest.php b/tests/functional/UrlMapTest.php index 31039db..e348611 100644 --- a/tests/functional/UrlMapTest.php +++ b/tests/functional/UrlMapTest.php @@ -27,6 +27,7 @@ public function test() $request = Request::create('/foo'); $response = $urlMap->handle($request); + $urlMap->terminate($request, $response); $this->assertEquals('foo', $response->getContent()); } @@ -51,7 +52,9 @@ public function testOverridesPathInfo() }), )); - $response = $urlMap->handle(Request::create('/foo?bar=baz')); + $response = $urlMap->handle($request = Request::create('/foo?bar=baz')); + $urlMap->terminate($request, $response); + $this->assertEquals('Hello World', $response->getContent()); } @@ -80,7 +83,9 @@ public function testShouldBeStackable() '/foo' => $urlMapInner )); - $response = $urlMapOuter->handle(Request::create('/foo/bar?baz=fiz')); + $response = $urlMapOuter->handle($request = Request::create('/foo/bar?baz=fiz')); + $urlMapOuter->terminate($request, $response); + $this->assertEquals('Hello World', $response->getContent()); } }