This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/src/Symfony/Component/DependencyInjection/Compiler
Fabien Potencier 37c599755d feature #20943 [DependencyInjection] Use current class as default class for factory declarations (ogizanagi)
This PR was merged into the 3.3-dev branch.

Discussion
----------

[DependencyInjection] Use current class as default class for factory declarations

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #20888
| License       | MIT
| Doc PR        | Should update the notice about the "class" attribute on http://symfony.com/doc/current/service_container/factories.html

#20888 makes sense to me, considering the following sample extracted from the documentation:

```xml
<service id="app.newsletter_manager" class="AppBundle\Email\NewsletterManager">
    <factory class="AppBundle\Email\NewsletterManager" method="create" />
</service>
```

The class is used as a factory to create itself, thus it can be simplified to:

```xml
<service id="app.newsletter_manager" class="AppBundle\Email\NewsletterManager">
    <factory method="create" />
</service>
```

However, it's not possible to provide the same feature for the YAML format, because it doesn't allow to distinct a function from a method call if the class is not provided explicitly under the `factory` key, whereas the xml format use a dedicated `function` attribute.
Would this inconsistency between those two formats be a no-go for this feature?

The doc notices:
> When using a factory to create services, the value chosen for the class option has no effect on the resulting service. The actual class name only depends on the object that is returned by the factory. However, the configured class name may be used by compiler passes and therefore should be set to a sensible value.

If this is merged, it should be updated wisely in order to not confuse everyone with this feature when using the xml format.

UPDATE: The yaml format is now supported when the class is not provided in the factory array:

```yml
services:
    my_factory:
        class: Bar\Baz
        factory: [~, 'create']
```

Commits
-------

e6d85700d5 [DependencyInjection] Use current class as default class for factory declarations
2017-01-23 16:48:23 -08:00
..
AbstractRecursivePass.php [DI] Factorize compiler passes around new AbstractRecursivePass 2017-01-18 21:44:53 +01:00
AnalyzeServiceReferencesPass.php [DI] Factorize compiler passes around new AbstractRecursivePass 2017-01-18 21:44:53 +01:00
AutoAliasServicePass.php Add an auto_alias compiler pass 2015-02-12 18:47:12 +01:00
AutowirePass.php [DependencyInjection] Remove an unused docblock 2017-01-23 23:12:12 +01:00
CheckCircularReferencesPass.php fixed CS 2017-01-21 08:52:33 -08:00
CheckDefinitionValidityPass.php [DI] Remove deprecated scope concept 2015-09-04 22:04:06 +02:00
CheckExceptionOnInvalidReferenceBehaviorPass.php [DI] Factorize compiler passes around new AbstractRecursivePass 2017-01-18 21:44:53 +01:00
CheckReferenceValidityPass.php [DI] Factorize compiler passes around new AbstractRecursivePass 2017-01-18 21:44:53 +01:00
Compiler.php [DI][Serializer] Add missing deprecations 2016-11-04 22:11:55 +01:00
CompilerPassInterface.php remove api tags from code 2015-09-28 19:11:22 +02:00
DecoratorServicePass.php Merge branch '2.8' into 3.1 2016-10-24 08:52:44 -07:00
ExtensionCompilerPass.php CS: apply rules 2016-11-03 08:44:53 +01:00
FactoryReturnTypePass.php [DI] Deprecate case insentivity of service identifiers 2017-01-11 16:25:44 +01:00
InlineServiceDefinitionsPass.php [DI] Factorize compiler passes around new AbstractRecursivePass 2017-01-18 21:44:53 +01:00
LoggingFormatter.php [DependencyInjection] Introduce method injection for autowiring 2016-12-02 09:49:57 +01:00
MergeExtensionConfigurationPass.php Merge branch '2.3' into 2.6 2015-03-22 17:55:57 +01:00
PassConfig.php [DependencyInjection] Use current class as default class for factory declarations 2017-01-24 00:01:39 +01:00
PriorityTaggedServiceTrait.php Fix the priority order of compiler pass trait 2016-12-20 14:31:21 +01:00
RemoveAbstractDefinitionsPass.php [2.3] CS And DocBlock Fixes 2014-12-22 16:58:09 +01:00
RemovePrivateAliasesPass.php [2.3] CS And DocBlock Fixes 2014-12-22 16:58:09 +01:00
RemoveUnusedDefinitionsPass.php made {@inheritdoc} annotations consistent across the board 2014-04-16 09:04:20 +02:00
RepeatablePassInterface.php fixed CS 2012-07-09 14:54:20 +02:00
RepeatedPass.php Minor cleanups and improvements 2016-09-06 09:06:41 -07:00
ReplaceAliasByActualDefinitionPass.php [DI] Factorize compiler passes around new AbstractRecursivePass 2017-01-18 21:44:53 +01:00
ResolveClassPass.php [DI] Deprecate case insentivity of service identifiers 2017-01-11 16:25:44 +01:00
ResolveDefinitionTemplatesPass.php [DI] Factorize compiler passes around new AbstractRecursivePass 2017-01-18 21:44:53 +01:00
ResolveFactoryClassPass.php [DependencyInjection] Use current class as default class for factory declarations 2017-01-24 00:01:39 +01:00
ResolveInvalidReferencesPass.php [DI] Factorize compiler passes around new AbstractRecursivePass 2017-01-18 21:44:53 +01:00
ResolveParameterPlaceHoldersPass.php [DI] Factorize compiler passes around new AbstractRecursivePass 2017-01-18 21:44:53 +01:00
ResolveReferencesToAliasesPass.php [DependencyInjection] Implement lazy collection type using generators 2017-01-05 21:34:37 +01:00
ServiceReferenceGraph.php [DependencyInjection] Implement lazy collection type using generators 2017-01-05 21:34:37 +01:00
ServiceReferenceGraphEdge.php [DependencyInjection] Implement lazy collection type using generators 2017-01-05 21:34:37 +01:00
ServiceReferenceGraphNode.php Merge branch '2.3' into 2.7 2016-04-14 17:17:41 +02:00