Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit46c2d4b

Browse files
bug#27364 [DI] Fix bad exception on uninitialized references to non-shared services (nicolas-grekas)
This PR was merged into the 3.4 branch.Discussion----------[DI] Fix bad exception on uninitialized references to non-shared services| Q | A| ------------- | ---| Branch? | 3.4| Bug fix? | yes| New feature? | no| BC breaks? | no| Deprecations? | no| Tests pass? | yes| Fixed tickets |#27360| License | MIT| Doc PR | -This restriction is unneeded complexity that prevents legit use cases (see linked issue#27360).Commits-------8bba68f [DI] Fix bad exception on uninitialized references to non-shared services
2 parents531fcac +8bba68f commit46c2d4b

File tree

3 files changed

+3
-25
lines changed

3 files changed

+3
-25
lines changed

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespaceSymfony\Component\DependencyInjection\Compiler;
1313

14-
useSymfony\Component\DependencyInjection\Exception\InvalidArgumentException;
1514
useSymfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
1615
useSymfony\Component\DependencyInjection\ContainerInterface;
1716
useSymfony\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
thrownewServiceNotFoundException($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-
thrownewInvalidArgumentException(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‎

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-
publicfunctiontestProcessThrowsExceptionOnNonSharedUninitializedReference()
76-
{
77-
$container =newContainerBuilder();
78-
79-
$container
80-
->register('a','stdClass')
81-
->addArgument(newReference('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
publicfunctiontestProcessDefinitionWithBindings()
9372
{
9473
$container =newContainerBuilder();

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp