Skip to content

Commit f9d73b9

Browse files
committed
feature symfony#22176 [DI] Allow imports in string format for YAML (ro0NL)
This PR was merged into the 3.4 branch. Discussion ---------- [DI] Allow imports in string format for YAML | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #... <!-- #-prefixed issue number(s), if any --> | License | MIT | Doc PR | symfony/symfony-docs#... <!--highly recommended for new features--> I see no real reasons why this shouldnt be allowed.. Before ```yml imports: - { resource: config.yml } ``` After ```yml imports: - config.yml ``` Commits ------- 632e934 [DI] Allow imports in string format for YAML
2 parents 050d686 + 632e934 commit f9d73b9

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,10 @@ private function parseImports(array $content, $file)
177177
$defaultDirectory = dirname($file);
178178
foreach ($content['imports'] as $import) {
179179
if (!is_array($import)) {
180-
throw new InvalidArgumentException(sprintf('The values in the "imports" key should be arrays in %s. Check your YAML syntax.', $file));
180+
$import = array('resource' => $import);
181+
}
182+
if (!isset($import['resource'])) {
183+
throw new InvalidArgumentException(sprintf('An import should provide a resource in %s. Check your YAML syntax.', $file));
181184
}
182185

183186
$this->setCurrentDir($defaultDirectory);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
imports:
2-
- foo.yml
2+
- { resource: ~ }

src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services4.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
imports:
2-
- { resource: services2.yml }
2+
- services2.yml
33
- { resource: services3.yml }
44
- { resource: "../php/simple.php" }
55
- { resource: "../ini/parameters.ini", class: Symfony\Component\DependencyInjection\Loader\IniFileLoader }

0 commit comments

Comments
 (0)