From d85a83999704ccc958c7346fe869962b5b42b328 Mon Sep 17 00:00:00 2001 From: Jeremy Mikola Date: Thu, 10 Feb 2011 10:49:59 -0500 Subject: [PATCH] [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. --- src/Symfony/Component/Routing/Loader/FileLoader.php | 4 +++- src/Symfony/Component/Routing/Loader/XmlFileLoader.php | 1 - src/Symfony/Component/Routing/Loader/YamlFileLoader.php | 1 - 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/Routing/Loader/FileLoader.php b/src/Symfony/Component/Routing/Loader/FileLoader.php index c9362e7f45..69e98f0e94 100644 --- a/src/Symfony/Component/Routing/Loader/FileLoader.php +++ b/src/Symfony/Component/Routing/Loader/FileLoader.php @@ -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); diff --git a/src/Symfony/Component/Routing/Loader/XmlFileLoader.php b/src/Symfony/Component/Routing/Loader/XmlFileLoader.php index 7370939446..37c94f59ee 100644 --- a/src/Symfony/Component/Routing/Loader/XmlFileLoader.php +++ b/src/Symfony/Component/Routing/Loader/XmlFileLoader.php @@ -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: diff --git a/src/Symfony/Component/Routing/Loader/YamlFileLoader.php b/src/Symfony/Component/Routing/Loader/YamlFileLoader.php index 6898c7ae7c..00d9ef67ac 100644 --- a/src/Symfony/Component/Routing/Loader/YamlFileLoader.php +++ b/src/Symfony/Component/Routing/Loader/YamlFileLoader.php @@ -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);