merged branch nomack84/issue6135 (PR #6136)

This PR was merged into the master branch.

Commits
-------

c8e65a2 [FrameworkBundle][Routing] Resolve placeholders in hostnamePattern rules

Discussion
----------

[FrameworkBundle][Routing] Resolve placeholders in hostnamePattern rules

Bug fix: yes
Feature addition: no
Backwards compatibility break: no
Symfony2 tests pass: yes
Fixes the following tickets: #6135
License of the code: MIT

Currently the placeholders in the `hostname_pattern` rule are not resolved, so that's why this PR is it for.

---------------------------------------------------------------------------

by nomack84 at 2012-11-28T14:18:02Z

@fabpot Could you please merge this? I really need this fix to be solve.
Thanks!
This commit is contained in:
Fabien Potencier 2012-11-28 17:24:04 +01:00
commit 7fce02c818
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".