-
Notifications
You must be signed in to change notification settings - Fork 349
Set default options to routes created in the route-providers #5561
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
Set default options to routes created in the route-providers #5561
Conversation
I guess we should only add the |
Maybe this is something which should the Symfony CMF Routing Bundle should take care of if the |
@alexander-schranz that sounds reasonable. i guess at the time we built this (symfony 2) this option probably did not exist. do you want to do a pull request for it? we might need a compiler pass to "copy" the configuration over. |
@dbu Thanks for your quick response. I just had a look the code of the My idea was to implement this similar to the symfony implementation: symfony/symfony#27774. In that implementation, the What would be the correct service to do this in the But as far as I see, this class is not registered as service in the Thanks for your time! |
the idea of the cmf routing is that routes are stored in a database, as opposed to being statically configured. is the utf8 option a thing on the route object, or more general? and what exactly is the effect of the flag? i hope this helps you. i am afraid that this could be quite a chain of changes in the end... we do not necessarily need it for all storage solutions provided by the cmf bundle, they already do not have exactly the same features. |
@dbu Thanks for your answer! Yes, the
The effect of the flag is that the With this in mind, here comes the problem: In 4.2, Symfony added a At the moment, setting this default value to the routes when the Do you see a place for handling this in the |
i see. then i think you should do it in the step that loads the route candidates from storage. (you will need to double-check if the candidates strategy works with utf8 routes though, as the point in the cmf route loading it to not always load potentially thousands or tens of thousands of routes) |
dd0cfad
to
774dbfe
Compare
774dbfe
to
e8dbf2e
Compare
@sulu/core-team I adjusted this PR to to use compiler passes for copying the route default options to our route providers. I also updated the title and description to explain why this is necessary 🙂 |
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 think to be sure that the ContentProvider is getting the correct defaultOptions we should have some kind of functional test case to test if the route have utf8=>true set. A mocked test I think is in this cases not enough as it would not test if the compilerpass works correctly when symfony does change the routing.loader service definition.
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
|
||
class RouteDefaultOptionsCompilerPass implements CompilerPassInterface |
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.
Maybe instead of having multiple compilerpasses we should have one compilerpass in the route or core bundle which sets a parameter which could be just used by the other service definitions.
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.
Yes i thought about that too, but where should I place it? 🙂
// https://github.com/symfony/symfony/pull/31900 | ||
$container->getDefinition('sulu_website.provider.content')->replaceArgument( | ||
7, | ||
$container->getDefinition('routing.loader')->getArgument(1) |
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.
Is it not possible to use getArgument('$defaultOptions')
or something to be sure that we load no other argument instead?
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.
Unfortunately not. The argument "$defaultOptions" doesn't exist.
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.
Okay a functional test that the defaultOptions is correctly set is then for me more important, else in a symfony upgrade this is maybe forgotten to be updated.
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.
added a functional test case 🙂
0077d7c
to
cb2ab85
Compare
cb2ab85
to
aee6ddb
Compare
What's in this PR?
This PR adjusts the following route providers to include the symfony route default options:
RouteProvider
of theRouteBundle
ContentRouteProvider
of theWebsiteBundle
CustomUrlRouteProvider
of theCustomUrlRouteBundle
The route default options were introduced in Symfony 4.2 to handle the
framework.router.utf8
configuration: symfony/symfony#27774. This options allows to set theutf8
option to all router per default. This is needed when using UTF8 symbols inside of the path or the requirement of a route. Unfortunately, thesymfony-cmf/routing
package cannot handle this for us (see discussion below).The
utf8
option of theRoute
class was introduced in Symfony 3.2:Why?
Because routes cannot use UTF-8 characters without setting the
utf8
option (See sulu/SuluArticleBundle#521). For example, the pathaccééeeents
leads to the following error:This is caused by the following lines:
https://github.com/symfony/symfony/blob/35dad22f9e01b06b538837b8c729d67f26c6f6ed/src/Symfony/Component/Routing/RouteCompiler.php#L113-L118