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

Breadcrumb

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

function ReverseContainer::getId

Same name in this branch
  1. 11.1.x core/lib/Drupal/Component/DependencyInjection/ReverseContainer.php \Drupal\Component\DependencyInjection\ReverseContainer::getId()

Returns the id of the passed object when it exists as a service.

To be reversible, services need to be either public or be tagged with "container.reversible".

File

vendor/symfony/dependency-injection/ReverseContainer.php, line 39

Class

ReverseContainer
Turns public and "container.reversible" services back to their ids.

Namespace

Symfony\Component\DependencyInjection

Code

public function getId(object $service) : ?string {
    if ($this->serviceContainer === $service) {
        return 'service_container';
    }
    if (null === ($id = ($this->getServiceId)($service))) {
        return null;
    }
    if ($this->serviceContainer
        ->has($id) || $this->reversibleLocator
        ->has($id)) {
        return $id;
    }
    return null;
}
RSS feed
Powered by Drupal