ContainerBuilder.php in Service Container 7
File
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\Reference;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
class ContainerBuilder extends SymfonyContainerBuilder {
public function __construct(ParameterBagInterface $parameterBag = NULL) {
$this
->setResourceTracking(FALSE);
parent::__construct($parameterBag);
}
public function set($id, $service, $scope = self::SCOPE_CONTAINER) {
if (strtolower($id) !== $id) {
throw new \InvalidArgumentException("Service ID names must be lowercase: {$id}");
}
SymfonyContainer::set($id, $service, $scope);
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}");
}
return parent::register($id, $class);
}
public function setParameter($name, $value) {
if (strtolower($name) !== $name) {
throw new \InvalidArgumentException("Parameter names must be lowercase: {$name}");
}
parent::setParameter($name, $value);
}
private function synchronize($id) {
foreach ($this
->getDefinitions() as $definitionId => $definition) {
if (!$this
->initialized($definitionId)) {
continue;
}
foreach ($definition
->getMethodCalls() as $call) {
foreach ($call[1] as $argument) {
if ($argument instanceof Reference && $id == (string) $argument) {
$this
->callMethod($this
->get($definitionId), $call);
}
}
}
}
}
protected function callMethod($service, $call) {
$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() {
trigger_error('The container was serialized.', E_USER_ERROR);
return array_keys(get_object_vars($this));
}
}