Skip to content

Commit 459ee7c

Browse files
[DI] Cleanup remainings from autoregistration
1 parent 7a60230 commit 459ee7c

File tree

2 files changed

+7
-24
lines changed

2 files changed

+7
-24
lines changed

Compiler/AutowirePass.php

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ class AutowirePass extends AbstractRecursivePass
2929
{
3030
private $types;
3131
private $ambiguousServiceTypes = array();
32-
private $autowired = array();
3332
private $lastFailure;
3433
private $throwOnAutowiringException;
3534

@@ -48,7 +47,6 @@ public function process(ContainerBuilder $container)
4847
} finally {
4948
$this->types = null;
5049
$this->ambiguousServiceTypes = array();
51-
$this->autowired = array();
5250
}
5351
}
5452

@@ -73,7 +71,7 @@ protected function processValue($value, $isRoot = false)
7371
private function doProcessValue($value, $isRoot = false)
7472
{
7573
if ($value instanceof TypedReference) {
76-
if ($ref = $this->getAutowiredReference($value, $value->getRequiringClass() ? sprintf('for "%s" in "%s"', $value->getType(), $value->getRequiringClass()) : '')) {
74+
if ($ref = $this->getAutowiredReference($value)) {
7775
return $ref;
7876
}
7977
$this->container->log($this, $this->createTypeNotFoundMessage($value, 'it'));
@@ -190,7 +188,7 @@ private function autowireMethod(\ReflectionFunctionAbstract $reflectionMethod, a
190188
continue;
191189
}
192190

193-
if (!$value = $this->getAutowiredReference($ref = new TypedReference($type, $type, !$parameter->isOptional() ? $class : ''), 'for '.sprintf('argument "$%s" of method "%s()"', $parameter->name, $class.'::'.$method))) {
191+
if (!$value = $this->getAutowiredReference($ref = new TypedReference($type, $type, !$parameter->isOptional() ? $class : ''))) {
194192
$failureMessage = $this->createTypeNotFoundMessage($ref, sprintf('argument "$%s" of method "%s()"', $parameter->name, $class !== $this->currentId ? $class.'::'.$method : $method));
195193

196194
if ($parameter->isDefaultValueAvailable()) {
@@ -224,30 +222,14 @@ private function autowireMethod(\ReflectionFunctionAbstract $reflectionMethod, a
224222
/**
225223
* @return TypedReference|null A reference to the service matching the given type, if any
226224
*/
227-
private function getAutowiredReference(TypedReference $reference, $deprecationMessage)
225+
private function getAutowiredReference(TypedReference $reference)
228226
{
229227
$this->lastFailure = null;
230228
$type = $reference->getType();
231229

232230
if ($type !== (string) $reference || ($this->container->has($type) && !$this->container->findDefinition($type)->isAbstract())) {
233231
return $reference;
234232
}
235-
236-
if (!$reference->canBeAutoregistered()) {
237-
return;
238-
}
239-
240-
if (null === $this->types) {
241-
$this->populateAvailableTypes();
242-
}
243-
244-
if (isset($this->types[$type]) || isset($this->ambiguousServiceTypes[$type])) {
245-
return;
246-
}
247-
248-
if (isset($this->autowired[$type])) {
249-
return $this->autowired[$type] ? new TypedReference($this->autowired[$type], $type) : null;
250-
}
251233
}
252234

253235
/**
@@ -351,6 +333,9 @@ private function createTypeAlternatives(TypedReference $reference)
351333
if ($message = $this->getAliasesSuggestionForType($type = $reference->getType())) {
352334
return ' '.$message;
353335
}
336+
if (null === $this->types) {
337+
$this->populateAvailableTypes();
338+
}
354339

355340
$servicesAndAliases = $this->container->getServiceIds();
356341
if (!$this->container->has($type) && false !== $key = array_search(strtolower($type), array_map('strtolower', $servicesAndAliases))) {
@@ -359,8 +344,6 @@ private function createTypeAlternatives(TypedReference $reference)
359344
$message = sprintf('one of these existing services: "%s"', implode('", "', $this->ambiguousServiceTypes[$type]));
360345
} elseif (isset($this->types[$type])) {
361346
$message = sprintf('the existing "%s" service', $this->types[$type]);
362-
} elseif ($reference->getRequiringClass() && !$reference->canBeAutoregistered()) {
363-
return ' It cannot be auto-registered because it is from a different root namespace.';
364347
} else {
365348
return;
366349
}

Tests/Compiler/AutowirePassTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ public function provideNotWireableCalls()
697697
{
698698
return array(
699699
array('setNotAutowireable', 'Cannot autowire service "foo": argument "$n" of method "Symfony\Component\DependencyInjection\Tests\Compiler\NotWireable::setNotAutowireable()" has type "Symfony\Component\DependencyInjection\Tests\Compiler\NotARealClass" but this class was not found.'),
700-
array('setDifferentNamespace', 'Cannot autowire service "foo": argument "$n" of method "Symfony\Component\DependencyInjection\Tests\Compiler\NotWireable::setDifferentNamespace()" references class "stdClass" but no such service exists. It cannot be auto-registered because it is from a different root namespace.'),
700+
array('setDifferentNamespace', 'Cannot autowire service "foo": argument "$n" of method "Symfony\Component\DependencyInjection\Tests\Compiler\NotWireable::setDifferentNamespace()" references class "stdClass" but no such service exists.'),
701701
array(null, 'Invalid service "foo": method "Symfony\Component\DependencyInjection\Tests\Compiler\NotWireable::setProtectedMethod()" must be public.'),
702702
);
703703
}

0 commit comments

Comments
 (0)