diff --git a/core/lib/Drupal/Core/DependencyInjection/Dumper/PhpArrayDumper.php b/core/lib/Drupal/Core/DependencyInjection/Dumper/PhpArrayDumper.php index eb084d2..46c695b 100644 --- a/core/lib/Drupal/Core/DependencyInjection/Dumper/PhpArrayDumper.php +++ b/core/lib/Drupal/Core/DependencyInjection/Dumper/PhpArrayDumper.php @@ -258,11 +258,7 @@ protected function dumpCallable($callable) $callable = array($this->getServiceCall((string) $callable[0], $callable[0]), $callable[1]); } elseif ($callable[0] instanceof Definition) { - $service = $this->getServiceDefinition($callable[0]); - $callable[0] = (object) [ - 'type' => 'service', - 'value' => $service, - ]; + $callable[0] = $this->getPrivateService($callable[0]); $callable = array($callable[0], $callable[1]); } else { @@ -274,6 +270,25 @@ protected function dumpCallable($callable) } /** + * Returns a private service definition in a suitable format. + * + * @param \Symfony\Component\DependencyInjection\Definition $definition + * The definition to process. + * + * @return \stdClass + * A very lightweight private service value object. + */ + protected function getPrivateService(Definition $definition) { + $service_definition = $this->getServiceDefinition($definition); + $hash = sha1(serialize($service_definition)); + return (object) [ + 'type' => 'service', + 'id' => 'private__' . $hash, + 'value' => $service_definition, + ]; + } + + /** * Dumps the value to YAML format. * * @param mixed $value @@ -294,11 +309,7 @@ protected function dumpValue($value) } elseif ($value instanceof Reference) { return $this->getServiceCall((string) $value, $value); } elseif ($value instanceof Definition) { - $service = $this->getServiceDefinition($value); - return (object) [ - 'type' => 'service', - 'value' => $service, - ]; + return $this->getPrivateService($value); } elseif ($value instanceof Parameter) { return $this->getParameterCall((string) $value); } elseif ($value instanceof Expression) { diff --git a/core/lib/Drupal/Core/DependencyInjection/PhpArray/Container.php b/core/lib/Drupal/Core/DependencyInjection/PhpArray/Container.php index f7c7106..5bcc6f6 100644 --- a/core/lib/Drupal/Core/DependencyInjection/PhpArray/Container.php +++ b/core/lib/Drupal/Core/DependencyInjection/PhpArray/Container.php @@ -48,13 +48,6 @@ class Container implements IntrospectableContainerInterface { protected $loading = array(); /** - * The private services counter. - * - * @var int - */ - protected $privateServicesCounter = 0; - - /** * Can the container parameters still be changed. * * For testing purposes the container needs to be changed. @@ -291,13 +284,11 @@ public function setParameter($name, $value) { protected function expandArguments($arguments, $invalidBehavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE) { foreach ($arguments as $key => $argument) { if ($argument instanceof \stdClass) { - // We need a unique service name. - $name = 'private__' . $this->privateServicesCounter; - $this->privateServicesCounter++; - $this->serviceDefinitions[$name] = $argument->value; + $name = $argument->id; + if (!isset($this->serviceDefinitions[$name])) { + $this->serviceDefinitions[$name] = $argument->value; + } $arguments[$key] = $this->get($name, $invalidBehavior); - unset($this->serviceDefinitions[$name]); - unset($this->services[$name]); continue; }