-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Closed
Description
I discovered this when trying to load Annotation routes from a location NOT in a bundle.
The location was a relative path.
I added a new routing.loader with its own instance of the file loader.
my.file_locator:
class: %file_locator.class%
arguments:
- @kernel
- %custom.root_dir%/backend/Resources
- [%custom.root_dir%]
dealersite.controller_routing_loader:
class: %sensio_framework_extra.routing.loader.annot_dir.class%
tags:
- { name: routing.loader }
arguments:
- @my.file_locator
- @sensio_framework_extra.routing.loader.annot_class
I had to dig for a long time since the actual exception is buried in a try/catch in the Symfony\Component\Config\Loader\FlieLoader class.
The lines in question are in FileLoader->import.
if ($loader instanceof FileLoader && null !== $this->currentDir) {
$resource = $this->locator->locate($resource, $this->currentDir, false);
}
As you can see, the loader uses ITS OWN locator, and not the locator of the $loader that it just resolved to!
by changing the code to
try {
//This is where we try the resolved loader's locator first
$resource = $loader->getLocator()->locate($resource, $this->currentDir, false);
} catch(\Exception $e) {
$resource = $this->locator->locate($resource, $this->currentDir, false);
}
It will first try the resolved loader that supports that resource to locate the file, and if that throws an exception, it will fall back to the current loader.
Metadata
Metadata
Assignees
Labels
No labels