8000 [DependencyInjection] Added support for keys "method" and "arguments"… · symfony/symfony@7549dd8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7549dd8

Browse files
committed
[DependencyInjection] Added support for keys "method" and "arguments" in "calls" statement for yaml format
1 parent 6963887 commit 7549dd8

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,14 @@ private function parseDefinition($id, $service, $file)
237237
}
238238

239239
foreach ($service['calls'] as $call) {
240-
$args = isset($cal 8000 l[1]) ? $this->resolveServices($call[1]) : array();
241-
$definition->addMethodCall($call[0], $args);
240+
$args = array();
241+
if (isset($call['arguments'])) {
242+
$args = $this->resolveServices($call['arguments']);
243+
} elseif (isset($call[1])) {
244+
$args = $this->resolveServices($call[1]);
245+
}
246+
247+
$definition->addMethodCall(isset($call['method']) ? $call['method'] : $call[0], $args);
242248
}
243249
}
244250

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
services:
2+
manager:
3+
class: UserManager
4+
arguments:
5+
- true
6+
calls:
7+
- method: setLogger
8+
arguments:
9+
- @logger
10+
- method: setClass
11+
arguments:
12+
- User
13+
tags:
14+
- name: manager
15+
alias: user

src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,4 +267,16 @@ public function testTagWithAttributeArrayThrowsException()
267267
$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');
268268
}
269269
}
270+
271+
public function testLoadYamlOnlyWithKeys()
272+
{
273+
$container = new ContainerBuilder();
274+
$loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml'));
275+
$loader->load('services21.yml');
276+
277+
$definition = $container->getDefinition('manager');
278+
$this->assertEquals(array(array('setLogger', array(new Reference('logger'))), array('setClass', array('User'))), $definition->getMethodCalls());
279+
$this->assertEquals(array(true), $definition->getArguments());
280+
$this->assertEquals(array('manager' => array(array('alias' => 'user'))), $definition->getTags());
281+
}
270282
}

0 commit comments

Comments
 (0)
0