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] Invokable Factory Services#30255
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
[DependencyInjection] Invokable Factory Services#30255
Uh oh!
There was an error while loading.Please reload this page.
Conversation
nicolas-grekas commentedFeb 16, 2019 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Looks like there are no reasons not to do it to me.
|
57e42e9 to98693beComparezanbaldwin commentedFeb 18, 2019
|
nicolas-grekas commentedFeb 18, 2019
actually, maybe this should be handled 100% at the loader level? If service reference then method defaults to |
src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/DependencyInjection/Compiler/AbstractRecursivePass.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
9e2edb7 to3b7bc89Compare
nicolas-grekas 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.
Nice. Could you please add some test cases? Then it will look to good me.
src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
| $factory =explode('::',$factory,2); | ||
| } | ||
| if ($factoryinstanceof Reference) { |
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.
Could beelseif. If\is_string($factory) resolves to true,instanceof will never be true. Although it does not really matter, it seems to be more logical to me, WDYT?
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.
Yes it should be an elseif logically to avoid an extra if condition.
Also I would suggest to extract the duplicate parsing logic in setConfigurator and setFactory into a private method.
zanbaldwin commentedFeb 19, 2019
Undrafting PR because I'm getting |
a470019 toc1ccda1CompareDocument new invokable factories (and configurators) implemented insymfony/symfony#30255.
Document new invokable factories (and configurators) implemented insymfony/symfony#30255.
c1ccda1 toc65fb8eCompareUh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
c65fb8e to16b7fcfCompareUh oh!
There was an error while loading.Please reload this page.
nicolas-grekas 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.
(once the remaining comments are addressed)
2e81b0f to801bb8aComparezanbaldwin commentedFeb 25, 2019
Done, and rebased latest |
| $factory =explode('::',$factory,2); | ||
| } | ||
| if ($factoryinstanceof Reference) { |
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.
Yes it should be an elseif logically to avoid an extra if condition.
Also I would suggest to extract the duplicate parsing logic in setConfigurator and setFactory into a private method.
801bb8a tob47aa9bCompare
nicolas-grekas 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.
(I just fixed the comments about the "if")
b47aa9b to23cb83fComparefabpot commentedApr 3, 2019
Thank you@zanbaldwin. |
…aldwin)This PR was squashed before being merged into the 4.3-dev branch (closes#30255).Discussion----------[DependencyInjection] Invokable Factory Services| Q | A| ------------- | ---| Branch? | `master`| Bug fix? | no| New feature? | yes| BC breaks? | no| Deprecations? | no| Tests pass? | yes| Fixed tickets || License | MIT| Doc PR |symfony/symfony-docs#11014> Failing test is in the Twig bridge, and outside of the the scope of this PR.Allow referencing invokable factory services, just as route definitions reference invokable controllers.This functionality was also added for service configurators for consistency.## Example```php<?phpnamespace App\Factory;class ServiceFactory{ public function __invoke(bool $debug) { return new Service($debug); }}``````yamlservices: App\Service: # Prepend with "@" to differentiate between service and function. factory: '@app\Factory\ServiceFactory' arguments: [ '%kernel.debug%' ]``````xml<?xml version="1.0" encoding="UTF-8" ?><container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/serviceshttp://symfony.com/schema/dic/services/services-1.0.xsd"> <services> <!-- ... --> <service > <factory service="App\Factory\ServiceFactory" /> </service> </services></container>``````php<?phpuse App\Service;use App\Factory\ServiceFactory;use Symfony\Component\DependencyInjection\Reference;$container->register(Service::class, Service::class) ->setFactory(new Reference(ServiceFactory::class));```Commits-------23cb83f [DependencyInjection] Invokable Factory Services
…dwin)This PR was merged into the master branch.Discussion----------[DependencyInjection] Invokable Factory ServicesDocument new invokable factories (and configurators) implemented insymfony/symfony#30255.There are now four ways to reference factories, perhaps making them more clear might be something else to do.- `function`- `Class::method`- `Service:method`- `@InvokableService`Commits-------2d7709f [DependencyInjection] Invokable Factory Services
Uh oh!
There was an error while loading.Please reload this page.
masterAllow referencing invokable factory services, just as route definitions reference invokable controllers.
This functionality was also added for service configurators for consistency.
Example