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

Breadcrumb

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

function PhpFileLoader::load

Same name in this branch
  1. 11.1.x vendor/symfony/routing/Loader/PhpFileLoader.php \Symfony\Component\Routing\Loader\PhpFileLoader::load()

File

vendor/symfony/dependency-injection/Loader/PhpFileLoader.php, line 50

Class

PhpFileLoader
PhpFileLoader loads service definitions from a PHP file.

Namespace

Symfony\Component\DependencyInjection\Loader

Code

public function load(mixed $resource, ?string $type = null) : mixed {
    // the container and loader variables are exposed to the included file below
    $container = $this->container;
    $loader = $this;
    $path = $this->locator
        ->locate($resource);
    $this->setCurrentDir(\dirname($path));
    $this->container
        ->fileExists($path);
    // the closure forbids access to the private scope in the included file
    $load = \Closure::bind(function ($path, $env) use ($container, $loader, $resource, $type) {
        return include $path;
    }, $this, ProtectedPhpFileLoader::class);
    try {
        $callback = $load($path, $this->env);
        if (\is_object($callback) && \is_callable($callback)) {
            $this->executeCallback($callback, new ContainerConfigurator($this->container, $this, $this->instanceof, $path, $resource, $this->env), $path);
        }
    } finally {
        $this->instanceof = [];
        $this->registerAliasesForSinglyImplementedInterfaces();
    }
    return null;
}
RSS feed
Powered by Drupal