function ContainerBuilder::setDefinition

Same name in other branches
  1. 8.9.x core/lib/Drupal/Core/DependencyInjection/ContainerBuilder.php \Drupal\Core\DependencyInjection\ContainerBuilder::setDefinition()
1 call to ContainerBuilder::setDefinition()
ContainerBuilder::register in core/lib/Drupal/Core/DependencyInjection/ContainerBuilder.php

File

core/lib/Drupal/Core/DependencyInjection/ContainerBuilder.php, line 71

Class

ContainerBuilder
Drupal's dependency injection container builder.

Namespace

Drupal\Core\DependencyInjection

Code

public function setDefinition($id, Definition $definition) : Definition {
    $definition = parent::setDefinition($id, $definition);
    // As of Symfony 3.4 all definitions are private by default.
    // \Symfony\Component\DependencyInjection\Compiler\ResolvePrivatesPassOnly
    // removes services marked as private from the container even if they are
    // also marked as public. Drupal requires services that are public to
    // remain in the container and not be removed.
    if ($definition->isPublic() && $definition->isPrivate()) {
        @trigger_error('Not marking service definitions as public is deprecated in drupal:9.2.0 and is required in drupal:10.0.0. Call $definition->setPublic(TRUE) before calling ::setDefinition(). See https://www.drupal.org/node/3194517', E_USER_DEPRECATED);
        $definition->setPrivate(FALSE);
    }
    return $definition;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.