[DI] Fix tracking of bound arguments when using autoconfiguration

This commit is contained in:
Nicolas Grekas 2017-09-24 19:51:14 +02:00
parent f617882ba7
commit 091f943900
3 changed files with 9 additions and 6 deletions

View File

@ -90,9 +90,11 @@ class ResolveInstanceofConditionalsPass implements CompilerPassInterface
}
if ($parent) {
$bindings = $definition->getBindings();
$abstract = $container->setDefinition('abstract.instanceof.'.$id, $definition);
// cast Definition to ChildDefinition
$definition->setBindings(array());
$definition = serialize($definition);
$definition = substr_replace($definition, '53', 2, 2);
$definition = substr_replace($definition, 'Child', 44, 0);
@ -117,6 +119,7 @@ class ResolveInstanceofConditionalsPass implements CompilerPassInterface
// reset fields with "merge" behavior
$abstract
->setBindings($bindings)
->setArguments(array())
->setMethodCalls(array())
->setTags(array())

View File

@ -38,6 +38,8 @@ trait ParentTrait
$this->definition->setParent($parent);
} elseif ($this->definition->isAutoconfigured()) {
throw new InvalidArgumentException(sprintf('The service "%s" cannot have a "parent" and also have "autoconfigure". Try disabling autoconfiguration for the service.', $this->id));
} elseif ($this->definition->getBindings()) {
throw new InvalidArgumentException(sprintf('The service "%s" cannot have a "parent" and also "bind" arguments.', $this->id));
} else {
// cast Definition to ChildDefinition
$definition = serialize($this->definition);

View File

@ -14,7 +14,6 @@ namespace Symfony\Component\HttpKernel\DependencyInjection;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\DependencyInjection\ChildDefinition;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\Compiler\ResolveBindingsPass;
use Symfony\Component\DependencyInjection\Compiler\ServiceLocatorTagPass;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
@ -54,11 +53,13 @@ class RegisterControllerArgumentLocatorsPass implements CompilerPassInterface
$def->setPublic(true);
$class = $def->getClass();
$autowire = $def->isAutowired();
$bindings = $def->getBindings();
// resolve service class, taking parent definitions into account
while (!$class && $def instanceof ChildDefinition) {
while ($def instanceof ChildDefinition) {
$def = $container->findDefinition($def->getParent());
$class = $def->getClass();
$class = $class ?: $def->getClass();
$bindings = $def->getBindings();
}
$class = $parameterBag->resolveValue($class);
@ -111,9 +112,6 @@ class RegisterControllerArgumentLocatorsPass implements CompilerPassInterface
}
}
// not validated, they are later in ResolveBindingsPass
$bindings = $def->getBindings();
foreach ($methods as list($r, $parameters)) {
/** @var \ReflectionMethod $r */