[DI] Cleanup remainings from autoregistration
This commit is contained in:
parent
1f119cc16c
commit
74afff8888
@ -29,7 +29,6 @@ class AutowirePass extends AbstractRecursivePass
|
|||||||
{
|
{
|
||||||
private $types;
|
private $types;
|
||||||
private $ambiguousServiceTypes = array();
|
private $ambiguousServiceTypes = array();
|
||||||
private $autowired = array();
|
|
||||||
private $lastFailure;
|
private $lastFailure;
|
||||||
private $throwOnAutowiringException;
|
private $throwOnAutowiringException;
|
||||||
|
|
||||||
@ -48,7 +47,6 @@ class AutowirePass extends AbstractRecursivePass
|
|||||||
} finally {
|
} finally {
|
||||||
$this->types = null;
|
$this->types = null;
|
||||||
$this->ambiguousServiceTypes = array();
|
$this->ambiguousServiceTypes = array();
|
||||||
$this->autowired = array();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,7 +71,7 @@ class AutowirePass extends AbstractRecursivePass
|
|||||||
private function doProcessValue($value, $isRoot = false)
|
private function doProcessValue($value, $isRoot = false)
|
||||||
{
|
{
|
||||||
if ($value instanceof TypedReference) {
|
if ($value instanceof TypedReference) {
|
||||||
if ($ref = $this->getAutowiredReference($value, $value->getRequiringClass() ? sprintf('for "%s" in "%s"', $value->getType(), $value->getRequiringClass()) : '')) {
|
if ($ref = $this->getAutowiredReference($value)) {
|
||||||
return $ref;
|
return $ref;
|
||||||
}
|
}
|
||||||
$this->container->log($this, $this->createTypeNotFoundMessage($value, 'it'));
|
$this->container->log($this, $this->createTypeNotFoundMessage($value, 'it'));
|
||||||
@ -190,7 +188,7 @@ class AutowirePass extends AbstractRecursivePass
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$value = $this->getAutowiredReference($ref = new TypedReference($type, $type, !$parameter->isOptional() ? $class : ''), 'for '.sprintf('argument "$%s" of method "%s()"', $parameter->name, $class.'::'.$method))) {
|
if (!$value = $this->getAutowiredReference($ref = new TypedReference($type, $type, !$parameter->isOptional() ? $class : ''))) {
|
||||||
$failureMessage = $this->createTypeNotFoundMessage($ref, sprintf('argument "$%s" of method "%s()"', $parameter->name, $class !== $this->currentId ? $class.'::'.$method : $method));
|
$failureMessage = $this->createTypeNotFoundMessage($ref, sprintf('argument "$%s" of method "%s()"', $parameter->name, $class !== $this->currentId ? $class.'::'.$method : $method));
|
||||||
|
|
||||||
if ($parameter->isDefaultValueAvailable()) {
|
if ($parameter->isDefaultValueAvailable()) {
|
||||||
@ -224,7 +222,7 @@ class AutowirePass extends AbstractRecursivePass
|
|||||||
/**
|
/**
|
||||||
* @return TypedReference|null A reference to the service matching the given type, if any
|
* @return TypedReference|null A reference to the service matching the given type, if any
|
||||||
*/
|
*/
|
||||||
private function getAutowiredReference(TypedReference $reference, $deprecationMessage)
|
private function getAutowiredReference(TypedReference $reference)
|
||||||
{
|
{
|
||||||
$this->lastFailure = null;
|
$this->lastFailure = null;
|
||||||
$type = $reference->getType();
|
$type = $reference->getType();
|
||||||
@ -232,22 +230,6 @@ class AutowirePass extends AbstractRecursivePass
|
|||||||
if ($type !== (string) $reference || ($this->container->has($type) && !$this->container->findDefinition($type)->isAbstract())) {
|
if ($type !== (string) $reference || ($this->container->has($type) && !$this->container->findDefinition($type)->isAbstract())) {
|
||||||
return $reference;
|
return $reference;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$reference->canBeAutoregistered()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (null === $this->types) {
|
|
||||||
$this->populateAvailableTypes();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($this->types[$type]) || isset($this->ambiguousServiceTypes[$type])) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($this->autowired[$type])) {
|
|
||||||
return $this->autowired[$type] ? new TypedReference($this->autowired[$type], $type) : null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -351,6 +333,9 @@ class AutowirePass extends AbstractRecursivePass
|
|||||||
if ($message = $this->getAliasesSuggestionForType($type = $reference->getType())) {
|
if ($message = $this->getAliasesSuggestionForType($type = $reference->getType())) {
|
||||||
return ' '.$message;
|
return ' '.$message;
|
||||||
}
|
}
|
||||||
|
if (null === $this->types) {
|
||||||
|
$this->populateAvailableTypes();
|
||||||
|
}
|
||||||
|
|
||||||
$servicesAndAliases = $this->container->getServiceIds();
|
$servicesAndAliases = $this->container->getServiceIds();
|
||||||
if (!$this->container->has($type) && false !== $key = array_search(strtolower($type), array_map('strtolower', $servicesAndAliases))) {
|
if (!$this->container->has($type) && false !== $key = array_search(strtolower($type), array_map('strtolower', $servicesAndAliases))) {
|
||||||
@ -359,8 +344,6 @@ class AutowirePass extends AbstractRecursivePass
|
|||||||
$message = sprintf('one of these existing services: "%s"', implode('", "', $this->ambiguousServiceTypes[$type]));
|
$message = sprintf('one of these existing services: "%s"', implode('", "', $this->ambiguousServiceTypes[$type]));
|
||||||
} elseif (isset($this->types[$type])) {
|
} elseif (isset($this->types[$type])) {
|
||||||
$message = sprintf('the existing "%s" service', $this->types[$type]);
|
$message = sprintf('the existing "%s" service', $this->types[$type]);
|
||||||
} elseif ($reference->getRequiringClass() && !$reference->canBeAutoregistered()) {
|
|
||||||
return ' It cannot be auto-registered because it is from a different root namespace.';
|
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -697,7 +697,7 @@ class AutowirePassTest extends TestCase
|
|||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
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.'),
|
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.'),
|
||||||
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.'),
|
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.'),
|
||||||
array(null, 'Invalid service "foo": method "Symfony\Component\DependencyInjection\Tests\Compiler\NotWireable::setProtectedMethod()" must be public.'),
|
array(null, 'Invalid service "foo": method "Symfony\Component\DependencyInjection\Tests\Compiler\NotWireable::setProtectedMethod()" must be public.'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user