Merge branch '3.4' into 4.2
* 3.4: [WIP] [DependencyInjection] Fix a wrong error when using a factory and a call
This commit is contained in:
commit
dc65401f66
@ -159,7 +159,15 @@ class AutowirePass extends AbstractRecursivePass
|
|||||||
if ($method instanceof \ReflectionFunctionAbstract) {
|
if ($method instanceof \ReflectionFunctionAbstract) {
|
||||||
$reflectionMethod = $method;
|
$reflectionMethod = $method;
|
||||||
} else {
|
} else {
|
||||||
$reflectionMethod = $this->getReflectionMethod(new Definition($reflectionClass->name), $method);
|
$definition = new Definition($reflectionClass->name);
|
||||||
|
try {
|
||||||
|
$reflectionMethod = $this->getReflectionMethod($definition, $method);
|
||||||
|
} catch (RuntimeException $e) {
|
||||||
|
if ($definition->getFactory()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$arguments = $this->autowireMethod($reflectionMethod, $arguments);
|
$arguments = $this->autowireMethod($reflectionMethod, $arguments);
|
||||||
|
@ -115,7 +115,14 @@ class ResolveBindingsPass extends AbstractRecursivePass
|
|||||||
if ($method instanceof \ReflectionFunctionAbstract) {
|
if ($method instanceof \ReflectionFunctionAbstract) {
|
||||||
$reflectionMethod = $method;
|
$reflectionMethod = $method;
|
||||||
} else {
|
} else {
|
||||||
$reflectionMethod = $this->getReflectionMethod($value, $method);
|
try {
|
||||||
|
$reflectionMethod = $this->getReflectionMethod($value, $method);
|
||||||
|
} catch (RuntimeException $e) {
|
||||||
|
if ($value->getFactory()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($reflectionMethod->getParameters() as $key => $parameter) {
|
foreach ($reflectionMethod->getParameters() as $key => $parameter) {
|
||||||
|
@ -27,6 +27,7 @@ use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
|||||||
use Symfony\Component\DependencyInjection\Reference;
|
use Symfony\Component\DependencyInjection\Reference;
|
||||||
use Symfony\Component\DependencyInjection\Tests\Fixtures\includes\FooVariadic;
|
use Symfony\Component\DependencyInjection\Tests\Fixtures\includes\FooVariadic;
|
||||||
use Symfony\Component\DependencyInjection\TypedReference;
|
use Symfony\Component\DependencyInjection\TypedReference;
|
||||||
|
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||||
|
|
||||||
require_once __DIR__.'/../Fixtures/includes/autowiring_classes.php';
|
require_once __DIR__.'/../Fixtures/includes/autowiring_classes.php';
|
||||||
|
|
||||||
@ -546,6 +547,18 @@ class AutowirePassTest extends TestCase
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testWithNonExistingSetterAndAutowiring()
|
||||||
|
{
|
||||||
|
$container = new ContainerBuilder();
|
||||||
|
|
||||||
|
$definition = $container->register(HttpKernelInterface::class, HttpKernelInterface::class)->setAutowired(true);
|
||||||
|
$definition->addMethodCall('setLogger');
|
||||||
|
$this->expectException(RuntimeException::class);
|
||||||
|
(new ResolveClassPass())->process($container);
|
||||||
|
(new AutowireRequiredMethodsPass())->process($container);
|
||||||
|
(new AutowirePass())->process($container);
|
||||||
|
}
|
||||||
|
|
||||||
public function testExplicitMethodInjection()
|
public function testExplicitMethodInjection()
|
||||||
{
|
{
|
||||||
$container = new ContainerBuilder();
|
$container = new ContainerBuilder();
|
||||||
|
@ -16,11 +16,14 @@ use Symfony\Component\DependencyInjection\Argument\BoundArgument;
|
|||||||
use Symfony\Component\DependencyInjection\Compiler\AutowireRequiredMethodsPass;
|
use Symfony\Component\DependencyInjection\Compiler\AutowireRequiredMethodsPass;
|
||||||
use Symfony\Component\DependencyInjection\Compiler\ResolveBindingsPass;
|
use Symfony\Component\DependencyInjection\Compiler\ResolveBindingsPass;
|
||||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
|
use Symfony\Component\DependencyInjection\Definition;
|
||||||
|
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
|
||||||
use Symfony\Component\DependencyInjection\Reference;
|
use Symfony\Component\DependencyInjection\Reference;
|
||||||
use Symfony\Component\DependencyInjection\Tests\Fixtures\CaseSensitiveClass;
|
use Symfony\Component\DependencyInjection\Tests\Fixtures\CaseSensitiveClass;
|
||||||
use Symfony\Component\DependencyInjection\Tests\Fixtures\NamedArgumentsDummy;
|
use Symfony\Component\DependencyInjection\Tests\Fixtures\NamedArgumentsDummy;
|
||||||
use Symfony\Component\DependencyInjection\Tests\Fixtures\ParentNotExists;
|
use Symfony\Component\DependencyInjection\Tests\Fixtures\ParentNotExists;
|
||||||
use Symfony\Component\DependencyInjection\TypedReference;
|
use Symfony\Component\DependencyInjection\TypedReference;
|
||||||
|
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||||
|
|
||||||
require_once __DIR__.'/../Fixtures/includes/autowiring_classes.php';
|
require_once __DIR__.'/../Fixtures/includes/autowiring_classes.php';
|
||||||
|
|
||||||
@ -112,6 +115,23 @@ class ResolveBindingsPassTest extends TestCase
|
|||||||
$this->assertEquals([['setDefaultLocale', ['fr']]], $definition->getMethodCalls());
|
$this->assertEquals([['setDefaultLocale', ['fr']]], $definition->getMethodCalls());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testWithNonExistingSetterAndBinding()
|
||||||
|
{
|
||||||
|
$container = new ContainerBuilder();
|
||||||
|
|
||||||
|
$bindings = [
|
||||||
|
'$c' => (new Definition('logger'))->setFactory('logger'),
|
||||||
|
];
|
||||||
|
|
||||||
|
$definition = $container->register(HttpKernelInterface::class, HttpKernelInterface::class);
|
||||||
|
$definition->addMethodCall('setLogger');
|
||||||
|
$definition->setBindings($bindings);
|
||||||
|
$this->expectException(RuntimeException::class);
|
||||||
|
|
||||||
|
$pass = new ResolveBindingsPass();
|
||||||
|
$pass->process($container);
|
||||||
|
}
|
||||||
|
|
||||||
public function testTupleBinding()
|
public function testTupleBinding()
|
||||||
{
|
{
|
||||||
$container = new ContainerBuilder();
|
$container = new ContainerBuilder();
|
||||||
|
Reference in New Issue
Block a user