diff --git a/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php b/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php index 54ad8be7c8c9..e903a4263474 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php +++ b/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php @@ -237,8 +237,15 @@ private function parseDefinition($id, $service, $file) } foreach ($service['calls'] as $call) { - $args = isset($call[1]) ? $this->resolveServices($call[1]) : array(); - $definition->addMethodCall($call[0], $args); + if (isset($call['method'])) { + $method = $call['method']; + $args = isset($call['arguments']) ? $this->resolveServices($call['arguments']) : array(); + } else { + $method = $call[0]; + $args = isset($call[1]) ? $this->resolveServices($call[1]) : array(); + } + + $definition->addMethodCall($method, $args); } } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services21.yml b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services21.yml new file mode 100644 index 000000000000..da717a8bb296 --- /dev/null +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services21.yml @@ -0,0 +1,15 @@ +services: + manager: + class: UserManager + arguments: + - true + calls: + - method: setLogger + arguments: + - @logger + - method: setClass + arguments: + - User + tags: + - name: manager + alias: user diff --git a/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php b/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php index 4d40e7c9c3c2..6bcb19c74678 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php @@ -270,4 +270,16 @@ public function testTagWithAttributeArrayThrowsException() $this->assertStringStartsWith('A "tags" attribute must be of a scalar-type for service "foo_service", tag "foo", attribute "bar"', $e->getMessage(), '->load() throws an InvalidArgumentException if a tag-attribute is not a scalar'); } } + + public function testLoadYamlOnlyWithKeys() + { + $container = new ContainerBuilder(); + $loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml')); + $loader->load('services21.yml'); + + $definition = $container->getDefinition('manager'); + $this->assertEquals(array(array('setLogger', array(new Reference('logger'))), array('setClass', array('User'))), $definition->getMethodCalls()); + $this->assertEquals(array(true), $definition->getArguments()); + $this->assertEquals(array('manager' => array(array('alias' => 'user'))), $definition->getTags()); + } }