You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
bug #6507 Improve the detection of pretty URLs usage (javiereguiluz)
This PR was squashed before being merged into the 4.x branch.
Discussion
----------
Improve the detection of pretty URLs usage
Fixes#6499.
-----
The bug: if you enable pretty URLs but visit a page that doesn't use them (e.g. a Symfony route embedded in a EasyAdmin dashboard), then all URLs of the dashboard (menus, actions, etc.) use ugly URLs.
Why: because we detected if pretty URLs should be used based on the current request. This is wrong.
How to solve this:
1) We could create a config option `easyadmin.use_pretty_urls: true` ... but that would require creating a config file (that soon will be useless because EasyAdmin 5 will only use pretty URLs). It goes a bit against DX, so I don't like that solution.
2) A good technical solution would be to detect if our custom route loader is enabled and it generated the admin routes. Ideally in a Compiler Pass. Sadly, this doesn't work. I asked in Symfony Slack and smart folks like `@stof` confirmed that this can't work.
3) So, I ended up with the following solution:
3.1) The custom route loader now dumps all the generated routes using Symfony's cache component
3.2) We detect if pretty URLs are used by checking if that cached item exists and it's not empty
3.3) Indirectly, this improves a lot the performance of finding the route name for a given tuple of Dashboard + CRUD controller + Action. I was going to do this change in the future, but doing it now will help us solve this issue.
-----
I tested in my apps and everything worked as expected, so I'll try to merge this very soon. Thanks.
Commits
-------
16c0f13 Improve the detection of pretty URLs usage
if (\in_array($adminRouteName, $addedRouteNames, true)) {
159
+
thrownew \RuntimeException(sprintf('When using pretty URLs, all CRUD controllers must have unique PHP class names to generate unique route names. However, your application has at least two controllers with the FQCN "%s", generating the route "%s". Even if both CRUD controllers are in different namespaces, they cannot have the same class name. Rename one of these controllers to resolve the issue.', $crudControllerFqcn, $adminRouteName));
if (\in_array($crudActionRouteName, $addedRouteNames, true)) {
123
-
thrownew \RuntimeException(sprintf('When using pretty URLs, all CRUD controllers must have unique PHP class names to generate unique route names. However, your application has at least two controllers with the FQCN "%s", generating the route "%s". Even if both CRUD controllers are in different namespaces, they cannot have the same class name. Rename one of these controllers to resolve the issue.', $crudControllerFqcn, $crudActionRouteName));
0 commit comments