Skip to content

Commit 7fce02c

Browse files
committed
merged branch nomack84/issue6135 (PR symfony#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: symfony#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!
2 parents aacfe74 + c8e65a2 commit 7fce02c

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/Symfony/Bundle/FrameworkBundle/Routing/Router.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ public function warmUp($cacheDir)
7878
* - the route defaults,
7979
* - the route requirements,
8080
* - the route pattern.
81+
* - the route hostnamePattern.
8182
*
8283
* @param RouteCollection $collection
8384
*/
@@ -96,6 +97,7 @@ private function resolveParameters(RouteCollection $collection)
9697
}
9798

9899
$route->setPattern($this->resolve($route->getPattern()));
100+
$route->setHostnamePattern($this->resolve($route->getHostnamePattern()));
99101
}
100102
}
101103
}

src/Symfony/Bundle/FrameworkBundle/Tests/Routing/RouterTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,29 @@ public function testPatternPlaceholders()
117117
);
118118
}
119119

120+
public function testHostnamePatternPlaceholders()
121+
{
122+
$routes = new RouteCollection();
123+
124+
$route = new Route('foo');
125+
$route->setHostnamePattern('/before/%parameter.foo%/after/%%unescaped%%');
126+
127+
$routes->add('foo', $route);
128+
129+
$sc = $this->getServiceContainer($routes);
130+
131+
$sc->expects($this->at(1))->method('hasParameter')->with('parameter.foo')->will($this->returnValue(true));
132+
$sc->expects($this->at(2))->method('getParameter')->with('parameter.foo')->will($this->returnValue('foo'));
133+
134+
$router = new Router($sc, 'foo');
135+
$route = $router->getRouteCollection()->get('foo');
136+
137+
$this->assertEquals(
138+
'/before/foo/after/%unescaped%',
139+
$route->getHostnamePattern()
140+
);
141+
}
142+
120143
/**
121144
* @expectedException \Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException
122145
* @expectedExceptionMessage You have requested a non-existent parameter "nope".

0 commit comments

Comments
 (0)