feature #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
-------

632e934cfa [DI] Allow imports in string format for YAML
This commit is contained in:
Fabien Potencier 2017-07-11 15:58:08 +02:00
commit f9d73b902d
3 changed files with 6 additions and 3 deletions

View File

@ -177,7 +177,10 @@ class YamlFileLoader extends FileLoader
$defaultDirectory = dirname($file);
foreach ($content['imports'] as $import) {
if (!is_array($import)) {
throw new InvalidArgumentException(sprintf('The values in the "imports" key should be arrays in %s. Check your YAML syntax.', $file));
$import = array('resource' => $import);
}
if (!isset($import['resource'])) {
throw new InvalidArgumentException(sprintf('An import should provide a resource in %s. Check your YAML syntax.', $file));
}
$this->setCurrentDir($defaultDirectory);

View File

@ -1,2 +1,2 @@
imports:
- foo.yml
- { resource: ~ }

View File

@ -1,5 +1,5 @@
imports:
- { resource: services2.yml }
- services2.yml
- { resource: services3.yml }
- { resource: "../php/simple.php" }
- { resource: "../ini/parameters.ini", class: Symfony\Component\DependencyInjection\Loader\IniFileLoader }