Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c6bdc5a

Browse files
[DI] Fix bad exception on uninitialized references to non-shared services
1 parent ffd612c commit c6bdc5a

File tree

3 files changed

+3
-24
lines changed

3 files changed

+3
-24
lines changed

src/Symfony/Component/DependencyInjection/Compiler/CheckExceptionOnInvalidReferenceBehaviorPass.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@ protected function processValue($value, $isRoot = false)
3131
if (ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE === $value->getInvalidBehavior() && !$this->container->has($id = (string) $value)) {
3232
throw new ServiceNotFoundException($id, $this->currentId);
3333
}
34-
if (ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE === $value->getInvalidBehavior() && $this->container->has($id = (string) $value) && !$this->container->findDefinition($id)->isShared()) {
35-
throw new InvalidArgumentException(sprintf('Invalid ignore-on-uninitialized reference found in service "%s": target service "%s" is not shared.', $this->currentId, $id));
36-
}
3734

3835
return $value;
3936
}

src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1896,6 +1896,9 @@ private function getServiceCall($id, Reference $reference = null)
18961896
if ($this->container->hasDefinition($id) && ($definition = $this->container->getDefinition($id)) && !$definition->isSynthetic()) {
18971897
if (null !== $reference && ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE === $reference->getInvalidBehavior()) {
18981898
$code = 'null';
1899+
if (!$definition->isShared()) {
1900+
return $code;
1901+
}
18991902
} elseif ($this->isTrivialInstance($definition)) {
19001903
$code = substr($this->addNewInstance($definition, '', '', $id), 8, -2);
19011904
if ($definition->isShared()) {

src/Symfony/Component/DependencyInjection/Tests/Compiler/CheckExceptionOnInvalidReferenceBehaviorPassTest.php

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -68,27 +68,6 @@ public function testProcessThrowsExceptionOnInvalidReferenceFromInlinedDefinitio
6868
$this->process($container);
6969
}
7070

71-
/**
72-
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
73-
* @expectedExceptionMessage Invalid ignore-on-uninitialized reference found in service
74-
*/
75-
public function testProcessThrowsExceptionOnNonSharedUninitializedReference()
76-
{
77-
$container = new ContainerBuilder();
78-
79-
$container
80-
->register('a', 'stdClass')
81-
->addArgument(new Reference('b', $container::IGNORE_ON_UNINITIALIZED_REFERENCE))
82-
;
83-
84-
$container
85-
->register('b', 'stdClass')
86-
->setShared(false)
87-
;
88-
89-
$this->process($container);
90-
}
91-
9271
public function testProcessDefinitionWithBindings()
9372
{
9473
$container = new ContainerBuilder();

0 commit comments

Comments
 (0)