Skip to content

Commit

Permalink
bug #26597 [Routing] Fix name-prefixing when using PHP DSL (nicolas-g…
Browse files Browse the repository at this point in the history
…rekas)

This PR was merged into the 4.1-dev branch.

Discussion
----------

[Routing] Fix name-prefixing when using PHP DSL

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

Fixes bad implem merged in #25178

Commits
-------

0053eee [Routing] Fix name-prefixing when using PHP DSL
  • Loading branch information
nicolas-grekas committed Mar 19, 2018
2 parents b2fafc6 + 0053eee commit e32c1da
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,14 @@ public function __destruct()
*
* @return $this
*/
final public function prefix($prefix)
final public function prefix($prefix, string $namePrefix = '')
{
if ('' !== $namePrefix) {
$this->route->addNamePrefix($namePrefix);
}
if (!$prefix) {
return $this;
}
if (!\is_array($prefix)) {
$this->route->addPrefix($prefix);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,4 @@ final public function controller($controller)

return $this;
}

/**
* Adds a prefix to the name of all the routes within the collection.
*/
final public function addNamePrefix(string $prefix): self
{
$this->route->addNamePrefix($prefix);

return $this;
}
}
3 changes: 3 additions & 0 deletions src/Symfony/Component/Routing/Tests/Fixtures/php_dsl.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
->prefix('/sub')
->requirements(array('id' => '\d+'));

$routes->import('php_dsl_sub.php')
->prefix('/zub', 'z_');

$routes->add('ouf', '/ouf')
->schemes(array('https'))
->methods(array('GET'))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ public function testRoutingConfigurator()
->setHost('host')
->setRequirements(array('id' => '\d+'))
);
$expectedCollection->add('z_c_bar', new Route('/zub/pub/bar'));
$expectedCollection->add('z_c_pub_buz', (new Route('/zub/pub/buz'))->setHost('host'));
$expectedCollection->add('ouf', (new Route('/ouf'))
->setSchemes(array('https'))
->setMethods(array('GET'))
Expand Down

0 comments on commit e32c1da

Please sign in to comment.