Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8bba68f

Browse filesBrowse files
[DI] Fix bad exception on uninitialized references to non-shared services
1 parent ffd612c commit 8bba68f
Copy full SHA for 8bba68f

File tree

Expand file treeCollapse file tree

3 files changed

+3
-25
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+3
-25
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Compiler/CheckExceptionOnInvalidReferenceBehaviorPass.php
-4Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespace Symfony\Component\DependencyInjection\Compiler;
1313

14-
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
1514
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
1615
use Symfony\Component\DependencyInjection\ContainerInterface;
1716
use Symfony\Component\DependencyInjection\Reference;
@@ -31,9 +30,6 @@ protected function processValue($value, $isRoot = false)
3130
if (ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE === $value->getInvalidBehavior() && !$this->container->has($id = (string) $value)) {
3231
throw new ServiceNotFoundException($id, $this->currentId);
3332
}
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-
}
3733

3834
return $value;
3935
}

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php
+3Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/Compiler/CheckExceptionOnInvalidReferenceBehaviorPassTest.php
-21Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.