You are here

class ContainerBuilder in Zircon Profile 8

Same name in this branch
  1. 8 vendor/symfony/dependency-injection/ContainerBuilder.php \Symfony\Component\DependencyInjection\ContainerBuilder
  2. 8 core/lib/Drupal/Core/DependencyInjection/ContainerBuilder.php \Drupal\Core\DependencyInjection\ContainerBuilder
Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/DependencyInjection/ContainerBuilder.php \Drupal\Core\DependencyInjection\ContainerBuilder

Drupal's dependency injection container builder.

@todo Submit upstream patches to Symfony to not require these overrides.

Hierarchy

Expanded class hierarchy of ContainerBuilder

Related topics

97 files declare their use of ContainerBuilder
AcceptHeaderRoutingTestServiceProvider.php in core/modules/system/tests/modules/accept_header_routing_test/src/AcceptHeaderRoutingTestServiceProvider.php
Contains \Drupal\accept_header_routing_test\AcceptHeaderRoutingTestServiceProvider.
AccessResultTest.php in core/tests/Drupal/Tests/Core/Access/AccessResultTest.php
Contains \Drupal\Tests\Core\Access\AccessResultTest.
BaseFieldDefinitionTest.php in core/tests/Drupal/Tests/Core/Entity/BaseFieldDefinitionTest.php
Contains \Drupal\Tests\Core\Entity\BaseFieldDefinitionTest.
BaseFieldDefinitionTestBase.php in core/tests/Drupal/Tests/Core/Field/BaseFieldDefinitionTestBase.php
Contains \Drupal\Tests\Core\Field\BaseFieldDefinitionTestBase.
BlockConfigEntityUnitTest.php in core/modules/block/tests/src/Unit/BlockConfigEntityUnitTest.php
Contains \Drupal\Tests\block\Unit\BlockConfigEntityUnitTest.

... See full list

File

core/lib/Drupal/Core/DependencyInjection/ContainerBuilder.php, line 22
Contains \Drupal\Core\DependencyInjection\ContainerBuilder.

Namespace

Drupal\Core\DependencyInjection
View source
class ContainerBuilder extends SymfonyContainerBuilder {

  /**
   * {@inheritdoc}
   */
  public function __construct(ParameterBagInterface $parameterBag = NULL) {
    $this
      ->setResourceTracking(FALSE);
    parent::__construct($parameterBag);
  }

  /**
   * Overrides Symfony\Component\DependencyInjection\ContainerBuilder::set().
   *
   * Drupal's container builder can be used at runtime after compilation, so we
   * override Symfony's ContainerBuilder's restriction on setting services in a
   * frozen builder.
   *
   * @todo Restrict this to synthetic services only. Ideally, the upstream
   *   ContainerBuilder class should be fixed to allow setting synthetic
   *   services in a frozen builder.
   */
  public function set($id, $service, $scope = self::SCOPE_CONTAINER) {
    if (strtolower($id) !== $id) {
      throw new \InvalidArgumentException("Service ID names must be lowercase: {$id}");
    }
    SymfonyContainer::set($id, $service, $scope);

    // Ensure that the _serviceId property is set on synthetic services as well.
    if (isset($this->services[$id]) && is_object($this->services[$id]) && !isset($this->services[$id]->_serviceId)) {
      $this->services[$id]->_serviceId = $id;
    }
  }

  /**
   * {@inheritdoc}
   */
  public function register($id, $class = null) {
    if (strtolower($id) !== $id) {
      throw new \InvalidArgumentException("Service ID names must be lowercase: {$id}");
    }
    return parent::register($id, $class);
  }

  /**
   * {@inheritdoc}
   */
  public function setParameter($name, $value) {
    if (strtolower($name) !== $name) {
      throw new \InvalidArgumentException("Parameter names must be lowercase: {$name}");
    }
    parent::setParameter($name, $value);
  }

  /**
   * A 1to1 copy of parent::callMethod.
   */
  protected function callMethod($service, $call) {
    $services = self::getServiceConditionals($call[1]);
    foreach ($services as $s) {
      if (!$this
        ->has($s)) {
        return;
      }
    }
    call_user_func_array(array(
      $service,
      $call[0],
    ), $this
      ->resolveServices($this
      ->getParameterBag()
      ->resolveValue($call[1])));
  }

