Skip to content

FileLoader uses ONLY its own locator even when resolving to a different FileLoader with a different locator. #10339

@msumme

Description

@msumme

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions