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

Commit

Permalink
Merge pull request #15 from jeromemacias/master
Browse files Browse the repository at this point in the history
Use TerminableInterface
  • Loading branch information
CHH committed Apr 16, 2015
2 parents 0364cda + 99f6792 commit bfc9bcf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
19 changes: 17 additions & 2 deletions src/Stack/UrlMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -12,7 +14,7 @@
*
* @author Christoph Hochstrasser <[email protected]>
*/
class UrlMap implements HttpKernelInterface
class UrlMap implements HttpKernelInterface, TerminableInterface
{
const ATTR_PREFIX = "stack.url_map.prefix";

Expand Down Expand Up @@ -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);
}
}
}
9 changes: 7 additions & 2 deletions tests/functional/UrlMapTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public function test()

$request = Request::create('/foo');
$response = $urlMap->handle($request);
$urlMap->terminate($request, $response);

$this->assertEquals('foo', $response->getContent());
}
Expand All @@ -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());
}

Expand Down Expand Up @@ -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());
}
}
Expand Down

0 comments on commit bfc9bcf

Please sign in to comment.