Skip to content

Commit 672d940

Browse files
Merge branch '2.3' into 2.6
* 2.3: [Routing][DependencyInjection] Support .yaml extension in YAML loaders [DX] improve file loader error for router/other resources in bundle [FrameworkBundle] Fix Routing\DelegatingLoader resiliency to fatal errors [HttpKernel] Cleanup ExceptionListener CS fixes [DependencyInjection] Show better error when the Yaml component is not installed [2.3] SCA for Components - reference mismatches [2.3] Static Code Analysis for Components [Translation][fixed test] refresh cache when resources are no longer fresh. [Validator] Added missing Simplified Chinese (zh_CN) translations [FrameworkBundle] Workaround php -S ignoring auto_prepend_file Conflicts: src/Symfony/Bundle/FrameworkBundle/Tests/Translation/TranslatorTest.php src/Symfony/Component/Config/Exception/FileLoaderLoadException.php src/Symfony/Component/Console/Descriptor/TextDescriptor.php src/Symfony/Component/Console/Helper/TableHelper.php src/Symfony/Component/Console/Tests/Formatter/OutputFormatterTest.php src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php src/Symfony/Component/DependencyInjection/Dumper/YamlDumper.php src/Symfony/Component/HttpKernel/Debug/TraceableEventDispatcher.php src/Symfony/Component/HttpKernel/Tests/Debug/TraceableEventDispatcherTest.php src/Symfony/Component/PropertyAccess/PropertyAccessor.php src/Symfony/Component/Yaml/Tests/InlineTest.php
2 parents f5d7ef2 + 8208e7b commit 672d940

File tree

10 files changed

+29
-33
lines changed

10 files changed

+29
-33
lines changed

Compiler/ResolveDefinitionTemplatesPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function process(ContainerBuilder $container)
3939
$this->compiler = $container->getCompiler();
4040
$this->formatter = $this->compiler->getLoggingFormatter();
4141

