Update FileLoader to fix issue #10339
FileLoader now uses resolved FileLoader's (the one that explicitly supports that resource) FileLocatorInterface instance before falling back to its own when trying to load resources in import() method.
This commit is contained in:
parent
ca60916331
commit
3988728169
@ -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