Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
1764295 tod4b53cdComparejvasseur commentedFeb 23, 2022
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 OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
nicolas-grekas commentedMar 1, 2022
I agree about that, especially the last sentence :) |
jvasseur left a comment
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 to913e1baCompareUh oh!
There was an error while loading.Please reload this page.
fabpot commentedMar 26, 2022
Thank you@nicolas-grekas. |
…tories (jvasseur)This PR was merged into the 6.1 branch.Discussion----------Add documentation for using expressions as service factoriesDoc PR forsymfony/symfony#45512Commits-------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 andargsvariable inside expressions:Internally, instead of allowing
Expressionobjects inDefinitionobjects 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.