From c8e65a28e907650d12b0bea0b8c049b825b9ca24 Mon Sep 17 00:00:00 2001 From: "Mario A. Alvarez Garcia" Date: Tue, 27 Nov 2012 17:22:45 -0500 Subject: [PATCH] [FrameworkBundle][Routing] Resolve placeholders in hostnamePattern rules --- .../Bundle/FrameworkBundle/Routing/Router.php | 2 ++ .../Tests/Routing/RouterTest.php | 23 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/Symfony/Bundle/FrameworkBundle/Routing/Router.php b/src/Symfony/Bundle/FrameworkBundle/Routing/Router.php index 31fbc63ef6..753a58e27a 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Routing/Router.php +++ b/src/Symfony/Bundle/FrameworkBundle/Routing/Router.php @@ -78,6 +78,7 @@ class Router extends BaseRouter implements WarmableInterface * - the route defaults, * - the route requirements, * - the route pattern. + * - the route hostnamePattern. * * @param RouteCollection $collection */ @@ -96,6 +97,7 @@ class Router extends BaseRouter implements WarmableInterface } $route->setPattern($this->resolve($route->getPattern())); + $route->setHostnamePattern($this->resolve($route->getHostnamePattern())); } } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Routing/RouterTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Routing/RouterTest.php index a25decc112..59f4d061be 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Routing/RouterTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Routing/RouterTest.php @@ -117,6 +117,29 @@ class RoutingTest extends \PHPUnit_Framework_TestCase ); } + public function testHostnamePatternPlaceholders() + { + $routes = new RouteCollection(); + + $route = new Route('foo'); + $route->setHostnamePattern('/before/%parameter.foo%/after/%%unescaped%%'); + + $routes->add('foo', $route); + + $sc = $this->getServiceContainer($routes); + + $sc->expects($this->at(1))->method('hasParameter')->with('parameter.foo')->will($this->returnValue(true)); + $sc->expects($this->at(2))->method('getParameter')->with('parameter.foo')->will($this->returnValue('foo')); + + $router = new Router($sc, 'foo'); + $route = $router->getRouteCollection()->get('foo'); + + $this->assertEquals( + '/before/foo/after/%unescaped%', + $route->getHostnamePattern() + ); + } + /** * @expectedException \Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException * @expectedExceptionMessage You have requested a non-existent parameter "nope".