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

Breadcrumb

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

function ServicesConfigurator::set

Registers a service.

Parameters

string|null $id The service id, or null to create an anonymous service:

string|null $class The class of the service, or null when $id is also the class name:

1 call to ServicesConfigurator::set()
ServicesConfigurator::__invoke in vendor/symfony/dependency-injection/Loader/Configurator/ServicesConfigurator.php
Registers a service.

File

vendor/symfony/dependency-injection/Loader/Configurator/ServicesConfigurator.php, line 72

Class

ServicesConfigurator
@author Nicolas Grekas <p@tchwork.com>

Namespace

Symfony\Component\DependencyInjection\Loader\Configurator

Code

public final function set(?string $id, ?string $class = null) : ServiceConfigurator {
    $defaults = $this->defaults;
    $definition = new Definition();
    if (null === $id) {
        if (!$class) {
            throw new \LogicException('Anonymous services must have a class name.');
        }
        $id = \sprintf('.%d_%s', ++$this->anonymousCount, preg_replace('/^.*\\\\/', '', $class) . '~' . $this->anonymousHash);
    }
    elseif (!$defaults->isPublic() || !$defaults->isPrivate()) {
        $definition->setPublic($defaults->isPublic() && !$defaults->isPrivate());
    }
    $definition->setAutowired($defaults->isAutowired());
    $definition->setAutoconfigured($defaults->isAutoconfigured());
    // deep clone, to avoid multiple process of the same instance in the passes
    $definition->setBindings(unserialize(serialize($defaults->getBindings())));
    $definition->setChanges([]);
    $configurator = new ServiceConfigurator($this->container, $this->instanceof, true, $this, $definition, $id, $defaults->getTags(), $this->path);
    return null !== $class ? $configurator->class($class) : $configurator;
}
RSS feed
Powered by Drupal