-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[Routing] allow setting multiple envs in #[Route]
attribute
#61358
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
[Routing] allow setting multiple envs in #[Route]
attribute
#61358
Conversation
I'm not entirely sure if this qualifies as a breaking change 🤔 |
I believe the errors in this PR will be resolved by PR #61360 😄. |
bf489ae
to
a1ef1ee
Compare
dbeae07
to
4b5d99d
Compare
I think the errors aren't relevant in the context of this PR |
src/Symfony/Component/Routing/Tests/Fixtures/AttributeFixtures/RouteWithMultipleEnvs.php
Outdated
Show resolved
Hide resolved
4b5d99d
to
67d8e1e
Compare
src/Symfony/Component/Routing/Tests/Fixtures/AttributeFixtures/RouteWithEnv.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Routing/Tests/Fixtures/AttributeFixtures/RouteWithEnv.php
Outdated
Show resolved
Hide resolved
67d8e1e
to
dcb540c
Compare
@GromNaN Thanks a lot for all your suggestions! I’ve made the changes ❤️ |
5fc6707
to
2f6564a
Compare
return $this->env[0]; | ||
} | ||
|
||
public function setEnvs(array|string $env): void |
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.
Why do we have setters at all?
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 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 🫡
2f6564a
to
4dbbede
Compare
4dbbede
to
2ad7ff3
Compare
Thanks for the suggestions! 🙌 |
2ad7ff3
to
525ec95
Compare
Thank you @santysisi. |
Summary
This PR enhances the
Symfony\Component\Routing\Attribute\Route
attribute by allowing theenv
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
andtest
environments, two separate route attributes were needed:After
Now, the same can be achieved with a single attribute by passing an array: