8000 feature #21214 [DI] Allow ~ instead of {} for services in Yaml (wouterj) · symfony/symfony@5f4ba31 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5f4ba31

Browse files
committed
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 ------- 28a1b5a Allow setting services as null
2 parents e6bd47e + 28a1b5a commit 5f4ba31

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,10 @@ private function parseDefinition($id, $service, $file, array $defaults)
220220
return;
221221
}
222222

223+
if (null === $service) {
224+
$service = array();
225+
}
226+
223227
if (!is_array($service)) {
224228
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));
225229
}

src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services28.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ services:
55
tags:
66
- name: foo
77

8+
Acme\Foo: ~
9+
810
with_defaults:
911
class: Foo
1012

0 commit comments

Comments
 (0)
0