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
Define alias with an attribute #41188
Comments
This issue with this approach is that many classes can have the attribute, which will create collisions. |
We could ask for a mandatory parameter in case of multiple interfaces. |
Actually not, there is no need for such a mechanism currently as no collision can happen, since only one service or alias can be named "foo".
Can you review actual use cases of yours and give us some examples where such aliases are need, both when you have control over the interface, and where you don't? Because putting the alias on the interface would really be the most appropriate. Maybe we can accept that when you don't have control over the interface, you should/could not use the attribute? |
Indeed, in yaml it's impossible just because you can't use the same keys twice. <?php
return static function (ContainerConfigurator $configurator): void {
$services->alias('foo', MyClass1)->alias('foo', MyClass2);
} And it's allowed: the first alias is overwritten by the second one.
The typical use case is when the interface is in a vendor. |
There's also the case when the alias is not an interface, but a arbitrary string. This and then case when you don't have control over the interface make me think it's better to use this attribute on a concrete implementation since you can't cover every case on the interface. You could make this attribute work on both interface and classes to cover this cases, but that makes the usage inconsistent IMO. |
Closing as discussed in #41207 |
See #49361 |
Description
Scenario: you have a concrete class that implements an interface. Currently, you need to add an alias in your services configuration,
The idea is to avoid it with a new php8 attribute, that can be applied to the class.
Example
the following then can be avoided:
The text was updated successfully, but these errors were encountered: