Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2e13d4e

Browse files
committed
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
2 parents b50efa5 + 02b4aaa commit 2e13d4e

File tree

4 files changed

+7
-6
lines changed

4 files changed

+7
-6
lines changed

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/ControllerArgumentValueResolverPass.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler;
1313

14+
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
1415
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
1516
use Symfony\Component\DependencyInjection\Compiler\PriorityTaggedServiceTrait;
1617
use Symfony\Component\DependencyInjection\ContainerBuilder;
@@ -32,6 +33,6 @@ public function process(ContainerBuilder $container)
3233

3334
$definition = $container->getDefinition('argument_resolver');
3435
$argumentResolvers = $this->findAndSortTaggedServices('controller.argument_value_resolver', $container);
35-
$definition->replaceArgument(1, $argumentResolvers);
36+
$definition->replaceArgument(1, new IteratorArgument($argumentResolvers));
3637
}
3738
}

src/Symfony/Bundle/FrameworkBundle/Resources/config/web.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
<service id="argument_resolver" class="Symfony\Component\HttpKernel\Controller\ArgumentResolver" public="false">
2323
<argument type="service" id="argument_metadata_factory" />
24-
<argument type="collection" />
24+
<argument /> <!-- argument value resolvers -->
2525
</service>
2626

2727
<service id="argument_resolver.request_attribute" class="Symfony\Component\HttpKernel\Controller\ArgumentResolver\RequestAttributeValueResolver" public="false">

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/ControllerArgumentValueResolverPassTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function testServicesAreOrderedAccordingToPriority()
4242
}
4343

4444
(new ControllerArgumentValueResolverPass())->process($container);
45-
$this->assertEquals($expected, $definition->getArgument(1));
45+
$this->assertEquals($expected, $definition->getArgument(1)->getValues());
4646
}
4747

4848
public function testReturningEmptyArrayWhenNoService()
@@ -52,7 +52,7 @@ public function testReturningEmptyArrayWhenNoService()
5252
$container->setDefinition('argument_resolver', $definition);
5353

5454
(new ControllerArgumentValueResolverPass())->process($container);
55-
$this->assertEquals(array(), $definition->getArgument(1));
55+
$this->assertEquals(array(), $definition->getArgument(1)->getValues());
5656
}
5757

5858
public function testNoArgumentResolver()

src/Symfony/Component/HttpKernel/Controller/ArgumentResolver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ final class ArgumentResolver implements ArgumentResolverInterface
2929
private $argumentMetadataFactory;
3030

3131
/**
32-
* @var ArgumentValueResolverInterface[]
32+
* @var iterable|ArgumentValueResolverInterface[]
3333
*/
3434
private $argumentValueResolvers;
3535

36-
public function __construct(ArgumentMetadataFactoryInterface $argumentMetadataFactory = null, array $argumentValueResolvers = array())
36+
public function __construct(ArgumentMetadataFactoryInterface $argumentMetadataFactory = null, $argumentValueResolvers = array())
3737
{
3838
$this->argumentMetadataFactory = $argumentMetadataFactory ?: new ArgumentMetadataFactory();
3939
$this->argumentValueResolvers = $argumentValueResolvers ?: self::getDefaultArgumentValueResolvers();

0 commit comments

Comments
 (0)