feature #21214 [DI] Allow ~ instead of {} for services in Yaml (wouterj)

This PR was merged into the 3.3-dev branch.

Discussion
----------

[DI] Allow ~ instead of {} for services in Yaml

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

Now we can omit the class name, Yaml config can look like this:
```yaml
services:
    AppBundle\Something: {}
```

While this works, the consistent way in Symfony for such cases is to use `~`. This PR allows to use `~` as well, ending up with:
```yaml
services:
    AppBundle\Something: ~
```

Commits
-------

28a1b5ac47 Allow setting services as null
This commit is contained in:
Fabien Potencier 2017-01-09 06:01:23 -08:00
commit 5f4ba3199c
2 changed files with 6 additions and 0 deletions

View File

@ -220,6 +220,10 @@ class YamlFileLoader extends FileLoader
return;
}
if (null === $service) {
$service = array();
}
if (!is_array($service)) {
throw new InvalidArgumentException(sprintf('A service definition must be an array or a string starting with "@" but %s found for service "%s" in %s. Check your YAML syntax.', gettype($service), $id, $file));
}

View File

@ -5,6 +5,8 @@ services:
tags:
- name: foo
Acme\Foo: ~
with_defaults:
class: Foo