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

Skip to content

Commit bcfd2d5

Browse files
committed
Move ControllerArgumentValueResolverPass to the HttpKernel component
1 parent 50b9126 commit bcfd2d5

File tree

9 files changed

+136
-18
lines changed

9 files changed

+136
-18
lines changed

UPGRADE-3.3.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ FrameworkBundle
148148

149149
* Extending `ConstraintValidatorFactory` is deprecated and won't be supported in 4.0.
150150

151+
* The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ControllerArgumentValueResolverPass` class
152+
has been removed. Use the `Symfony\Component\HttpKernel\DependencyInjection\ControllerArgumentValueResolverPass`
153+
class instead.
154+
151155
HttpKernel
152156
-----------
153157

UPGRADE-4.0.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,10 @@ FrameworkBundle
207207

208208
* Extending `ConstraintValidatorFactory` is not supported anymore.
209209

210+
* The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ControllerArgumentValueResolverPass` class
211+
has been removed. Use the `Symfony\Component\HttpKernel\DependencyInjection\ControllerArgumentValueResolverPass`
212+
class instead.
213+
210214
HttpFoundation
211215
---------------
212216

src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ CHANGELOG
2727
`render()`, `renderView()` and `stream()` methods can only use Twig (using the Templating component is not supported).
2828
The `json()` method requires the Serializer component (use `Symfony\Component\HttpFoundation\JsonResponse` directly if
2929
you do not want to use the Serializer).
30+
* Deprecated `ControllerArgumentValueResolverPass`. Use
31+
`Symfony\Component\HttpKernel\DependencyInjection\ControllerArgumentValueResolverPass` instead
3032

3133
3.2.0
3234
-----

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

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,17 @@
1111

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

14-
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
15-
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
16-
use Symfony\Component\DependencyInjection\Compiler\PriorityTaggedServiceTrait;
17-
use Symfony\Component\DependencyInjection\ContainerBuilder;
14+
@trigger_error(sprintf('The %s class is deprecated since version 3.3 and will be removed in 4.0. Use Symfony\Component\HttpKernel\DependencyInjection\ControllerArgumentValueResolverPass instead.', ControllerArgumentValueResolverPass::class), E_USER_DEPRECATED);
15+
16+
use Symfony\Component\HttpKernel\DependencyInjection\ControllerArgumentValueResolverPass as BaseControllerArgumentValueResolverPass;
1817

1918
/**
2019
* Gathers and configures the argument value resolvers.
2120
*
2221
* @author Iltar van der Berg <[email protected]>
22+
*
23+
* @deprecated since version 3.3, to be removed in 4.0. Use {@link BaseControllerArgumentValueResolverPass}
2324
*/
24-
class ControllerArgumentValueResolverPass implements CompilerPassInterface
25+
class ControllerArgumentValueResolverPass extends BaseControllerArgumentValueResolverPass
2526
{
26-
use PriorityTaggedServiceTrait;
27-
28-
public function process(ContainerBuilder $container)
29-
{
30-
if (!$container->hasDefinition('argument_resolver')) {
31-
return;
32-
}
33-
34-
$definition = $container->getDefinition('argument_resolver');
35-
$argumentResolvers = $this->findAndSortTaggedServices('controller.argument_value_resolver', $container);
36-
$definition->replaceArgument(1, new IteratorArgument($argumentResolvers));
37-
}
3827
}

src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\CacheCollectorPass;
1919
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\CachePoolPass;
2020
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\CachePoolClearerPass;
21-
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ControllerArgumentValueResolverPass;
2221
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\DataCollectorTranslatorPass;
2322
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TemplatingPass;
2423
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\RoutingResolverPass;
@@ -36,6 +35,7 @@
3635
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ValidateWorkflowsPass;
3736
use Symfony\Component\Config\DependencyInjection\ConfigCachePass;
3837
use Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass;
38+
use Symfony\Component\HttpKernel\DependencyInjection\ControllerArgumentValueResolverPass;
3939
use Symfony\Component\PropertyInfo\DependencyInjection\PropertyInfoPass;
4040
use Symfony\Component\Serializer\DependencyInjection\SerializerPass;
4141
use Symfony\Component\Debug\ErrorHandler;

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
use Symfony\Component\DependencyInjection\Reference;
1919
use Symfony\Component\HttpKernel\Controller\ArgumentResolver;
2020

