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

Breadcrumb

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

class ServiceLocator

Same name in this branch
  1. 11.1.x vendor/symfony/dependency-injection/ServiceLocator.php \Symfony\Component\DependencyInjection\ServiceLocator

@author Nicolas Grekas <p@tchwork.com>

@internal

Hierarchy

  • class \Symfony\Component\DependencyInjection\ServiceLocator implements \Symfony\Contracts\Service\ServiceCollectionInterface uses \Symfony\Contracts\Service\ServiceLocatorTrait
    • class \Symfony\Component\DependencyInjection\Argument\ServiceLocator extends \Symfony\Component\DependencyInjection\ServiceLocator

Expanded class hierarchy of ServiceLocator

3 files declare their use of ServiceLocator
Container.php in vendor/symfony/dependency-injection/Container.php
ContainerBuilder.php in vendor/symfony/dependency-injection/ContainerBuilder.php
PhpDumper.php in vendor/symfony/dependency-injection/Dumper/PhpDumper.php

File

vendor/symfony/dependency-injection/Argument/ServiceLocator.php, line 21

Namespace

Symfony\Component\DependencyInjection\Argument
View source
class ServiceLocator extends BaseServiceLocator {
    public function __construct(\Closure $factory, array $serviceMap, ?array $serviceTypes = null) {
        parent::__construct($serviceMap);
    }
    public function get(string $id) : mixed {
        return match (\count($this->serviceMap[$id] ?? [])) {    0 => parent::get($id),
            1 => $this->serviceMap[$id][0],
            default => ($this->factory)(...$this->serviceMap[$id]),
        
        };
    }
    public function getProvidedServices() : array {
        return $this->serviceTypes ??= array_map(fn() => '?', $this->serviceMap);
    }

}

Members

Title Sort descending Modifiers Object type Summary Member alias Overriden Title
ServiceLocator::$container private property
ServiceLocator::$externalId private property
ServiceLocator::count public function
ServiceLocator::createCircularReferenceException private function Overrides ServiceLocatorTrait::createCircularReferenceException
ServiceLocator::createNotFoundException private function Overrides ServiceLocatorTrait::createNotFoundException
ServiceLocator::formatAlternatives private function
ServiceLocator::get public function Overrides ServiceLocator::get
ServiceLocator::getIterator public function
ServiceLocator::getProvidedServices public function Overrides ServiceLocatorTrait::getProvidedServices
ServiceLocator::withContext public function @internal
ServiceLocator::__construct public function Overrides ServiceLocatorTrait::__construct
ServiceLocator::__invoke public function
ServiceLocatorTrait::$factories private property
ServiceLocatorTrait::$loading private property
ServiceLocatorTrait::$providedTypes private property
ServiceLocatorTrait::get public function Aliased as: doGet
ServiceLocatorTrait::has public function
RSS feed
Powered by Drupal