[FrameworkBundle][Routing] Resolve placeholders in hostnamePattern rules

This commit is contained in:
Mario A. Alvarez Garcia 2012-11-27 17:22:45 -05:00
parent 1b34ddb6b4
commit c8e65a28e9
2 changed files with 25 additions and 0 deletions

View File

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

View File

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