8000 [DI] Handle container.autowiring.strict_mode to opt-out from legacy a… · symfony/symfony@a4a0ae2 · GitHub
[go: up one dir, main page]

Skip to content

Commit a4a0ae2

Browse files
[DI] Handle container.autowiring.strict_mode to opt-out from legacy autowiring
1 parent dde192a commit a4a0ae2

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class AutowirePass extends AbstractRecursivePass
3434
private $lastFailure;
3535
private $throwOnAutowiringException;
3636
private $autowiringExceptions = array();
37+
private $strictMode;
3738

3839
/**
3940
* @param bool $throwOnAutowireException Errors can be retrieved via Definition::getErrors()
@@ -62,6 +63,7 @@ public function process(ContainerBuilder $container)
6263
{
6364
// clear out any possibly stored exceptions from before
6465
$this->autowiringExceptions = array();
66+
$this->strictMode = $container->hasParameter('container.autowiring.strict_mode') && $container->getParameter('container.autowiring.strict_mode');
6567

6668
try {
6769
parent::process C918 ($container);
@@ -290,7 +292,7 @@ private function getAutowiredReference(TypedReference $reference, $deprecationMe
290292
return new TypedReference($this->types[$type], $type);
291293
}
292294

293-
if (isset($this->types[$type])) {
295+
if (!$this->strictMode && isset($this->types[$type])) {
294296
$message = 'Autowiring services based on the types they implement is deprecated since Symfony 3.3 and won\'t be supported in version 4.0.';
295297
if ($aliasSuggestion = $this->getAliasesSuggestionForType($type = $reference->getType(), $deprecationMessage)) {
296298
$message .= ' '.$aliasSuggestion;
@@ -311,7 +313,9 @@ private function getAutowiredReference(TypedReference $reference, $deprecationMe
311313
return $this->autowired[$type] ? new TypedReference($this->autowired[$type], $type) : null;
312314
}
313315

314-
return $this->createAutowiredDefinition($type);
316+
if (!$this->strictMode) {
317+
return $this->createAutowiredDefinition($type);
318+
}
315319
}
316320

317321
/**

0 commit comments

Comments
 (0)
0