This PR was merged into the 2.3 branch.
Discussion
----------
Update FileLoader to fix issue #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 | #10339
| License | MIT
| Doc PR | none
Commits
-------
3988728
Update FileLoader to fix issue #10339
This commit is contained in:
commit
79999ffd5c
@ -67,7 +67,8 @@ abstract class FileLoader extends Loader
|
||||
$loader = $this->resolve($resource, $type);
|
||||
|
||||
if ($loader instanceof FileLoader && null !== $this->currentDir) {
|
||||
$resource = $this->locator->locate($resource, $this->currentDir, false);
|
||||
$locator = $loader->getLocator() ?: $this->locator;
|
||||
$resource = $locator->locate($resource, $this->currentDir, false);
|
||||
}
|
||||
|
||||
$resources = is_array($resource) ? $resource : array($resource);
|
||||
|
@ -20,10 +20,12 @@ class FileLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
/**
|
||||
* @covers Symfony\Component\Config\Loader\FileLoader
|
||||
*/
|
||||
public function testImport()
|
||||
public function testImportWithFileLocatorDelegation()
|
||||
{
|
||||
$locatorMock = $this->getMock('Symfony\Component\Config\FileLocatorInterface');
|
||||
$locatorMock->expects($this->any())->method('locate')->will($this->onConsecutiveCalls(
|
||||
|
||||
$locatorMockForAdditionalLoader = $this->getMock('Symfony\Component\Config\FileLocatorInterface');
|
||||
$locatorMockForAdditionalLoader->expects($this->any())->method('locate')->will($this->onConsecutiveCalls(
|
||||
array('path/to/file1'), // Default
|
||||
array('path/to/file1', 'path/to/file2'), // First is imported
|
||||
array('path/to/file1', 'path/to/file2'), // Second is imported
|
||||
@ -32,8 +34,13 @@ class FileLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
));
|
||||
|
||||
$fileLoader = new TestFileLoader($locatorMock);
|
||||
$fileLoader->setSupports(false);
|
||||
$fileLoader->setCurrentDir('.');
|
||||
$fileLoader->setResolver($loaderResolver = new LoaderResolver(array($fileLoader)));
|
||||
|
||||
$additionalLoader = new TestFileLoader($locatorMockForAdditionalLoader);
|
||||
$additionalLoader->setCurrentDir('.');
|
||||
|
||||
$fileLoader->setResolver($loaderResolver = new LoaderResolver(array($fileLoader, $additionalLoader)));
|
||||
|
||||
// Default case
|
||||
$this->assertSame('path/to/file1', $fileLoader->import('my_resource'));
|
||||
@ -66,6 +73,8 @@ class FileLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
class TestFileLoader extends FileLoader
|
||||
{
|
||||
private $supports = true;
|
||||
|
||||
public function load($resource, $type = null)
|
||||
{
|
||||
return $resource;
|
||||
@ -73,7 +82,7 @@ class TestFileLoader extends FileLoader
|
||||
|
||||
public function supports($resource, $type = null)
|
||||
{
|
||||
return true;
|
||||
return $this->supports;
|
||||
}
|
||||
|
||||
public function addLoading($resource)
|
||||
@ -90,4 +99,9 @@ class TestFileLoader extends FileLoader
|
||||
{
|
||||
self::$loading = array();
|
||||
}
|
||||
|
||||
public function setSupports($supports)
|
||||
{
|
||||
$this->supports = $supports;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user