소스 검색

[DependencyInjection] Support Yaml calls without arguments

Igor Wiedler 13 년 전
부모
커밋
24a0d0a2dc

+ 2 - 1
src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php

@@ -196,7 +196,8 @@ class YamlFileLoader extends FileLoader
 
         if (isset($service['calls'])) {
             foreach ($service['calls'] as $call) {
-                $definition->addMethodCall($call[0], $this->resolveServices($call[1]));
+                $args = isset($call[1]) ? $this->resolveServices($call[1]) : array();
+                $definition->addMethodCall($call[0], $args);
             }
         }
 

+ 1 - 0
tests/Symfony/Tests/Component/DependencyInjection/Fixtures/yaml/services6.yml

@@ -14,6 +14,7 @@ services:
     class: FooClass
     calls:
       - [ setBar, [] ]
+      - [ setBar ]
   method_call2:
     class: FooClass
     calls:

+ 1 - 1
tests/Symfony/Tests/Component/DependencyInjection/Loader/YamlFileLoaderTest.php

@@ -113,7 +113,7 @@ class YamlFileLoaderTest extends \PHPUnit_Framework_TestCase
         $this->assertEquals('sc_configure', $services['configurator1']->getConfigurator(), '->load() parses the configurator tag');
         $this->assertEquals(array(new Reference('baz'), 'configure'), $services['configurator2']->getConfigurator(), '->load() parses the configurator tag');
         $this->assertEquals(array('BazClass', 'configureStatic'), $services['configurator3']->getConfigurator(), '->load() parses the configurator tag');
-        $this->assertEquals(array(array('setBar', array())), $services['method_call1']->getMethodCalls(), '->load() parses the method_call tag');
+        $this->assertEquals(array(array('setBar', array()), array('setBar', array())), $services['method_call1']->getMethodCalls(), '->load() parses the method_call tag');
         $this->assertEquals(array(array('setBar', array('foo', new Reference('foo'), array(true, false)))), $services['method_call2']->getMethodCalls(), '->load() parses the method_call tag');
         $this->assertEquals('baz_factory', $services['factory_service']->getFactoryService());