Skip to content

Conversation

@santysisi
Copy link
Contributor

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

Summary

This PR enhances the Symfony\Component\Routing\Attribute\Route attribute by allowing the env parameter to accept an array of environment names. This change enables defining a single route that is conditionally available in multiple environments without duplicating route definitions.

Before

To make a route available in both dev and test environments, two separate route attributes were needed:

#[Route('/test', name: 'test', env: 'dev')] #[Route('/test', name: 'test-testing', env: 'test')]

After

Now, the same can be achieved with a single attribute by passing an array:

#[Route('/test', name: 'test', env: ['dev', 'test'])]
@santysisi
Copy link
Contributor Author

I'm not entirely sure if this qualifies as a breaking change 🤔
If it is, I can update the UPGRADE.md and change the target branch from 7.4 to 8.0.

@santysisi
Copy link
Contributor Author

I believe the errors in this PR will be resolved by PR #61360 😄.

@santysisi santysisi force-pushed the feature/support-multiple-envs-in-route-attribute branch 3 times, most recently from bf489ae to a1ef1ee Compare August 8, 2025 22:10
@santysisi santysisi force-pushed the feature/support-multiple-envs-in-route-attribute branch 2 times, most recently from dbeae07 to 4b5d99d Compare August 9, 2025 13:30
@santysisi
Copy link
Contributor Author

I think the errors aren't relevant in the context of this PR

@santysisi santysisi force-pushed the feature/support-multiple-envs-in-route-attribute branch from 4b5d99d to 67d8e1e Compare August 10, 2025 20:08
@santysisi santysisi force-pushed the feature/support-multiple-envs-in-route-attribute branch from 67d8e1e to dcb540c Compare August 10, 2025 21:53
@santysisi
Copy link
Contributor Author

@GromNaN Thanks a lot for all your suggestions! I’ve made the changes ❤️

@santysisi santysisi force-pushed the feature/support-multiple-envs-in-route-attribute branch 2 times, most recently from 5fc6707 to 2f6564a Compare August 16, 2025 23:32
return $this->env[0];
}

public function setEnvs(array|string $env): void
Copy link
Member

Choose a reason for hiding this comment

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

Why do we have setters at all?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think adding the setter helps keep consistency with the current class design. But if you feel it’s unnecessary, I can remove it
just let me know 🫡

@santysisi santysisi force-pushed the feature/support-multiple-envs-in-route-attribute branch from 2f6564a to 4dbbede Compare August 19, 2025 23:20
@santysisi santysisi force-pushed the feature/support-multiple-envs-in-route-attribute branch from 4dbbede to 2ad7ff3 Compare August 19, 2025 23:21
@santysisi
Copy link
Contributor Author

santysisi commented Aug 19, 2025

Thanks for the suggestions! 🙌
I’ve made the changes

@nicolas-grekas nicolas-grekas force-pushed the feature/support-multiple-envs-in-route-attribute branch from 2ad7ff3 to 525ec95 Compare August 20, 2025 06:50
@nicolas-grekas
Copy link
Member

Thank you @santysisi.

@nicolas-grekas nicolas-grekas merged commit 6726234 into symfony:7.4 Aug 20, 2025
7 of 12 checks passed
This was referenced Oct 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment