Skip to content

[Routing] Fixed priority getting lost when setting localized prefix #52913

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

Merged
merged 1 commit into from
Jan 30, 2024

Conversation

SystematicCZ
Copy link

@SystematicCZ SystematicCZ commented Dec 6, 2023

Q A
Branch? 5.4
Bug fix? yes
New feature? no
Deprecations? no
Issues Fix #52912
License MIT

When a route prefix is an array, the original route is removed from the collection and then re-added with a new name and path. During this process, the route's priority is lost as it's not preserved during the removal and re-addition.

Current state of PrefixTrait.php

 $routes->remove($name);
 ...
  $routes->add($name.'.'.$locale, $localizedRoute);

To resolve this issue, I implemented a change where the priority of the route is stored before removal. This stored priority is then reassigned to the route when it's added back to the collection.

@carsonbot
Copy link

Hey!

I see that this is your first PR. That is great! Welcome!

Symfony has a contribution guide which I suggest you to read.

In short:

  • Always add tests
  • Keep backward compatibility (see https://symfony.com/bc).
  • Bug fixes must be submitted against the lowest maintained branch where they apply (see https://symfony.com/releases)
  • Features and deprecations must be submitted against the 7.1 branch.

Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change.

When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor!
If this PR is merged in a lower version branch, it will be merged up to all maintained branches within a few days.

I am going to sit back now and wait for the reviews.

Cheers!

Carsonbot

@SystematicCZ SystematicCZ force-pushed the fix_52912 branch 2 times, most recently from 5a1519e to 347a471 Compare December 6, 2023 13:39
Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm annoyed by the need for adding a method but I don't see any other non-hacky way.
Since this issue exists in 5.4, can you please rebase/retarget the PR for 5.4?

@nicolas-grekas nicolas-grekas modified the milestones: 6.4, 5.4 Jan 29, 2024
@SystematicCZ
Copy link
Author

Thx. I will rebase tommorow.

{
new LoaderResolver([
$loader = new YamlFileLoader(new FileLocator(\dirname(__DIR__).'/Fixtures/localized')),
new class() extends AttributeClassLoader {
Copy link
Member

@nicolas-grekas nicolas-grekas Jan 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class doesn't exist in 5.4.
Maybe we can define the routes using plain yaml or xml instead so that we don't have to deal with this concern (migrating from annotations to attributes when merging up ;) )

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, thats a good idea. I will fix

Copy link
Author

@SystematicCZ SystematicCZ Jan 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to docs priority can be set only in annotations or attributes. So I don't see a clear way how to test this easily on 5.4 and 6 without changing the code between those

In YAML and XML you can move the route definitions up or down in the configuration file to control their priority. In routes defined as PHP attributes this is much harder to do, so you can set the optional priority parameter in those routes to control their priority

@nicolas-grekas nicolas-grekas force-pushed the fix_52912 branch 2 times, most recently from d9d6695 to 47dfa69 Compare January 30, 2024 11:48
@SystematicCZ SystematicCZ force-pushed the fix_52912 branch 4 times, most recently from 4133cd7 to 6360deb Compare January 30, 2024 12:45
@nicolas-grekas
Copy link
Member

Thank you @SystematicCZ.

@nicolas-grekas nicolas-grekas merged commit 0566c39 into symfony:5.4 Jan 30, 2024
@SystematicCZ SystematicCZ deleted the fix_52912 branch January 30, 2024 13:16
This was referenced Jan 30, 2024
@fabpot fabpot mentioned this pull request Jan 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants