Skip to content

Commit b8c0e7c

Browse files
committed
Add support for the short syntax
1 parent 51ac9a1 commit b8c0e7c

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,22 @@ private function parseDefaults(array &$content, $file)
226226
return $defaults;
227227
}
228228

229+
/**
230+
* @param array $service
231+
*
232+
* @return bool
233+
*/
234+
private function isUsingShortSyntax(array $service)
235+
{
236+
foreach (static::$keywords as $keyword) {
237+
if (array_key_exists($keyword, $service)) {
238+
return false;
239+
}
240+
}
241+
242+
return true;
243+
}
244+
229245
/**
230246
* Parses a definition.
231247
*
@@ -245,7 +261,7 @@ private function parseDefinition($id, $service, $file, array $defaults)
245261
return;
246262
}
247263

248-
if (is_array($service) && array_values($service) === $service) {
264+
if (is_array($service) && $this->isUsingShortSyntax($service)) {
249265
$service = array('arguments' => $service);
250266
}
251267

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
services:
2-
Symfony\Component\DependencyInjection\Tests\Fixtures\NamedArgumentsDummy:
3-
arguments: { apiKey: ABCD }
2+
Symfony\Component\DependencyInjection\Tests\Fixtures\NamedArgumentsDummy: { apiKey: ABCD }
3+
4+
another_one:
5+
class: Symfony\Component\DependencyInjection\Tests\Fixtures\NamedArgumentsDummy
6+
arguments:
7+
apiKey: ABCD

0 commit comments

Comments
 (0)