[Routing] Fix "config-file-relative" annotation loader resources

This commit is contained in:
Nicolas Grekas 2017-11-22 15:32:31 +01:00
parent 4eaf1e5ce2
commit 5998e9d7b5

View File

@ -34,7 +34,9 @@ class AnnotationDirectoryLoader extends AnnotationFileLoader
*/
public function load($path, $type = null)
{
$dir = $this->locator->locate($path);
if (!is_dir($dir = $this->locator->locate($path))) {
return parent::supports($path, $type) ? parent::load($path, $type) : new RouteCollection();
}
$collection = new RouteCollection();
$collection->addResource(new DirectoryResource($dir, '/\.php$/'));
@ -74,16 +76,18 @@ class AnnotationDirectoryLoader extends AnnotationFileLoader
*/
public function supports($resource, $type = null)
{
if (!is_string($resource)) {
if ('annotation' === $type) {
return true;
}
if ($type || !is_string($resource)) {
return false;
}
try {
$path = $this->locator->locate($resource);
return is_dir($this->locator->locate($resource));
} catch (\Exception $e) {
return false;
}
return is_dir($path) && (!$type || 'annotation' === $type);
}
}