8000 [Routing] UrlGenerator: fixed missing query param and some ignored requirements by Tobion · Pull Request #5445 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Routing] UrlGenerator: fixed missing query param and some ignored requirements #5445

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 3, 2012
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
[Routing] context params should have higher priority than defaults
fixes #5437
  • Loading branch information
Tobion committed Sep 7, 2012
commit e22823bb7d6c0a4cd5fb9d5315144d35ecc1a0b2
2 changes: 1 addition & 1 deletion src/Symfony/Component/Routing/Generator/UrlGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public function generate($name, $parameters = array(), $absolute = false)
protected function doGenerate($variables, $defaults, $requirements, $tokens, $parameters, $name, $absolute)
{
$variables = array_flip($variables);
$mergedParams = array_replace($this->context->getParameters(), $defaults, $parameters);
$mergedParams = array_replace($defaults, $this->context->getParameters(), $parameters);

// all params must be given
if ($diff = array_diff_key($variables, $mergedParams)) {
Expand Down
12 changes: 12 additions & 0 deletions src/Symfony/Component/Routing/Tests/Generator/UrlGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,18 @@ public function testUrlWithGlobalParameter()
$this->assertEquals('/app.php/testing/bar', $url);
}

public function testGlobalParameterHasHigherPriorityThanDefault()
{
$routes = $this->getRoutes('test', new Route('/{_locale}', array('_locale' => 'en')));
$generator = $this->getGenerator($routes);
$context = new RequestContext('/app.php');
$context->setParameter('_locale', 'de');
$generator->setContext($context);
$url = $generator->generate('test', array());

$this->assertSame('/app.php/de', $url);
}

/**
* @expectedException Symfony\Component\Routing\Exception\RouteNotFoundException
*/
Expand Down
0