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".