Skip to content
This repository was archived by the owner on Jul 29, 2024. It is now read-only.

Commit bfc9bcf

Browse files
committed
Merge pull request #15 from jeromemacias/master
Use TerminableInterface
2 parents 0364cda + 99f6792 commit bfc9bcf

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

src/Stack/UrlMap.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
namespace Stack;
44

5-
use Symfony\Component\HttpKernel\HttpKernelInterface;
65
use Symfony\Component\HttpFoundation\Request;
6+
use Symfony\Component\HttpFoundation\Response;
7+
use Symfony\Component\HttpKernel\HttpKernelInterface;
8+
use Symfony\Component\HttpKernel\TerminableInterface;
79

810
/**
911
* URL Map Middleware, which maps kernels to paths
@@ -12,7 +14,7 @@
1214
*
1315
* @author Christoph Hochstrasser <[email protected]>
1416
*/
15-
class UrlMap implements HttpKernelInterface
17+
class UrlMap implements HttpKernelInterface, TerminableInterface
1618
{
1719
const ATTR_PREFIX = "stack.url_map.prefix";
1820

@@ -69,4 +71,17 @@ public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQ
6971

7072
return $this->app->handle($request, $type, $catch);
7173
}
74+
75+
public function terminate(Request $request, Response $response)
76+
{
77+
foreach ($this->map as $path => $app) {
78+
if ($app instanceof TerminableInterface) {
79+
$app->terminate($request, $response);
80+
}
81+
}
82+
83+
if ($this->app instanceof TerminableInterface) {
84+
$this->app->terminate($request, $response);
85+
}
86+
}
7287
}

tests/functional/UrlMapTest.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public function test()
2727

2828
$request = Request::create('/foo');
2929
$response = $urlMap->handle($request);
30+
$urlMap->terminate($request, $response);
3031

3132
$this->assertEquals('foo', $response->getContent());
3233
}
@@ -51,7 +52,9 @@ public function testOverridesPathInfo()
5152
}),
5253
));
5354

54-
$response = $urlMap->handle(Request::create('/foo?bar=baz'));
55+
$response = $urlMap->handle($request = Request::create('/foo?bar=baz'));
56+
$urlMap->terminate($request, $response);
57+
5558
$this->assertEquals('Hello World', $response->getContent());
5659
}
5760

@@ -80,7 +83,9 @@ public function testShouldBeStackable()
8083
'/foo' => $urlMapInner
8184
));
8285

83-
$response = $urlMapOuter->handle(Request::create('/foo/bar?baz=fiz'));
86+
$response = $urlMapOuter->handle($request = Request::create('/foo/bar?baz=fiz'));
87+
$urlMapOuter->terminate($request, $response);
88+
8489
$this->assertEquals('Hello World', $response->getContent());
8590
}
8691
}

0 commit comments

Comments
 (0)