-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
[WIP][Routing] Extended Expression Language in a routing component #10512
[WIP][Routing] Extended Expression Language in a routing component #10512
Conversation
how would one then parse out the relevant headers? ie. how would one then parse the version from a media type? |
a PR support only extension of expression language, after this PR you can inject an expression language service with injected services (ie. request, security.context etc...). I need this PR for Versioning API with FOSRestBndle. with add version_compare function i can use a routing condition like this: condition: "compare(request.attributes.get('version'),'1.1', '>')" a request and context services is initialized by default |
@lsmith77 seems like that part isnt actually a consideration here. I like the idea of being able to use version_compare in the routing definitions, but that leaves implementing parsing of version headers up to the user (which we could provide in FOSRestBundle) |
i created an experimental bundle for this functionality |
if (method_exists($this->matcher, 'setExpressionLanguage')) { | ||
$this->matcher->setExpressionLanguage($this->expressionLanguage); | ||
} | ||
|
||
return $this->matcher = new $this->options['matcher_class']($this->getRouteCollection(), $this->context); |
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.
This looks wrong to me. It should just be return $this->matcher;
.
Using I like this PR. Besides my comment, can you add some tests to validate that the router actually works when injecting an expression language? |
Sure! |
dd8dbcc
to
fd756bb
Compare
fd756bb
to
52aa876
Compare
Thinking about this a bit more, I think this is not enough. If several bundles wants to add functions, it won't be possible as we are using inheritance here. Instead, I think we need to create some kind of |
Multiple ExpressionLanguage is a good option but can create conflict with multiple expression language. |
This PR was merged into the 2.6-dev branch. Discussion ---------- Expression language extensibility | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #10512 | License | MIT | Doc PR | not yet The way we can add functions to an ExpressionLanguage instance is by using inheritance. #10512 tries to make the expression language in the routing flexible but using inheritance won't work when several bundles want to add functions. So, this PR takes another approach to solve the problem globally. Todo: * [x] add some more tests * [ ] add some docs Commits ------- 7c24188 [FrameworkBundle] added a compiler pass for expression language providers 4195a91 [Routing] added support for custom expression language functions 1a39046 [Security] added support for custom expression language functions 79bcd52 [DependencyInjection] added support for custom expression language functions 184742c [ExpressionLanguage] added ExpressionFunction and ExpressionFunctionProviderInterface
A new expression language engine in a routing component can't extended with new custom functions, in my project i need custom function in a route condition.
with this patch and a custom compilerpass in my bundle i can added my custom function (version_compare of php).
this feature work with symfony/routing >= 2.4
a code of examplebundle.routing_expression_language is here: