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
Fabien Potencier 4ad54dad28 feature #30255 [DependencyInjection] Invokable Factory Services (zanbaldwin)
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
<?php

namespace App\Factory;

class ServiceFactory
{
    public function __invoke(bool $debug)
    {
        return new Service($debug);
    }
}
```

```yaml
services:
    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/services
               http://symfony.com/schema/dic/services/services-1.0.xsd">
    <services>
        <!-- ... -->
        <service id="App\Service"
                 class="App\Service">
            <factory service="App\Factory\ServiceFactory" />
        </service>
    </services>
</container>
```

```php
<?php

use App\Service;
use App\Factory\ServiceFactory;
use Symfony\Component\DependencyInjection\Reference;

$container->register(Service::class, Service::class)
    ->setFactory(new Reference(ServiceFactory::class));
```

Commits
-------

23cb83f726 [DependencyInjection] Invokable Factory Services
2019-04-03 14:19:39 +02:00
..
Asset Merge branch '4.2' into short-array-master 2019-01-16 22:53:39 +01:00
BrowserKit minor #30831 [HttpClient][Contracts] rename "raw_headers" to "response_headers" (nicolas-grekas) 2019-04-02 13:11:42 +02:00
Cache [Cache] add logs on early-recomputation and locking 2019-04-03 11:22:57 +02:00
Config fixed some exception previous type hints 2019-03-30 08:40:00 +01:00
Console fixed some exception previous type hints 2019-03-30 08:40:00 +01:00
CssSelector Merge branch '4.2' into short-array-master 2019-01-16 22:53:39 +01:00
Debug feature #28879 [Debug] Mimic __toString php behavior in FlattenException (Deltachaos) 2019-03-31 11:12:58 +02:00
DependencyInjection feature #30255 [DependencyInjection] Invokable Factory Services (zanbaldwin) 2019-04-03 14:19:39 +02:00
DomCrawler added PHPUnit assertions in various components 2019-04-01 18:52:57 +02:00
Dotenv Merge branch '4.2' 2019-01-24 22:40:22 +01:00
EventDispatcher [EventDispatcher] Split events across requests 2019-04-02 12:04:04 +02:00
ExpressionLanguage Merge branch '4.2' into short-array-master 2019-01-16 22:53:39 +01:00
Filesystem Handling relative/absolute path 2019-03-27 10:50:42 +01:00
Finder Throw a dedicated exception for non-existing directory 2019-03-28 12:28:31 +01:00
Form Add file links for described classes 2019-04-01 16:27:30 -04:00
HttpClient feature #30843 [HttpClient] Add ScopingHttpClient::forBaseUri() + tweak MockHttpClient (nicolas-grekas) 2019-04-03 12:40:25 +02:00
HttpFoundation [FrameworkBundle] change the way http clients are configured by leveraging ScopingHttpClient 2019-04-03 10:47:24 +02:00
HttpKernel [FrameworkBundle] change the way http clients are configured by leveraging ScopingHttpClient 2019-04-03 10:47:24 +02:00
Inflector [Inflector] remove "internal" marker from the component 2019-04-01 15:53:46 +02:00
Intl Merge branch '4.2' 2019-03-22 09:16:47 +01:00
Ldap fixed CS 2019-03-31 12:10:11 +02:00
Lock #27345 Added Lock/Store/MongoDbStore 2019-03-29 23:39:57 +10:00
Mailer [Mailer] Remove unneeded catch in ping() 2019-03-30 16:56:09 +01:00
Messenger bug #30805 [Messenger] bug fixes in Doctrine Transport (vincenttouzet) 2019-04-01 16:43:38 +02:00
Mime [Mime] added BodyRendererInterface 2019-03-27 08:07:59 +01:00
OptionsResolver [OptionsResolver] Add a new method addNormalizer and normalization hierarchy 2019-03-31 13:47:13 +02:00
Process [Process] Added more detail to the exception when the CWD is invalid 2019-04-01 15:29:45 +02:00
PropertyAccess [PropertyAccess] Allow Can Accessor in Property Access 2019-03-28 11:50:55 -07:00
PropertyInfo minor #30525 [PropertyInfo] Use a single cache item per method (deviantintegral) 2019-04-03 13:59:42 +02:00
Routing removed obsolete code 2019-03-30 08:32:15 +01:00
Security [Contracts][EventDispatcher] add EventDispatcherInterface to symfony/contracts and use it where possible 2019-03-25 18:18:00 +01:00
Serializer throw TypeErrors to prepare for type hints in 5.0 2019-03-19 22:12:04 +01:00
Stopwatch Merge branch '4.2' into short-array-master 2019-01-16 22:53:39 +01:00
Templating Merge branch '4.2' 2019-02-23 16:22:31 +01:00
Translation removed obsolete code 2019-03-30 08:32:15 +01:00
Validator added PHPUnit assertions in various components 2019-04-01 18:52:57 +02:00
VarDumper [Console] Add dumper 2019-03-24 11:32:26 +01:00
VarExporter Merge branch '4.2' into short-array-master 2019-01-16 22:53:39 +01:00
WebLink [EventDispatcher] swap arguments of dispatch() to allow registering events by FQCN 2019-03-14 08:32:46 +01:00
Workflow fixed CS 2019-03-31 12:10:11 +02:00
Yaml Merge branch '4.2' 2019-02-23 16:22:31 +01:00