-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[HttpKernel] Add the UidValueResolver argument value resolver #44665
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
Conversation
c7de8b5
to
e0e3413
Compare
use Symfony\Component\Uid\UuidV4; | ||
use Symfony\Component\Uid\UuidV6; | ||
|
||
class UidController |
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.
Check this file for different use cases.
e0e3413
to
2b5b596
Compare
src/Symfony/Component/Uid/ArgumentResolver/UidValueResolver.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Uid/ArgumentResolver/UidValueResolver.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Uid/ArgumentResolver/UidValueResolver.php
Outdated
Show resolved
Hide resolved
0188adb
to
6712733
Compare
Nice, I was just thinking of making something like this 👍 I am just trying to figure out now how is the best way to make route parameter requirements based on Uid |
b2c1b7f
to
fd22d35
Compare
src/Symfony/Component/Uid/ArgumentResolver/UidValueResolver.php
Outdated
Show resolved
Hide resolved
...mfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/Controller/UidController.php
Outdated
Show resolved
Hide resolved
That's a good question actually. If we figure out how to make this, we might be able to remove the proposed Any idea how to do this? |
Now I'm wondering: what about removing the "format" configuration setting and attribute, and instead accept only the canonical representation? |
I haven't yet looked into the router, but I am wondering is there some kind of parser level for parameters before generating URL matchers? If so we could add some extension in that point which would mark that param as UID |
We could define a If this looks like a useful path forward, we could then simplify this PR and make the resolver accept any format. I think that's my current preference (and we could define these |
My previous implementation was basically like you mention parameter + argument resolver, but I was planning to look into something nicer |
49c3f64
to
4b61f8e
Compare
src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Uid/ArgumentResolver/UidValueResolver.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Uid/Tests/ArgumentResolver/UidValueResolverTest.php
Outdated
Show resolved
Hide resolved
4b61f8e
to
5658b5a
Compare
5658b5a
to
19f3e39
Compare
11ef7d9
to
785c6ef
Compare
785c6ef
to
398ff80
Compare
Thank you @fancyweb. |
…egular-expressions constants to use as route parameter requirements (fancyweb) This PR was merged into the 6.1 branch. Discussion ---------- [Routing] Add Requirement, a collection of universal regular-expressions constants to use as route parameter requirements | Q | A | ------------- | --- | Branch? | 6.1 | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - Ref #44665. We need a way to easily reference some universal complicated regexes in routes parameters requirements, for example: ```php #[Route(path: '/users/{id}', requirements: ['id' => Requirement::UUID])] #[Route(path: '/users/{id<'.Requirement::UID_BASE58.'>}')] ``` What about having a collection in the routing component itself? I'm sure there are other common cases we would add here. Commits ------- f49cb6a [Routing] Add Requirement, a collection of universal regular-expression constants to use as route parameter requirements
This feature adds an argument value resolver for UIDs.
Before:
After:
By default, all formats are accepted because the resolver uses the
fromString()
method from the target UID class.It's possible to restrict to one format or a combination of formats by using a route parameter requirement, for example: