Skip to content

[DependencyInjection] Add "when" argument to #[AsAlias] #60186

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
Apr 14, 2025

Conversation

Zuruuh
Copy link
Contributor

@Zuruuh Zuruuh commented Apr 9, 2025

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

Also I wonder if it would make sense to accept an array of environments in #[AsAlias], since in practice if I want to use the same service in two envs I'd have to duplicate the whole declaration now

#[AsAlias(MyInterface::class, when: 'dev']
#[AsAlias(MyInterface::class, when: 'test']
class MyClass {}

Thoughts ?

@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.3 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

@Zuruuh Zuruuh force-pushed the alias-attribute-when-argument branch from 32ab3b0 to e3fcf6d Compare April 9, 2025 09:58
@nicolas-grekas
Copy link
Member

Accepting string|array would make sense to me indeed.
Note that tests fail currently.

@Zuruuh Zuruuh force-pushed the alias-attribute-when-argument branch from e3fcf6d to 2020177 Compare April 9, 2025 12:25
@Zuruuh
Copy link
Contributor Author

Zuruuh commented Apr 9, 2025

👍 Updated the implem to use a string|array instead 👍 Also moved the check for existing aliases inside of the env condition to ensure we don't fail when an alias isn't going to be used for the selected environment.
Also fixed the huge diff on CHANGELOG.md I forgot to disable my auto-formatter 🤠

The new tests pass now locally

@Zuruuh
Copy link
Contributor Author

Zuruuh commented Apr 10, 2025

I've checked the failling tests quickly and they seem unrelated 👍 Looks like they're also failling on other PRs

@nicolas-grekas nicolas-grekas force-pushed the alias-attribute-when-argument branch from 0f2869f to 187524d Compare April 14, 2025 12:40
@nicolas-grekas
Copy link
Member

Thank you @Zuruuh.

@nicolas-grekas nicolas-grekas merged commit d5b5581 into symfony:7.3 Apr 14, 2025
6 of 11 checks passed
@Zuruuh Zuruuh deleted the alias-attribute-when-argument branch April 14, 2025 12:47
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.

Add "when" argument to #[AsAlias]
6 participants