Permalink
Browse files

feature #21516 [HttpKernel][FrameworkBundle] Lazy load argument value…

… resolvers (chalasr)

This PR was merged into the 3.3-dev branch.

Discussion
----------

[HttpKernel][FrameworkBundle] Lazy load argument value resolvers

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | n/a
| License       | MIT
| Doc PR        | n/a

The ArgumentResolver resolves an arg using the first ArgumentValueResolver which `supports()` it (which can be complex, see e.g. [sensiolabs/SensioFrameworkExtraBundle#436](https://github.com/sensiolabs/SensioFrameworkExtraBundle/pull/436/files#diff-865d48d9369c4431bce36ba642834570R10)).

Commits
-------

02b4aaa [HttpKernel] Lazy load argument value resolvers
  • Loading branch information...
2 parents b50efa5 + 02b4aaa commit 2e13d4efa65545b7dffb9586be98993d3af8dd4b @fabpot fabpot committed Feb 2, 2017
@@ -11,6 +11,7 @@
namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler;
+use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\Compiler\PriorityTaggedServiceTrait;
use Symfony\Component\DependencyInjection\ContainerBuilder;
@@ -32,6 +33,6 @@ public function process(ContainerBuilder $container)
$definition = $container->getDefinition('argument_resolver');
$argumentResolvers = $this->findAndSortTaggedServices('controller.argument_value_resolver', $container);
- $definition->replaceArgument(1, $argumentResolvers);
+ $definition->replaceArgument(1, new IteratorArgument($argumentResolvers));
}
}
@@ -21,7 +21,7 @@
<service id="argument_resolver" class="Symfony\Component\HttpKernel\Controller\ArgumentResolver" public="false">
<argument type="service" id="argument_metadata_factory" />
- <argument type="collection" />
+ <argument /> <!-- argument value resolvers -->
</service>
<service id="argument_resolver.request_attribute" class="Symfony\Component\HttpKernel\Controller\ArgumentResolver\RequestAttributeValueResolver" public="false">
@@ -42,7 +42,7 @@ public function testServicesAreOrderedAccordingToPriority()
}
(new ControllerArgumentValueResolverPass())->process($container);
- $this->assertEquals($expected, $definition->getArgument(1));
+ $this->assertEquals($expected, $definition->getArgument(1)->getValues());
}
public function testReturningEmptyArrayWhenNoService()
@@ -52,7 +52,7 @@ public function testReturningEmptyArrayWhenNoService()
$container->setDefinition('argument_resolver', $definition);
(new ControllerArgumentValueResolverPass())->process($container);
- $this->assertEquals(array(), $definition->getArgument(1));
+ $this->assertEquals(array(), $definition->getArgument(1)->getValues());
}
public function testNoArgumentResolver()
@@ -29,11 +29,11 @@
private $argumentMetadataFactory;
/**
- * @var ArgumentValueResolverInterface[]
+ * @var iterable|ArgumentValueResolverInterface[]
*/
private $argumentValueResolvers;
- public function __construct(ArgumentMetadataFactoryInterface $argumentMetadataFactory = null, array $argumentValueResolvers = array())
+ public function __construct(ArgumentMetadataFactoryInterface $argumentMetadataFactory = null, $argumentValueResolvers = array())
{
$this->argumentMetadataFactory = $argumentMetadataFactory ?: new ArgumentMetadataFactory();
$this->argumentValueResolvers = $argumentValueResolvers ?: self::getDefaultArgumentValueResolvers();

0 comments on commit 2e13d4e

Please sign in to comment.