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

Use TerminableInterface #15

Merged
merged 4 commits into from
Apr 16, 2015
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 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,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());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should no longer be needed

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