Skip to content

Commit a8d0b1a

Browse files
committed
bug symfony#14325 [Routing][DependencyInjection] Support .yaml extension in YAML loaders (thunderer)
This PR was squashed before being merged into the 2.3 branch (closes symfony#14325). Discussion ---------- [Routing][DependencyInjection] Support .yaml extension in YAML loaders | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | symfony#14319 | License | MIT | Doc PR | - YAML [FAQ](http://www.yaml.org/faq.html) states that .yaml file extension should be used whenever possible. I tweaked YamlFileLoader supports() method in Symfony Routing component to accept both .yml and .yaml and added some asserts in tests for that behavior. This PR replaces symfony#14319 as it was based on 2.7. BTW Is there a way to "rebase" PR branch without redoing all the work? Commits ------- dd5a811 [Routing][DependencyInjection] Support .yaml extension in YAML loaders
2 parents 8584bfc + dd5a811 commit a8d0b1a

File tree

4 files changed

+5
-2
lines changed

4 files changed

+5
-2
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function load($resource, $type = null)
7474
*/
7575
public function supports($resource, $type = null)
7676
{
77-
return is_string($resource) && 'yml' === pathinfo($resource, PATHINFO_EXTENSION);
77+
return is_string($resource) && in_array(pathinfo($resource, PATHINFO_EXTENSION), array('yml', 'yaml'), true);
7878
}
7979

8080
/**

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ public function testSupports()
187187
$loader = new YamlFileLoader(new ContainerBuilder(), new FileLocator());
188188

189189
$this->assertTrue($loader->supports('foo.yml'), '->supports() returns true if the resource is loadable');
190+
$this->assertTrue($loader->supports('foo.yaml'), '->supports() returns true if the resource is loadable');
190191
$this->assertFalse($loader->supports('foo.foo'), '->supports() returns true if the resource is loadable');
191192
}
192193

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public function load($file, $type = null)
104104
*/
105105
public function supports($resource, $type = null)
106106
{
107-
return is_string($resource) && 'yml' === pathinfo($resource, PATHINFO_EXTENSION) && (!$type || 'yaml' === $type);
107+
return is_string($resource) && in_array(pathinfo($resource, PATHINFO_EXTENSION), array('yml', 'yaml'), true) && (!$type || 'yaml' === $type);
108108
}
109109

110110
/**

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ public function testSupports()
2222
$loader = new YamlFileLoader($this->getMock('Symfony\Component\Config\FileLocator'));
2323

2424
$this->assertTrue($loader->supports('foo.yml'), '->supports() returns true if the resource is loadable');
25+
$this->assertTrue($loader->supports('foo.yaml'), '->supports() returns true if the resource is loadable');
2526
$this->assertFalse($loader->supports('foo.foo'), '->supports() returns true if the resource is loadable');
2627

2728
$this->assertTrue($loader->supports('foo.yml', 'yaml'), '->supports() checks the resource type if specified');
29+
$this->assertTrue($loader->supports('foo.yaml', 'yaml'), '->supports() checks the resource type if specified');
2830
$this->assertFalse($loader->supports('foo.yml', 'foo'), '->supports() checks the resource type if specified');
2931
}
3032

0 commit comments

Comments
 (0)