21+
/**
22+
* @group legacy
23+
*/
2124
class ControllerArgumentValueResolverPassTest extends TestCase
2225
{
2326
public function testServicesAreOrderedAccordingToPriority()

src/Symfony/Component/HttpKernel/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ CHANGELOG
1313

1414
* deprecated `DataCollector::varToString()`, use `cloneVar()` instead
1515
* changed surrogate capability name in `AbstractSurrogate::addSurrogateCapability` to 'symfony'
16+
* Added `ControllerArgumentValueResolverPass`
1617

1718
3.1.0
1819
-----
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\HttpKernel\DependencyInjection;
13+
14+
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
15+
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
16+
use Symfony\Component\DependencyInjection\Compiler\PriorityTaggedServiceTrait;
17+
use Symfony\Component\DependencyInjection\ContainerBuilder;
18+
19+
/**
20+
* Gathers and configures the argument value resolvers.
21+
*
22+
* @author Iltar van der Berg <[email protected]>
23+
*/
24+
class ControllerArgumentValueResolverPass implements CompilerPassInterface
25+
{
26+
use PriorityTaggedServiceTrait;
27+
28+
private $argumentResolverService;
29+
private $argumentValueResolverTag;
30+
31+
public function __construct($argumentResolverService = 'argument_resolver', $argumentValueResolverTag = 'controller.argument_value_resolver')
32+
{
33+
$this->argumentResolverService = $argumentResolverService;
34+
$this->argumentValueResolverTag = $argumentValueResolverTag;
35+
}
36+
37+
public function process(ContainerBuilder $container)
38+
{
39+
if (!$container->hasDefinition($this->argumentResolverService)) {
40+
return;
41+
}
42+
43+
$container
44+
->getDefinition($this->argumentResolverService)
45+
->replaceArgument(1, new IteratorArgument($this->findAndSortTaggedServices($this->argumentValueResolverTag, $container)))
46+
;
47+
}
48+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\HttpKernel\Tests\DependencyInjection;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\DependencyInjection\ContainerBuilder;
16+
use Symfony\Component\DependencyInjection\Definition;
17+
use Symfony\Component\DependencyInjection\Reference;
18+
use Symfony\Component\HttpKernel\Controller\ArgumentResolver;
19+
use Symfony\Component\HttpKernel\DependencyInjection\ControllerArgumentValueResolverPass;
20+
21+
class ControllerArgumentValueResolverPassTest extends TestCase
22+
{
23+
public function testServicesAreOrderedAccordingToPriority()
24+
{
25+
$services = array(
26+
'n3' => array(array()),
27+
'n1' => array(array('priority' => 200)),
28+
'n2' => array(array('priority' => 100)),
29+
);
30+
31+
$expected = array(
32+
new Reference('n1'),
33+
new Reference('n2'),
34+
new Reference('n3'),
35+
);
36+
37+
$definition = new Definition(ArgumentResolver::class, array(null, array()));
38+
$container = new ContainerBuilder();
39+
$container->setDefinition('argument_resolver', $definition);
40+
41+
foreach ($services as $id => list($tag)) {
42+
$container->register($id)->addTag('controller.argument_value_resolver', $tag);
43+
}
44+
45+
(new ControllerArgumentValueResolverPass())->process($container);
46+
$this->assertEquals($expected, $definition->getArgument(1)->getValues());
47+
}
48+
49+
public function testReturningEmptyArrayWhenNoService()
50+
{
51+
$definition = new Definition(ArgumentResolver::class, array(null, array()));
52+
$container = new ContainerBuilder();
53+
$container->setDefinition('argument_resolver', $definition);
54+
55+
(new ControllerArgumentValueResolverPass())->process($container);
56+
$this->assertEquals(array(), $definition->getArgument(1)->getValues());
57+
}
58+
59+
public function testNoArgumentResolver()
60+
{
61+
$container = new ContainerBuilder();
62+
63+
(new ControllerArgumentValueResolverPass())->process($container);
64+
65+
$this->assertFalse($container->hasDefinition('argument_resolver'));
66+
}
67+
}

0 commit comments

Comments
 (0)