-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Routing] Allow to set name prefixes from the configuration #25178
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
[Routing] Allow to set name prefixes from the configuration #25178
Conversation
0875723
to
e0a8690
Compare
public function testAddNamePrefix() | ||
{ | ||
$collection = new RouteCollection(); | ||
$collection->add('foo', $foo = new Route('/foo')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please also add an existing api_foo
route, to be sure that the prefixing does not delete this route due to overriding.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, added.
Does the PHP DSL also need this feature, or is it already available in it ? |
841d5ee
to
a4c836c
Compare
@stof it was't. I've added it to the trait. |
Status: Needs review |
@@ -124,4 +124,18 @@ | |||
|
|||
return $this; | |||
} | |||
|
|||
/** | |||
* Add a prefix to the name of all the routes within the collection. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adds
@@ -153,6 +153,22 @@ public function addPrefix($prefix, array $defaults = array(), array $requirement | |||
} | |||
} | |||
|
|||
/** | |||
* Add a prefix to the name of all the routes within in the collection. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adds
/** | ||
* Add a prefix to the name of all the routes within in the collection. | ||
* | ||
* @param string $prefix |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be removed
/** | ||
* Add a prefix to the name of all the routes within the collection. | ||
* | ||
* @param string $prefix |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be removed
* | ||
* @return $this | ||
*/ | ||
final public function addNamePrefix(string $prefix) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
: self
to fully get rid of the phpdoc?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, we still need the description I'd say, as it's meant to be used by developers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Getting rid of @return $this
would be nice though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but... on the trait I'm not sure if this makes sense... as (at least in my mind) self
refers to the trait here, not the class use
ing the trait.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no such thing as referring to a trait. PHP merges traits into the class, so self will always point to the correct class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was talking conceptually, by reading this. But if you two believe it's better just to put self
within the trait, I'm happy with it as I don't mind that much tbh. Changed 👍
a4c836c
to
9f7c4e7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated based on @fabpot's comments.
* | ||
* @return $this | ||
*/ | ||
final public function addNamePrefix(string $prefix) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, we still need the description I'd say, as it's meant to be used by developers
9f7c4e7
to
dd15433
Compare
Add the `addNamePrefix` method to the PHP trait
dd15433
to
e895402
Compare
Thank you @sroze. |
…ation (sroze) This PR was squashed before being merged into the 4.1-dev branch (closes #25178). Discussion ---------- [Routing] Allow to set name prefixes from the configuration | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #19612 | License | MIT | Doc PR | ø This allows setting name prefixes to routes while importing them. Typically, we can then import multiple times a similar file. This was originally requested by 🎸 @chrisguitarguy in #19612 ```yaml app: resource: ../controller/routing.yml api: resource: ../controller/routing.yml name_prefix: api_ prefix: /api ``` ```xml <?xml version="1.0" encoding="UTF-8" ?> <routes xmlns="http://symfony.com/schema/routing" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd"> <import resource="../controller/routing.xml" /> <import resource="../controller/routing.xml" prefix="/api" name-prefix="api_" /> </routes> ``` Commits ------- 880d7e7 [Routing] Allow to set name prefixes from the configuration
…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
This allows setting name prefixes to routes while importing them. Typically, we can then import multiple times a similar file. This was originally requested by 🎸 @chrisguitarguy in #19612