From a7e0f7e34e462f33f676ae152d537e3442e49927 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Macias?= Date: Wed, 3 Dec 2014 11:48:23 +0100 Subject: [PATCH 1/4] Use TerminableInterface --- src/Stack/UrlMap.php | 20 ++++++++++++++++++-- tests/functional/UrlMapTest.php | 9 +++++++-- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/Stack/UrlMap.php b/src/Stack/UrlMap.php index 261b562..22b4603 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,18 @@ public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQ return $this->app->handle($request, $type, $catch); } + + public function terminate(Request $request, Response $response) + { + $pathInfo = rawurldecode($request->getPathInfo()); + foreach ($this->map as $path => $app) { + if (0 === strpos($pathInfo, $path)) { + if ($app instanceof TerminableInterface) { + $app->terminate($request, $response); + } + + break; + } + } + } } 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()); } } From b1303977f5c55c0f679ff2d19871c9b097352930 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Macias?= Date: Wed, 3 Dec 2014 13:06:31 +0100 Subject: [PATCH 2/4] Call termintate on all apps --- src/Stack/UrlMap.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/Stack/UrlMap.php b/src/Stack/UrlMap.php index 22b4603..e87a677 100644 --- a/src/Stack/UrlMap.php +++ b/src/Stack/UrlMap.php @@ -76,12 +76,8 @@ public function terminate(Request $request, Response $response) { $pathInfo = rawurldecode($request->getPathInfo()); foreach ($this->map as $path => $app) { - if (0 === strpos($pathInfo, $path)) { - if ($app instanceof TerminableInterface) { - $app->terminate($request, $response); - } - - break; + if ($app instanceof TerminableInterface) { + $app->terminate($request, $response); } } } From 737a41f820144a282a872f1d6ab03983ec74d995 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Macias?= Date: Wed, 3 Dec 2014 22:16:24 +0100 Subject: [PATCH 3/4] Call terminate on main app --- src/Stack/UrlMap.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Stack/UrlMap.php b/src/Stack/UrlMap.php index e87a677..ed010a7 100644 --- a/src/Stack/UrlMap.php +++ b/src/Stack/UrlMap.php @@ -80,5 +80,9 @@ public function terminate(Request $request, Response $response) $app->terminate($request, $response); } } + + if ($this->app instanceof TerminableInterface) { + $this->app->terminate($request, $response); + } } } From 99f67929aa83bcf1be99be250422b55d4a4a4eed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Macias?= Date: Thu, 4 Dec 2014 16:16:51 +0100 Subject: [PATCH 4/4] Clean dead code in UrlMap::terminate() method --- src/Stack/UrlMap.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Stack/UrlMap.php b/src/Stack/UrlMap.php index ed010a7..67d346d 100644 --- a/src/Stack/UrlMap.php +++ b/src/Stack/UrlMap.php @@ -74,7 +74,6 @@ public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQ public function terminate(Request $request, Response $response) { - $pathInfo = rawurldecode($request->getPathInfo()); foreach ($this->map as $path => $app) { if ($app instanceof TerminableInterface) { $app->terminate($request, $response);