[DI] Add Yaml syntax for short services definition
This commit is contained in:
parent
f8b02ed038
commit
83b599c6ad
@ -229,6 +229,10 @@ class YamlFileLoader extends FileLoader
|
||||
return;
|
||||
}
|
||||
|
||||
if (is_array($service) && array_values($service) === $service) {
|
||||
$service = array('arguments' => $service);
|
||||
}
|
||||
|
||||
if (null === $service) {
|
||||
$service = array();
|
||||
}
|
||||
|
@ -39,3 +39,5 @@ services:
|
||||
alias: with_defaults
|
||||
|
||||
with_defaults_aliased_short: '@with_defaults'
|
||||
|
||||
with_shortcut_args: [foo]
|
||||
|
@ -39,3 +39,4 @@ services:
|
||||
new_factory1: { class: FooBarClass, factory: factory}
|
||||
new_factory2: { class: FooBarClass, factory: ['@baz', getClass]}
|
||||
new_factory3: { class: FooBarClass, factory: [BazClass, getInstance]}
|
||||
with_shortcut_args: [foo, '@baz']
|
||||
|
@ -153,6 +153,7 @@ class YamlFileLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals('factory', $services['new_factory1']->getFactory(), '->load() parses the factory tag');
|
||||
$this->assertEquals(array(new Reference('baz'), 'getClass'), $services['new_factory2']->getFactory(), '->load() parses the factory tag');
|
||||
$this->assertEquals(array('BazClass', 'getInstance'), $services['new_factory3']->getFactory(), '->load() parses the factory tag');
|
||||
$this->assertEquals(array('foo', new Reference('baz')), $services['with_shortcut_args']->getArguments(), '->load() parses short service definition');
|
||||
|
||||
$aliases = $container->getAliases();
|
||||
$this->assertTrue(isset($aliases['alias_for_foo']), '->load() parses aliases');
|
||||
@ -383,6 +384,10 @@ class YamlFileLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertArrayNotHasKey('public', $container->getDefinition('no_defaults_child')->getChanges());
|
||||
$this->assertArrayNotHasKey('autowire', $container->getDefinition('no_defaults_child')->getChanges());
|
||||
|
||||
$this->assertFalse($container->getDefinition('with_shortcut_args')->isPublic());
|
||||
$this->assertSame(array('foo' => array(array())), $container->getDefinition('with_shortcut_args')->getTags());
|
||||
$this->assertTrue($container->getDefinition('with_shortcut_args')->isAutowired());
|
||||
|
||||
$container->compile();
|
||||
|
||||
$this->assertTrue($container->getDefinition('with_null')->isPublic());
|
||||
|
Reference in New Issue
Block a user