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

Skip to content

Commit 723d26f

Browse files
bug #26635 [DI] Dont tell about autoregistration in strict autowiring mode (nicolas-grekas)
This PR was merged into the 3.4 branch. Discussion ---------- [DI] Dont tell about autoregistration in strict autowiring mode | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #25959 | License | MIT | Doc PR | - Commits ------- 5e922db [DI] Dont tell about autoregistration in strict autowiring mode
2 parents 7af20bc + 5e922db commit 723d26f

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

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

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class AutowirePass extends AbstractRecursivePass
3030
{
3131
private $definedTypes = array();
3232
private $types;
33-
private $ambiguousServiceTypes = array();
33+
private $ambiguousServiceTypes;
3434
private $autowired = array();
3535
private $lastFailure;
3636
private $throwOnAutowiringException;
@@ -71,7 +71,7 @@ public function process(ContainerBuilder $container)
7171
} finally {
7272
$this->definedTypes = array();
7373
$this->types = null;
74-
$this->ambiguousServiceTypes = array();
74+
$this->ambiguousServiceTypes = null;
7575
$this->autowired = array();
7676
}
7777
}
@@ -286,7 +286,7 @@ private function getAutowiredReference(TypedReference $reference, $deprecationMe
286286
}
287287

288288
if (null === $this->types) {
289-
$this->populateAvailableTypes();
289+
$this->populateAvailableTypes($this->strictMode);
290290
}
291291

292292
if (isset($this->definedTypes[$type])) {
@@ -322,12 +322,15 @@ private function getAutowiredReference(TypedReference $reference, $deprecationMe
322322
/**
323323
* Populates the list of available types.
324324
*/
325-
private function populateAvailableTypes()
325+
private function populateAvailableTypes($onlyAutowiringTypes = false)
326326
{
327327
$this->types = array();
328+
if (!$onlyAutowiringTypes) {
329+
$this->ambiguousServiceTypes = array();
330+
}
328331

329332
foreach ($this->container->getDefinitions() as $id => $definition) {
330-
$this->populateAvailableType($id, $definition);
333+
$this->populateAvailableType($id, $definition, $onlyAutowiringTypes);
331334
}
332335
}
333336

@@ -337,7 +340,7 @@ private function populateAvailableTypes()
337340
* @param string $id
338341
* @param Definition $definition
339342
*/
340-
private function populateAvailableType($id, Definition $definition)
343+
private function populateAvailableType($id, Definition $definition, $onlyAutowiringTypes)
341344
{
342345
// Never use abstract services
343346
if ($definition->isAbstract()) {
@@ -350,6 +353,10 @@ private function populateAvailableType($id, Definition $definition)
350353
unset($this->ambiguousServiceTypes[$type]);
351354
}
352355

356+
if ($onlyAutowiringTypes) {
357+
return;
358+
}
359+
353360
if (preg_match('/^\d+_[^~]++~[._a-zA-Z\d]{7}$/', $id) || $definition->isDeprecated() || !$reflectionClass = $this->container->getReflectionClass($definition->getClass(), false)) {
354361
return;
355362
}
@@ -479,12 +486,15 @@ private function createTypeAlternatives(TypedReference $reference)
479486
if ($message = $this->getAliasesSuggestionForType($type = $reference->getType())) {
480487
return ' '.$message;
481488
}
489+
if (null === $this->ambiguousServiceTypes) {
490+
$this->populateAvailableTypes();
491+
}
482492

483493
if (isset($this->ambiguousServiceTypes[$type])) {
484494
$message = sprintf('one of these existing services: "%s"', implode('", "', $this->ambiguousServiceTypes[$type]));
485495
} elseif (isset($this->types[$type])) {
486496
$message = sprintf('the existing "%s" service', $this->types[$type]);
487-
} elseif ($reference->getRequiringClass() && !$reference->canBeAutoregistered()) {
497+
} elseif ($reference->getRequiringClass() && !$reference->canBeAutoregistered() && !$this->strictMode) {
488498
return ' It cannot be auto-registered because it is from a different root namespace.';
489499
} else {
490500
return;

0 commit comments

Comments
 (0)