-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DependencyInjection] Add support for casting callables into single-method interfaces #49632
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
Conversation
Doesn't this reduce the evolutivity of the interface? If I understand this correctly then adding a second method to the interface would break your wrapping. I don't see the real benefits at the moment. Could you share real world usage cases ? |
@Neirda24 adding a method to an interface is a BC break so this shouldn't come unplanned. Also the segregation principle tells us that interfaces should have less methods, not more, so that the natural path for them is to shrink, not grow. Of course nothing enforces this, but this still helps answer you argument. I don't have a better real world usage than the one I posted in the description. |
@nicolas-grekas : agreed on the principles. I simply fear that it adds a lot of complexity both to maintain in symfony and to read in real world apps without gaining much from it. Maybe there is something I am not seeing ATM. Using the factory we usually expect that the class or type is the one from the method itself, here it is automatically cast as what Interface was provided on the service definition. AFAIK only this factory would do this. Am I wrong ? |
ac79179
to
1e609b0
Compare
PR updated to make it easy to configure. This should alleviate your concerns @Neirda24. About the complexity for maintainers, this was pretty straightforward to implement actually so it's not an issue to me. |
Indeed easier to read. And less confusing for new developers. Gotta make sure the "cast" keyword is kept out of the documentation because even though it could be affiliated to a cast it is more a decorator to me. Thanks @nicolas-grekas ! |
981b377
to
42618d2
Compare
42618d2
to
31c4039
Compare
rebase needed |
done |
31c4039
to
9c48c76
Compare
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.
Cool
f8ff913
to
a20f329
Compare
(rebased) |
a20f329
to
9419701
Compare
9419701
to
3da7803
Compare
3da7803
to
a4bf469
Compare
8a74fd9
to
be26be8
Compare
f54e352
to
ad0c643
Compare
…method interfaces
ad0c643
to
9975de2
Compare
This PR makes it possible to cast closures to single-method interfaces.
It is best reviewed ignoring whitespaces.
This works at the service definition level. Here is an example that creates heterogeneous URI-template expanders and exposes them under a common interface (using real classes inspired from #49302):
And then, in some service configuration using the PHP-DSL:
Internally, this creates a proxy class that will behave like this one (which could be used in a test case):
This also adds support for YAML and XML of course:
This also works using attributes: