Skip to content

Commit 79999ff

Browse files
committed
bug symfony#10348 Update FileLoader to fix issue symfony#10339 (msumme)
This PR was merged into the 2.3 branch. Discussion ---------- Update FileLoader to fix issue symfony#10339 This fixes an issue in Symfony\Component\Config\Loader\FileLoader | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | symfony#10339 | License | MIT | Doc PR | none Commits ------- 3988728 Update FileLoader to fix issue symfony#10339
2 parents 1c0fcd0 + 3988728 commit 79999ff

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

src/Symfony/Component/Config/Loader/FileLoader.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ public function import($resource, $type = null, $ignoreErrors = false, $sourceRe
6767
$loader = $this->resolve($resource, $type);
6868

6969
if ($loader instanceof FileLoader && null !== $this->currentDir) {
70-
$resource = $this->locator->locate($resource, $this->currentDir, false);
70+
$locator = $loader->getLocator() ?: $this->locator;
71+
$resource = $locator->locate($resource, $this->currentDir, false);
7172
}
7273

7374
$resources = is_array($resource) ? $resource : array($resource);

src/Symfony/Component/Config/Tests/Loader/FileLoaderTest.php

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@ class FileLoaderTest extends \PHPUnit_Framework_TestCase
2020
/**
2121
* @covers Symfony\Component\Config\Loader\FileLoader
2222
*/
23-
public function testImport()
23+
public function testImportWithFileLocatorDelegation()
2424
{
2525
$locatorMock = $this->getMock('Symfony\Component\Config\FileLocatorInterface');
26-
$locatorMock->expects($this->any())->method('locate')->will($this->onConsecutiveCalls(
26+
27+
$locatorMockForAdditionalLoader = $this->getMock('Symfony\Component\Config\FileLocatorInterface');
28+
$locatorMockForAdditionalLoader->expects($this->any())->method('locate')->will($this->onConsecutiveCalls(
2729
array('path/to/file1'), // Default
2830
array('path/to/file1', 'path/to/file2'), // First is imported
2931
array('path/to/file1', 'path/to/file2'), // Second is imported
@@ -32,8 +34,13 @@ public function testImport()
3234
));
3335

3436
$fileLoader = new TestFileLoader($locatorMock);
37+
$fileLoader->setSupports(false);
3538
$fileLoader->setCurrentDir('.');
36-
$fileLoader->setResolver($loaderResolver = new LoaderResolver(array($fileLoader)));
39+
40+
$additionalLoader = new TestFileLoader($locatorMockForAdditionalLoader);
41+
$additionalLoader->setCurrentDir('.');
42+
43+
$fileLoader->setResolver($loaderResolver = new LoaderResolver(array($fileLoader, $additionalLoader)));
3744

3845
// Default case
3946
$this->assertSame('path/to/file1', $fileLoader->import('my_resource'));
@@ -66,14 +73,16 @@ public function testImport()
6673

6774
class TestFileLoader extends FileLoader
6875
{
76+
private $supports = true;
77+
6978
public function load($resource, $type = null)
7079
{
7180
return $resource;
7281
}
7382

7483
public function supports($resource, $type = null)
7584
{
76-
return true;
85+
return $this->supports;
7786
}
7887

7988
public function addLoading($resource)
@@ -90,4 +99,9 @@ public function clearLoading()
9099
{
91100
self::$loading = array();
92101
}
102+
103+
public function setSupports($supports)
104+
{
105+
$this->supports = $supports;
106+
}
93107
}

0 commit comments

Comments
 (0)