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

Breadcrumb

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

function ServiceLocatorTrait::get

1 call to ServiceLocatorTrait::get()
ServiceLocator::get in vendor/symfony/dependency-injection/ServiceLocator.php

File

vendor/symfony/service-contracts/ServiceLocatorTrait.php, line 46

Class

ServiceLocatorTrait
A trait to help implement ServiceProviderInterface.

Namespace

Symfony\Contracts\Service

Code

public function get(string $id) : mixed {
    if (!isset($this->factories[$id])) {
        throw $this->createNotFoundException($id);
    }
    if (isset($this->loading[$id])) {
        $ids = array_values($this->loading);
        $ids = \array_slice($this->loading, array_search($id, $ids));
        $ids[] = $id;
        throw $this->createCircularReferenceException($id, $ids);
    }
    $this->loading[$id] = $id;
    try {
        return $this->factories[$id]($this);
    } finally {
        unset($this->loading[$id]);
    }
}
RSS feed
Powered by Drupal