You are here

class Container in Service Container 7.2

Same name in this branch
  1. 7.2 src/DependencyInjection/Container.php \Drupal\service_container\DependencyInjection\Container
  2. 7.2 lib/Drupal/Core/DependencyInjection/Container.php \Drupal\Core\DependencyInjection\Container
  3. 7.2 lib/Drupal/Component/DependencyInjection/Container.php \Drupal\Component\DependencyInjection\Container
  4. 7.2 modules/providers/service_container_symfony/lib/Symfony/Component/DependencyInjection/Container.php \Symfony\Component\DependencyInjection\Container
  5. 7.2 modules/providers/service_container_symfony/lib/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services1-1.php \Symfony\Component\DependencyInjection\Container
Same name and namespace in other branches
  1. 7 src/DependencyInjection/Container.php \Drupal\service_container\DependencyInjection\Container

Container is a DI container that provides services to users of the class.

Hierarchy

  • class \Drupal\Component\DependencyInjection\Container implements \Symfony\Component\DependencyInjection\IntrospectableContainerInterface

Expanded class hierarchy of Container

4 files declare their use of Container
ContainerAwarePluginManagerTest.php in tests/src/Plugin/ContainerAwarePluginManagerTest.php
Contains \Drupal\Tests\service_container\Plugin\ContainerAwarePluginManagerTest
ContainerTest.php in tests/src/DependencyInjection/ContainerTest.php
Contains \Drupal\Tests\service_container\DependencyInjection\ContainerTest
ServiceContainerCToolsIntegrationTest.php in lib/Drupal/service_container/Tests/ServiceContainerCToolsIntegrationTest.php
Contains \Drupal\service_container\Tests\ServiceContainerCToolsIntegrationTest.
ServiceContainerServiceProvider.php in src/ServiceContainer/ServiceProvider/ServiceContainerServiceProvider.php
Contains \Drupal\service_container\ServiceContainer\ServiceProvider\ServiceContainerServiceProvider
2 string references to 'Container'
PhpDumper::dump in modules/providers/service_container_symfony/lib/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php
Dumps the service container as a PHP class.
PhpDumperTest::testDump in modules/providers/service_container_symfony/lib/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php

File

src/DependencyInjection/Container.php, line 19
Contains \Drupal\service_container\DependencyInjection\Container

Namespace

Drupal\service_container\DependencyInjection
View source
class Container extends PhpArrayContainer implements ContainerInterface {

  /**
   * {@inheritdoc}
   */
  public function createInstance($plugin_id, $service_definition) {
    $temporary_name = 'plugin_' . $plugin_id;
    $this->serviceDefinitions[$temporary_name] = $service_definition;
    $plugin = $this
      ->get($temporary_name);
    unset($this->serviceDefinitions[$temporary_name]);
    unset($this->services[$temporary_name]);
    return $plugin;
  }

  /**
   * {@inheritdoc}
   */
  public function getDefinition($plugin_id, $exception_on_invalid = TRUE) {
    $definition = isset($this->serviceDefinitions[$plugin_id]) ? $this->serviceDefinitions[$plugin_id] : NULL;
    if (!$definition && $exception_on_invalid) {
      throw new RuntimeException(sprintf('The "%s" service definition does not exist.', $plugin_id));
    }
    return $definition;
  }

  /**
   * {@inheritdoc}
   */
  public function getDefinitions() {
    return $this->serviceDefinitions;
  }

  /**
   * {@inheritdoc}
   */
  public function hasDefinition($plugin_id) {
    return isset($this->serviceDefinitions[$plugin_id]);
  }

  /**
   * Camelizes a string.
   *
   * @param $name
   *   The string to camelize.
   *
   * @return string
   *   The camelized string.
   *
   */
  public static function camelize($name) {
    return strtr(ucwords(strtr($name, array(
      '_' => ' ',
      '\\' => '_ ',
    ))), array(
      ' ' => '',
    ));
  }

  /**
   * Un-camelizes a string.
   *
   * @param $name
   *   The string to underscore.
   *
   * @return string
   *   The underscored string.
   *
   */
  public static function underscore($name) {
    return strtolower(preg_replace(array(
      '/([A-Z]+)([A-Z][a-z])/',
      '/([a-z\\d])([A-Z])/',
    ), array(
      '\\1_\\2',
      '\\1_\\2',
    ), $name));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Container::$aliases protected property The aliases of the container.
Container::$frozen protected property Whether the container parameters can still be changed.
Container::$loading protected property The currently loading services.
Container::$parameters protected property The parameters of the container.
Container::$privateServices protected property The instantiated private services.
Container::$serviceDefinitions protected property The service definitions of the container.
Container::$services protected property The instantiated services.
Container::addScope public function
Container::camelize public static function Camelizes a string.
Container::createInstance public function
Container::enterScope public function
Container::get public function
Container::getAlternatives protected function Provides alternatives for a given array and key.
Container::getDefinition public function Gets a specific plugin definition. Overrides DiscoveryInterface::getDefinition
Container::getDefinitions public function Gets the definition of all plugins for this type. Overrides DiscoveryInterface::getDefinitions
Container::getParameter public function
Container::getParameterAlternatives protected function Provides alternatives in case a parameter was not found.
Container::getServiceAlternatives protected function Provides alternatives in case a service was not found.
Container::getServiceIds public function Gets all defined service IDs.
Container::has public function
Container::hasDefinition public function Indicates if a specific plugin definition exists. Overrides DiscoveryInterface::hasDefinition
Container::hasParameter public function
Container::hasScope public function
Container::initialized public function
Container::isScopeActive public function
Container::leaveScope public function
Container::set public function
Container::setParameter public function
Container::underscore public static function Un-camelizes a string.
PhpArrayContainer::createService protected function Creates a service from a service definition. Overrides Container::createService
PhpArrayContainer::resolveServicesAndParameters protected function Resolves arguments that represent services or variables to the real values. Overrides Container::resolveServicesAndParameters
PhpArrayContainer::__construct public function Constructs a new Container instance. Overrides Container::__construct