Skip to content

Commit

Permalink
feature #21516 [HttpKernel][FrameworkBundle] Lazy load argument value…
Browse files Browse the repository at this point in the history
… 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
fabpot committed Feb 2, 2017
2 parents b50efa5 + 02b4aaa commit 2e13d4e
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
Expand Up @@ -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;
Expand All @@ -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));
}
}
Expand Up @@ -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">
Expand Down
Expand Up @@ -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()
Expand All @@ -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()
Expand Down
Expand Up @@ -29,11 +29,11 @@ final class ArgumentResolver implements ArgumentResolverInterface
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();
Expand Down

0 comments on commit 2e13d4e

Please sign in to comment.