[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:
Jeremy Mikola 2011-02-10 10:49:59 -05:00 committed by Fabien Potencier
parent e929bc5d1b
commit d85a839997
3 changed files with 3 additions and 3 deletions

View File

@ -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);

View File

@ -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:

View File

@ -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);