42-
foreach (array_keys($container->getDefinitions()) as $id) {
42+
foreach ($container->getDefinitions() as $id => $definition) {
4343
// yes, we are specifically fetching the definition from the
4444
// container to ensure we are not operating on stale data
4545
$definition = $container->getDefinition($id);

Container.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE
307307
}
308308

309309
$alternatives = array();
310-
foreach (array_keys($this->services) as $key) {
310+
foreach ($this->services as $key => $associatedService) {
311311
$lev = levenshtein($id, $key);
312312
if ($lev <= strlen($id) / 3 || false !== strpos($key, $id)) {
313313
$alternatives[] = $key;

Dumper/PhpDumper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ private function addService($id, $definition)
560560
if ($definition->isSynthetic()) {
561561
$return[] = '@throws RuntimeException always since this service is expected to be injected dynamically';
562562
} elseif ($class = $definition->getClass()) {
563-
$return[] = sprintf('@return %s A %s instance.', 0 === strpos($class, '%') ? 'object' : "\\".$class, $class);
563+
$return[] = sprintf('@return %s A %s instance.', 0 === strpos($class, '%') ? 'object' : '\\'.$class, $class);
564564
} elseif ($definition->getFactory()) {
565565
$factory = $definition->getFactory();
566566
if (is_string($factory)) {
@@ -1340,7 +1340,7 @@ private function dumpValue($value, $interpolate = true)
13401340
}
13411341
}
13421342

1343-
return sprintf("new \\%s(%s)", substr(str_replace('\\\\', '\\', $class), 1, -1), implode(', ', $arguments));
1343+
return sprintf('new \\%s(%s)', substr(str_replace('\\\\', '\\', $class), 1, -1), implode(', ', $arguments));
13441344
} elseif ($value instanceof Variable) {
13451345
return '$'.$value;
13461346
} elseif ($value instanceof Reference) {

Dumper/YamlDumper.php

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
use Symfony\Component\DependencyInjection\Parameter;
1919
use Symfony\Component\DependencyInjection\Reference;
2020
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
21-
use Symfony\Component\DependencyInjection\ContainerBuilder;
2221
use Symfony\Component\ExpressionLanguage\Expression;
2322

2423
/**
@@ -32,20 +31,6 @@ class YamlDumper extends Dumper
3231
{
3332
private $dumper;
3433

35-
/**
36-
* Constructor.
37-
*
38-
* @param ContainerBuilder $container The service container to dump
39-
*
40-
* @api
41-
*/
42-
public function __construct(ContainerBuilder $container)
43-
{
44-
parent::__construct($container);
45-
46-
$this->dumper = new YmlDumper();
47-
}
48-
4934
/**
5035
* Dumps the service container as an YAML string.
5136
*
@@ -57,6 +42,14 @@ public function __construct(ContainerBuilder $container)
5742
*/
5843
public function dump(array $options = array())
5944
{
45+
if (!class_exists('Symfony\Component\Yaml\Dumper')) {
46+
throw new RuntimeException('Unable to dump the container as the Symfony Yaml Component is not installed.');
47+
}
48+
49+
if (null === $this->dumper) {
50+
$this->dumper = new YmlDumper();
51+
}
52+
6053
return $this->addParameters()."\n".$this->addServices();
6154
}
6255

Loader/YamlFileLoader.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Symfony\Component\DependencyInjection\Definition;
1818
use Symfony\Component\DependencyInjection\Reference;
1919
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
20+
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
2021
use Symfony\Component\Config\Resource\FileResource;
2122
use Symfony\Component\Yaml\Parser as YamlParser;
2223
use Symfony\Component\ExpressionLanguage\Expression;
@@ -74,7 +75,7 @@ public function load($resource, $type = null)
7475
*/
7576
public function supports($resource, $type = null)
7677
{
77-
return is_string($resource) && 'yml' === pathinfo($resource, PATHINFO_EXTENSION);
78+
return is_string($resource) && in_array(pathinfo($resource, PATHINFO_EXTENSION), array('yml', 'yaml'), true);
7879
}
7980

8081
/**
@@ -288,6 +289,10 @@ private function parseDefinition($id, $service, $file)
288289
*/
289290
protected function loadFile($file)
290291
{
292+
if (!class_exists('Symfony\Component\Yaml\Parser')) {
293+
throw new RuntimeException('Unable to load YAML config files as the Symfony Yaml Component is not installed.');
294+
}
295+
291296
if (!stream_is_local($file)) {
292297
throw new InvalidArgumentException(sprintf('This is not a local file "%s".', $file));
293298
}
@@ -323,7 +328,7 @@ private function validate($content, $file)
323328
throw new InvalidArgumentException(sprintf('The service file "%s" is not valid. It should contain an array. Check your YAML syntax.', $file));
324329
}
325330

326-
foreach (array_keys($content) as $namespace) {
331+
foreach ($content as $namespace => $data) {
327332
if (in_array($namespace, array('imports', 'parameters', 'services'))) {
328333
continue;
329334
}

ParameterBag/ParameterBag.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public function get($name)
9696
}
9797

9898
$alternatives = array();
99-
foreach (array_keys($this->parameters) as $key) {
99+
foreach ($this->parameters as $key => $parameterValue) {
100100
$lev = levenshtein($name, $key);
101101
if ($lev <= strlen($name) / 3 || false !== strpos($key, $name)) {
102102
$alternatives[] = $key;

Tests/Dumper/XmlDumperTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,21 +65,21 @@ public function testDumpAnonymousServices()
6565
{
6666
$container = include self::$fixturesPath.'/containers/container11.php';
6767
$dumper = new XmlDumper($container);
68-
$this->assertEquals("<?xml version=\"1.0\" encoding=\"utf-8\"?>
69-
<container xmlns=\"http://symfony.com/schema/dic/services\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd\">
68+
$this->assertEquals('<?xml version="1.0" encoding="utf-8"?>
69+
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
7070
<services>
71-
<service id=\"foo\" class=\"FooClass\">
72-
<argument type=\"service\">
73-
<service class=\"BarClass\">
74-
<argument type=\"service\">
75-
<service class=\"BazClass\"/>
71+
<service id="foo" class="FooClass">
72+
<argument type="service">
73+
<service class="BarClass">
74+
<argument type="service">
75+
<service class="BazClass"/>
7676
</argument>
7777
</service>
7878
</argument>
7979
</service>
8080
</services>
8181
</container>
82-
", $dumper->dump());
82+
', $dumper->dump());
8383
}
8484

8585
public function testDumpEntities()

Tests/Loader/PhpFileLoaderTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
namespace Symfony\Component\DependencyInjection\Tests\Loader;
1313

1414
use Symfony\Component\DependencyInjection\ContainerBuilder;
15-
use Symfony\Component\Config\Loader\Loader;
1615
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
1716
use Symfony\Component\Config\FileLocator;
1817

Tests/Loader/XmlFileLoaderTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use Symfony\Component\DependencyInjection\ContainerInterface;
1515
use Symfony\Component\DependencyInjection\ContainerBuilder;
1616
use Symfony\Component\DependencyInjection\Reference;
17-
use Symfony\Component\Config\Loader\Loader;
1817
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
1918
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
2019
use Symfony\Component\DependencyInjection\Loader\IniFileLoader;

Tests/Loader/YamlFileLoaderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
use Symfony\Component\DependencyInjection\ContainerBuilder;
1515
use Symfony\Component\DependencyInjection\Reference;
16-
use Symfony\Component\Config\Loader\Loader;
1716
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
1817
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
1918
use Symfony\Component\DependencyInjection\Loader\IniFileLoader;
@@ -206,6 +205,7 @@ public function testSupports()
206205
$loader = new YamlFileLoader(new ContainerBuilder(), new FileLocator());
207206

208207
$this->assertTrue($loader->supports('foo.yml'), '->supports() returns true if the resource is loadable');
208+
$this->assertTrue($loader->supports('foo.yaml'), '->supports() returns true if the resource is loadable');
209209
$this->assertFalse($loader->supports('foo.foo'), '->supports() returns true if the resource is loadable');
210210
}
211211

0 commit comments

Comments
 (0)