class ConfigContextFactory

Defines configuration context factory.

The configuration context factory creates configuration context objects.

Hierarchy

Expanded class hierarchy of ConfigContextFactory

See also

\Drupal\Core\Config\Context\ContextInterface

1 file declares its use of ConfigContextFactory
UrlGeneratorTest.php in drupal/core/tests/Drupal/Tests/Core/Routing/UrlGeneratorTest.php
Contains Drupal\Tests\Core\Routing\UrlGeneratorTest.
1 string reference to 'ConfigContextFactory'
core.services.yml in drupal/core/core.services.yml
drupal/core/core.services.yml

File

drupal/core/lib/Drupal/Core/Config/Context/ConfigContextFactory.php, line 21
Contains \Drupal\Core\Config\Context\ConfigContextFactory.

Namespace

Drupal\Core\Config\Context
View source
class ConfigContextFactory {

  /**
   * An event dispatcher instance to use for configuration events.
   *
   * @var \Symfony\Component\EventDispatcher\EventDispatcher
   */
  protected $eventDispatcher;

  /**
   * Constructs the configuration context.
   *
   * @param \Symfony\Component\EventDispatcher\EventDispatcher $event_dispatcher
   *   An event dispatcher instance to use for configuration events.
   */
  public function __construct(EventDispatcher $event_dispatcher) {
    $this->eventDispatcher = $event_dispatcher;
  }

  /**
   * Returns a configuration context object.
   *
   * @param string $class
   *   (Optional) The name of the configuration class to use. Defaults to
   *   Drupal\Core\Config\Context\ConfigContext
   *
   * @return \Drupal\Core\Config\Context\ContextInterface $context
   *   (Optional) The configuration context to use.
   */
  public function get($class = NULL) {
    if (!$class) {
      $class = 'Drupal\\Core\\Config\\Context\\ConfigContext';
    }
    if (class_exists($class)) {
      $context = new $class($this->eventDispatcher);
    }
    else {
      throw new ConfigException(sprintf('Unknown config context class: %s', $class));
    }
    return $context;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConfigContextFactory::$eventDispatcher protected property An event dispatcher instance to use for configuration events.
ConfigContextFactory::get public function Returns a configuration context object.
ConfigContextFactory::__construct public function Constructs the configuration context.