class ClosureLoader

ClosureLoader loads service definitions from a PHP closure.

The Closure has access to the container as its first argument.

@author Fabien Potencier <fabien@symfony.com>

Hierarchy

  • class \Symfony\Component\DependencyInjection\Loader\ClosureLoader extends \Symfony\Component\Config\Loader\Loader

Expanded class hierarchy of ClosureLoader

2 files declare their use of ClosureLoader
ClosureLoaderTest.php in drupal/core/vendor/symfony/dependency-injection/Symfony/Component/DependencyInjection/Tests/Loader/ClosureLoaderTest.php
Kernel.php in drupal/core/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/Kernel.php

File

drupal/core/vendor/symfony/dependency-injection/Symfony/Component/DependencyInjection/Loader/ClosureLoader.php, line 24

Namespace

Symfony\Component\DependencyInjection\Loader
View source
class ClosureLoader extends Loader {
  private $container;

  /**
   * Constructor.
   *
   * @param ContainerBuilder $container A ContainerBuilder instance
   */
  public function __construct(ContainerBuilder $container) {
    $this->container = $container;
  }

  /**
   * Loads a Closure.
   *
   * @param \Closure $closure The resource
   * @param string   $type    The resource type
   */
  public function load($closure, $type = null) {
    call_user_func($closure, $this->container);
  }

  /**
   * Returns true if this class supports the given resource.
   *
   * @param mixed  $resource A resource
   * @param string $type     The resource type
   *
   * @return Boolean true if this class supports the given resource, false otherwise
   */
  public function supports($resource, $type = null) {
    return $resource instanceof \Closure;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ClosureLoader::$container private property
ClosureLoader::load public function Loads a Closure.
ClosureLoader::supports public function Returns true if this class supports the given resource.
ClosureLoader::__construct public function Constructor.