  /**
   * {@inheritdoc}
   */
  public function __sleep() {
    assert(FALSE, 'The container was serialized.');
    return array_keys(get_object_vars($this));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ContainerBuilder::$aliasDefinitions private property
ContainerBuilder::$compiler private property
ContainerBuilder::$definitions private property
ContainerBuilder::$expressionLanguage private property
ContainerBuilder::$expressionLanguageProviders private property
ContainerBuilder::$extensionConfigs private property
ContainerBuilder::$extensions private property
ContainerBuilder::$extensionsByNs private property
ContainerBuilder::$obsoleteDefinitions private property
ContainerBuilder::$proxyInstantiator private property
ContainerBuilder::$resources private property
ContainerBuilder::$trackResources private property
ContainerBuilder::addAliases public function Adds the service aliases.
ContainerBuilder::addClassResource public function Adds the given class hierarchy as resources.
ContainerBuilder::addCompilerPass public function Adds a compiler pass.
ContainerBuilder::addDefinitions public function Adds the service definitions.
ContainerBuilder::addExpressionLanguageProvider public function
ContainerBuilder::addObjectResource public function Adds the object class hierarchy as resources.
ContainerBuilder::addResource public function Adds a resource for this configuration.
ContainerBuilder::callMethod protected function A 1to1 copy of parent::callMethod. Overrides ContainerBuilder::callMethod
ContainerBuilder::compile public function Compiles the container.
ContainerBuilder::createService public function Creates a service for a service definition.
ContainerBuilder::findDefinition public function Gets a service definition by id or alias.
ContainerBuilder::findTaggedServiceIds public function Returns service ids for a given tag. Overrides TaggedContainerInterface::findTaggedServiceIds
ContainerBuilder::findTags public function Returns all tags the defined services use.
ContainerBuilder::get public function Gets a service. Overrides ContainerInterface::get
ContainerBuilder::getAlias public function Gets an alias.
ContainerBuilder::getAliases public function Gets all defined aliases.
ContainerBuilder::getCompiler public function Returns the compiler.
ContainerBuilder::getCompilerPassConfig public function Returns the compiler pass config which can then be modified.
ContainerBuilder::getDefinition public function Gets a service definition.
ContainerBuilder::getDefinitions public function Gets all service definitions.
ContainerBuilder::getExpressionLanguage private function
ContainerBuilder::getExpressionLanguageProviders public function
ContainerBuilder::getExtension public function Returns an extension by alias or namespace.
ContainerBuilder::getExtensionConfig public function Returns the configuration array for the given extension.
ContainerBuilder::getExtensions public function Returns all registered extensions.
ContainerBuilder::getProxyInstantiator private function Retrieves the currently set proxy instantiator or instantiates one.
ContainerBuilder::getResources public function Returns an array of resources loaded to build this configuration.
ContainerBuilder::getScopeChildren public function Returns all Scope children.
ContainerBuilder::getScopes public function Returns all Scopes.
ContainerBuilder::getServiceConditionals public static function Returns the Service Conditionals.
ContainerBuilder::getServiceIds public function Gets all service ids.
ContainerBuilder::has public function Returns true if the given service is defined. Overrides ContainerInterface::has
ContainerBuilder::hasAlias public function Returns true if an alias exists under the given identifier.
ContainerBuilder::hasDefinition public function Returns true if a service definition exists under the given identifier.
ContainerBuilder::hasExtension public function Checks if we have an extension.
ContainerBuilder::isTrackingResources public function Checks if resources are tracked.
ContainerBuilder::loadFromExtension public function Loads the configuration for an extension.
ContainerBuilder::merge public function Merges a ContainerBuilder with the current ContainerBuilder configuration.
ContainerBuilder::prependExtensionConfig public function Prepends a config array to the configs of the given extension.
ContainerBuilder::register public function Registers a service definition. Overrides ContainerBuilder::register
ContainerBuilder::registerExtension public function Registers an extension.
ContainerBuilder::removeAlias public function Removes an alias.
ContainerBuilder::removeDefinition public function Removes a service definition.
ContainerBuilder::resolveServices public function Replaces service references by the real service instance and evaluates expressions.
ContainerBuilder::set public function Overrides Symfony\Component\DependencyInjection\ContainerBuilder::set(). Overrides ContainerBuilder::set
ContainerBuilder::setAlias public function Sets an alias for an existing service.
ContainerBuilder::setAliases public function Sets the service aliases.
ContainerBuilder::setDefinition public function Sets a service definition.
ContainerBuilder::setDefinitions public function Sets the service definitions.
ContainerBuilder::setParameter public function Sets a parameter. Overrides ContainerInterface::setParameter
ContainerBuilder::setProxyInstantiator public function Sets the instantiator to be used when fetching proxies.
ContainerBuilder::setResources public function Sets the resources for this configuration.
ContainerBuilder::setResourceTracking public function Sets the track resources flag.
ContainerBuilder::shareService private function Shares a given service in the container.
ContainerBuilder::synchronize Deprecated private function Synchronizes a service change.
ContainerBuilder::__construct public function Constructor.
ContainerBuilder::__sleep public function
ContainerInterface::addScope public function Adds a scope to the container. 2
ContainerInterface::enterScope public function Enters the given scope. 2
ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE constant
ContainerInterface::getParameter public function Gets a parameter. 2
ContainerInterface::hasParameter public function Checks if a parameter exists. 2
ContainerInterface::hasScope public function Whether this container has the given scope. 2
ContainerInterface::IGNORE_ON_INVALID_REFERENCE constant
ContainerInterface::isScopeActive public function Determines whether the given scope is currently active. 2
ContainerInterface::leaveScope public function Leaves the current scope, and re-enters the parent scope. 2
ContainerInterface::NULL_ON_INVALID_REFERENCE constant
ContainerInterface::SCOPE_CONTAINER constant
ContainerInterface::SCOPE_PROTOTYPE constant