protected function PhpArrayContainer::resolveServicesAndParameters in Drupal 10
Same name and namespace in other branches
- 8 core/lib/Drupal/Component/DependencyInjection/PhpArrayContainer.php \Drupal\Component\DependencyInjection\PhpArrayContainer::resolveServicesAndParameters()
- 9 core/lib/Drupal/Component/DependencyInjection/PhpArrayContainer.php \Drupal\Component\DependencyInjection\PhpArrayContainer::resolveServicesAndParameters()
File
- core/lib/Drupal/Component/DependencyInjection/PhpArrayContainer.php, line 128
Class
- PhpArrayContainer
- Provides a container optimized for Drupal's needs.
Namespace
Drupal\Component\DependencyInjection
Code
protected function resolveServicesAndParameters($arguments) {
foreach ($arguments as $key => $argument) {
if ($argument instanceof \stdClass) {
$type = $argument->type;
if ($type == 'private_service') {
$id = $argument->id;
if (!empty($argument->shared) && isset($this->privateServices[$id])) {
$arguments[$key] = $this->privateServices[$id];
continue;
}
$arguments[$key] = $this
->createService($argument->value, $id);
if (!empty($argument->shared)) {
$this->privateServices[$id] = $arguments[$key];
}
continue;
}
elseif ($type == 'raw') {
$arguments[$key] = $argument->value;
continue;
}
if ($type !== NULL) {
throw new InvalidArgumentException("Undefined type '{$type}' while resolving parameters and services.");
}
}
if (is_array($argument)) {
$arguments[$key] = $this
->resolveServicesAndParameters($argument);
continue;
}
if (!is_string($argument)) {
continue;
}
if ($argument[0] === '%') {
$name = substr($argument, 1, -1);
if (!isset($this->parameters[$name])) {
$arguments[$key] = $this
->getParameter($name);
}
$argument = $this->parameters[$name];
$arguments[$key] = $argument;
}
if ($argument[0] === '@') {
$id = substr($argument, 1);
$invalid_behavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE;
if ($id[0] === '?') {
$id = substr($id, 1);
$invalid_behavior = ContainerInterface::NULL_ON_INVALID_REFERENCE;
}
if (isset($this->services[$id])) {
$arguments[$key] = $this->services[$id];
}
else {
$arguments[$key] = $this
->get($id, $invalid_behavior);
}
}
}
return $arguments;
}