-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DependencyInjection] Allow using expressions as service factories #45512
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
1764295
to
d4b53cd
Compare
That's an interesting way to do it without having to change the typing of I think this could still introduce subtle BC breaks since the PHPDoc of
people could expect to get a function name when the value is a string and probably doesn't bother doing additional checks before passing it to something like the BTW good jobs adding support for passing arguments to the expression, I didn't bother doing it because the gain wasn't important but it's nice to have expressions be more in line with other types of factories. |
src/Symfony/Component/DependencyInjection/Compiler/AbstractRecursivePass.php
Outdated
Show resolved
Hide resolved
d4b53cd
to
311a8df
Compare
I agree about that, especially the last sentence :) |
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.
Well apart from that theoretical BC break (but every change can break someone's workflow) this looks good to me.
b1ae0fe
to
913e1ba
Compare
913e1ba
to
3195443
Compare
3195443
to
da35a9c
Compare
Thank you @nicolas-grekas. |
…tories (jvasseur) This PR was merged into the 6.1 branch. Discussion ---------- Add documentation for using expressions as service factories Doc PR for symfony/symfony#45512 Commits ------- f8fc3d6 Add documentation for using expressions as service factories
Replaces #45447
This PR allows using expressions as service factories:
factory: '@=service("foo").bar()'
->factory(expr('service("foo").bar()'))
<factory expression="service('foo').bar()" />
In addition, it allows the corresponding expressions to get access to the arguments of the service definition using the
arg($index)
function andargs
variable inside expressions:Internally, instead of allowing
Expression
objects inDefinition
objects as in #45447, factory expressions are conveyed as a strings that starts with@=
. This is chosen by taking inspiration from yaml and to not collide with any existing callable.