Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 89cbafd

Browse filesBrowse files
committed
feature #13892 [DependencyInjection] Improved yaml syntax (hason)
This PR was merged into the 2.7 branch. Discussion ---------- [DependencyInjection] Improved yaml syntax | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | This PR adds support for this: ```yaml services: manager: class: UserManager arguments: - true calls: - method: setLogger arguments: - @logger - method: setClass arguments: - User tags: - name: manager alias: user ``` Commits ------- 0eb34f3 [DependencyInjection] Added support for keys "method" and "arguments" in "calls" statement for yaml format
2 parents 89a6b95 + 0eb34f3 commit 89cbafd
Copy full SHA for 89cbafd

File tree

3 files changed

+36
-2
lines changed
Filter options

3 files changed

+36
-2
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php
+9-2Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,15 @@ private function parseDefinition($id, $service, $file)
237237
}
238238

239239
foreach ($service['calls'] as $call) {
240-
$args = isset($call[1]) ? $this->resolveServices($call[1]) : array();
241-
$definition->addMethodCall($call[0], $args);
240+
if (isset($call['method'])) {
241+
$method = $call['method'];
242+
$args = isset($call['arguments']) ? $this->resolveServices($call['arguments']) : array();
243+
} else {
244+
$method = $call[0];
245+
$args = isset($call[1]) ? $this->resolveServices($call[1]) : array();
246+
}
247+
248+
$definition->addMethodCall($method, $args);
242249
}
243250
}
244251

+15Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,4 +270,16 @@ public function testTagWithAttributeArrayThrowsException()
270270
$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');
271271
}
272272
}
273+
274+
public function testLoadYamlOnlyWithKeys()
275+
{
276+
$container = new ContainerBuilder();
277+
$loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml'));
278+
$loader->load('services21.yml');
279+
280+
$definition = $container->getDefinition('manager');
281+
$this->assertEquals(array(array('setLogger', array(new Reference('logger'))), array('setClass', array('User'))), $definition->getMethodCalls());
282+
$this->assertEquals(array(true), $definition->getArguments());
283+
$this->assertEquals(array('manager' => array(array('alias' => 'user'))), $definition->getTags());
284+
}
273285
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.