Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e32c1da

Browse files
bug #26597 [Routing] Fix name-prefixing when using PHP DSL (nicolas-grekas)
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
2 parents b2fafc6 + 0053eee commit e32c1da

File tree

4 files changed

+12
-11
lines changed

4 files changed

+12
-11
lines changed

src/Symfony/Component/Routing/Loader/Configurator/ImportConfigurator.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,14 @@ public function __destruct()
4040
*
4141
* @return $this
4242
*/
43-
final public function prefix($prefix)
43+
final public function prefix($prefix, string $namePrefix = '')
4444
{
45+
if ('' !== $namePrefix) {
46+
$this->route->addNamePrefix($namePrefix);
47+
}
48+
if (!$prefix) {
49+
return $this;
50+
}
4551
if (!\is_array($prefix)) {
4652
$this->route->addPrefix($prefix);
4753
} else {

src/Symfony/Component/Routing/Loader/Configurator/Traits/RouteTrait.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,4 @@ final public function controller($controller)
124124

125125
return $this;
126126
}
127-
128-
/**
129-
* Adds a prefix to the name of all the routes within the collection.
130-
*/
131-
final public function addNamePrefix(string $prefix): self
132-
{
133-
$this->route->addNamePrefix($prefix);
134-
135-
return $this;
136-
}
137127
}

src/Symfony/Component/Routing/Tests/Fixtures/php_dsl.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
->prefix('/sub')
1616
->requirements(array('id' => '\d+'));
1717

18+
$routes->import('php_dsl_sub.php')
19+
->prefix('/zub', 'z_');
20+
1821
$routes->add('ouf', '/ouf')
1922
->schemes(array('https'))
2023
->methods(array('GET'))

src/Symfony/Component/Routing/Tests/Loader/PhpFileLoaderTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ public function testRoutingConfigurator()
106106
->setHost('host')
107107
->setRequirements(array('id' => '\d+'))
108108
);
109+
$expectedCollection->add('z_c_bar', new Route('/zub/pub/bar'));
110+
$expectedCollection->add('z_c_pub_buz', (new Route('/zub/pub/buz'))->setHost('host'));
109111
$expectedCollection->add('ouf', (new Route('/ouf'))
110112
->setSchemes(array('https'))
111113
->setMethods(array('GET'))

0 commit comments

Comments
 (0)