8000 [Routing] Fix name-prefixing when using PHP DSL by nicolas-grekas · Pull Request #26597 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Routing] Fix name-prefixing when using PHP DSL #26597

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 1 commit into from
Mar 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
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 = '')
Copy link
Contributor

Choose a reaso 8000 n for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO addng a name prefix should be a separate method again. Those are totally unrelated concepts and I can add a name prefix without having to add a path prefix. This is also possible in the annotation loader for example. So it not consistent to do do it in one method.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed, done in #26284

{
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
< 2A68 /div>
0