ContainerBuilder.php in Drupal 9
File
core/lib/Drupal/Core/DependencyInjection/ContainerBuilder.php
View source
<?php
namespace Drupal\Core\DependencyInjection;
use Symfony\Component\DependencyInjection\ContainerBuilder as SymfonyContainerBuilder;
use Symfony\Component\DependencyInjection\Container as SymfonyContainer;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\LazyProxy\Instantiator\RealServiceInstantiator;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
class ContainerBuilder extends SymfonyContainerBuilder {
private $proxyInstantiator;
public function __construct(ParameterBagInterface $parameterBag = NULL) {
parent::__construct($parameterBag);
$this
->setResourceTracking(FALSE);
}
private function getProxyInstantiator() {
if (!$this->proxyInstantiator) {
$this->proxyInstantiator = new RealServiceInstantiator();
}
return $this->proxyInstantiator;
}
protected function shareService(Definition $definition, $service, $id, array &$inlineServices) {
if ($definition
->isShared()) {
$this->services[$lowerId = strtolower($id)] = $service;
}
}
public function set($id, $service) {
if (strtolower($id) !== $id) {
throw new \InvalidArgumentException("Service ID names must be lowercase: {$id}");
}
SymfonyContainer::set($id, $service);
if (isset($this->services[$id]) && is_object($this->services[$id]) && !isset($this->services[$id]->_serviceId)) {
$this->services[$id]->_serviceId = $id;
}
}
public function register($id, $class = null) {
if (strtolower($id) !== $id) {
throw new \InvalidArgumentException("Service ID names must be lowercase: {$id}");
}
$definition = new Definition($class);
$definition
->setPublic(TRUE);
return $this
->setDefinition($id, $definition);
}
public function setAlias($alias, $id) {
$alias = parent::setAlias($alias, $id);
$alias
->setPublic(TRUE);
return $alias;
}
public function setDefinition($id, Definition $definition) {
$definition = parent::setDefinition($id, $definition);
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;
}
public function setParameter($name, $value) {
if (strtolower($name) !== $name) {
throw new \InvalidArgumentException("Parameter names must be lowercase: {$name}");
}
parent::setParameter($name, $value);
}
protected function callMethod($service, $call, array &$inlineServices = array()) {
$services = self::getServiceConditionals($call[1]);
foreach ($services as $s) {
if (!$this
->has($s)) {
return;
}
}
call_user_func_array(array(
$service,
$call[0],
), $this
->resolveServices($this
->getParameterBag()
->resolveValue($call[1])));
}
public function __sleep() {
assert(FALSE, 'The container was serialized.');
return array_keys(get_object_vars($this));
}
}