Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. ObjectLoader.php

function ObjectLoader::load

Calls the object method that will load the routes.

File

vendor/symfony/routing/Loader/ObjectLoader.php, line 36

Class

ObjectLoader
A route loader that calls a method on an object to load the routes.

Namespace

Symfony\Component\Routing\Loader

Code

public function load(mixed $resource, ?string $type = null) : RouteCollection {
    if (!preg_match('/^[^\\:]+(?:::(?:[^\\:]+))?$/', $resource)) {
        throw new \InvalidArgumentException(\sprintf('Invalid resource "%s" passed to the %s route loader: use the format "object_id::method" or "object_id" if your object class has an "__invoke" method.', $resource, \is_string($type) ? '"' . $type . '"' : 'object'));
    }
    $parts = explode('::', $resource);
    $method = $parts[1] ?? '__invoke';
    $loaderObject = $this->getObject($parts[0]);
    if (!\is_callable([
        $loaderObject,
        $method,
    ])) {
        throw new \BadMethodCallException(\sprintf('Method "%s" not found on "%s" when importing routing resource "%s".', $method, get_debug_type($loaderObject), $resource));
    }
    $routeCollection = $loaderObject->{$method}($this, $this->env);
    if (!$routeCollection instanceof RouteCollection) {
        $type = get_debug_type($routeCollection);
        throw new \LogicException(\sprintf('The "%s::%s()" method must return a RouteCollection: "%s" returned.', get_debug_type($loaderObject), $method, $type));
    }
    // make the object file tracked so that if it changes, the cache rebuilds
    $this->addClassResource(new \ReflectionClass($loaderObject), $routeCollection);
    return $routeCollection;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal