[Routing] Avoid locating imported resources as files unless they resolve to a FileLoader
XML/YAML loaders assume imported resources are files before attempting to resolve their loader. This is problematic for loaders such as Assetic, which does not use a file as its resource. Furthermore, the previous consecutive calls to both locate() and getAbsolutePath() were redundant. File location can safely be delayed until FileLoader::import(), and we can let that throw an exception if the file is not found.
This commit is contained in:
parent
e929bc5d1b
commit
d85a839997
@ -40,13 +40,15 @@ abstract class FileLoader extends Loader
|
||||
* @param string $type The resource type
|
||||
*
|
||||
* @return RouteCollection A RouteCollection instance
|
||||
*
|
||||
* @throws \InvalidArgumentException When resource is expected to be a file and cannot be found
|
||||
*/
|
||||
public function import($resource, $type = null)
|
||||
{
|
||||
$loader = $this->resolve($resource, $type);
|
||||
|
||||
if ($loader instanceof FileLoader && null !== $this->currentDir) {
|
||||
$resource = $this->locator->getAbsolutePath($resource, $this->currentDir);
|
||||
$resource = $this->locator->locate($resource, $this->currentDir);
|
||||
}
|
||||
|
||||
return $loader->load($resource, $type);
|
||||
|
@ -56,7 +56,6 @@ class XmlFileLoader extends FileLoader
|
||||
$type = (string) $node->getAttribute('type');
|
||||
$prefix = (string) $node->getAttribute('prefix');
|
||||
$this->currentDir = dirname($path);
|
||||
$file = $this->locator->locate($resource, $this->currentDir);
|
||||
$collection->addCollection($this->import($file, $type), $prefix);
|
||||
break;
|
||||
default:
|
||||
|
@ -57,7 +57,6 @@ class YamlFileLoader extends FileLoader
|
||||
$type = isset($config['type']) ? $config['type'] : null;
|
||||
$prefix = isset($config['prefix']) ? $config['prefix'] : null;
|
||||
$this->currentDir = dirname($path);
|
||||
$file = $this->locator->locate($config['resource'], $this->currentDir);
|
||||
$collection->addCollection($this->import($file, $type), $prefix);
|
||||
} elseif (isset($config['pattern'])) {
|
||||
$this->parseRoute($collection, $name, $config, $path);
|
||||
|
Reference in New Issue
Block a user