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/Loader
Fabien Potencier 9ac3a7e010 feature #21383 [DependencyInjection] Add support for named arguments (dunglas, nicolas-grekas)
This PR was merged into the 3.3-dev branch.

Discussion
----------

[DependencyInjection] Add support for named arguments

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | yes
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | todo

This PR introduces named arguments for services definitions. It's especially useful to inject parameters in an autowired service. It is (at least partially) an alternative to #21376 and #20738.

Usage:

```yml
services:
    _defaults: { autowire: true }
    Acme\NewsletterManager: { $apiKey: "%mandrill_api_key%" }

# Alternative (traditional) syntax
services:
    newsletter_manager:
        class: Acme\NewsletterManager
        arguments:
            $apiKey: "%mandrill_api_key%"
        autowire: true
```
```php
use Doctrine\ORM\EntityManager;
use Psr\Log\LoggerInterface;

namespace Acme;

class NewsletterManager
{
    private $logger;
    private $em;
    private $apiKey;

    public function __construct(LoggerInterface $logger, EntityManager $em, $apiKey)
    {
        $this->logger = $logger;
        $this->em = $em;
        $this->apiKey = $apiKey;
    }
}
```

Commits
-------

8a126c8537 [DI] Deprecate string keys in arguments
2ce36a6074 [DependencyInjection] Add a new pass to check arguments validity
6e501296f9 [DependencyInjection] Add support for named arguments
2017-02-13 15:38:11 +01:00
..
schema/dic/services [DI] Replace container injection by explicit service locators 2017-02-13 11:05:06 +01:00
ClosureLoader.php [DependencyInjection] fix phpDoc 2016-04-11 16:45:49 +02:00
DirectoryLoader.php [Config][DI] Add ComposerResource to track runtime + vendors 2017-02-07 15:42:58 +01:00
FileLoader.php [DI] Add "psr4" service attribute for PSR4-based discovery and registration 2017-02-12 23:09:17 +01:00
IniFileLoader.php [Config][DI] Add ComposerResource to track runtime + vendors 2017-02-07 15:42:58 +01:00
PhpFileLoader.php [Config][DI] Add ComposerResource to track runtime + vendors 2017-02-07 15:42:58 +01:00
XmlFileLoader.php [DI] Replace container injection by explicit service locators 2017-02-13 11:05:06 +01:00
YamlFileLoader.php feature #21383 [DependencyInjection] Add support for named arguments (dunglas, nicolas-grekas) 2017-02-13 15:38:11 +01:00