Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 906a05c

Browse filesBrowse files
committed
minor #27252 [HttpKernel] Make TraceableValueResolver $stopwatch mandatory (ogizanagi)
This PR was merged into the 4.1 branch. Discussion ---------- [HttpKernel] Make TraceableValueResolver $stopwatch mandatory | Q | A | ------------- | --- | Branch? | 4.1 <!-- see below --> | Bug fix? | no | New feature? | no <!-- don't forget to update src/**/CHANGELOG.md files --> | BC breaks? | no <!-- see https://symfony.com/bc --> | Deprecations? | no <!-- don't forget to update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets | #26833 (comment) <!-- #-prefixed issue number(s), if any --> | License | MIT | Doc PR | N/A I understand why this was suggested in #26833 (comment), but as stated by @iltar , I don't think it makes sense to register a traceable resolver instantiating a Stopwatch itself, as there is no way to fetch it and wouldn't be a shared instance, probably defeating the feature and registering a useless decorator. Instead, let's make the stopwatch mandatory and make the service id to use in the pass configurable. Commits ------- 585ae7c [HttpKernel] Make TraceableValueResolver $stopwatch mandatory
2 parents 8335537 + 585ae7c commit 906a05c
Copy full SHA for 906a05c

File tree

3 files changed

+28
-7
lines changed
Filter options

3 files changed

+28
-7
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/Controller/ArgumentResolver/TraceableValueResolver.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ final class TraceableValueResolver implements ArgumentValueResolverInterface
2626
private $inner;
2727
private $stopwatch;
2828

29-
public function __construct(ArgumentValueResolverInterface $inner, ?Stopwatch $stopwatch = null)
29+
public function __construct(ArgumentValueResolverInterface $inner, Stopwatch $stopwatch)
3030
{
3131
$this->inner = $inner;
32-
$this->stopwatch = $stopwatch ?? new Stopwatch();
32+
$this->stopwatch = $stopwatch;
3333
}
3434

3535
/**

‎src/Symfony/Component/HttpKernel/DependencyInjection/ControllerArgumentValueResolverPass.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/DependencyInjection/ControllerArgumentValueResolverPass.php
+5-4Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
1616
use Symfony\Component\DependencyInjection\Compiler\PriorityTaggedServiceTrait;
1717
use Symfony\Component\DependencyInjection\ContainerBuilder;
18-
use Symfony\Component\DependencyInjection\ContainerInterface;
1918
use Symfony\Component\DependencyInjection\Reference;
2019
use Symfony\Component\HttpKernel\Controller\ArgumentResolver\TraceableValueResolver;
2120
use Symfony\Component\Stopwatch\Stopwatch;
@@ -31,11 +30,13 @@ class ControllerArgumentValueResolverPass implements CompilerPassInterface
3130

3231
private $argumentResolverService;
3332
private $argumentValueResolverTag;
33+
private $traceableResolverStopwatch;
3434

35-
public function __construct(string $argumentResolverService = 'argument_resolver', string $argumentValueResolverTag = 'controller.argument_value_resolver')
35+
public function __construct(string $argumentResolverService = 'argument_resolver', string $argumentValueResolverTag = 'controller.argument_value_resolver', string $traceableResolverStopwatch = 'debug.stopwatch')
3636
{
3737
$this->argumentResolverService = $argumentResolverService;
3838
$this->argumentValueResolverTag = $argumentValueResolverTag;
39+
$this->traceableResolverStopwatch = $traceableResolverStopwatch;
3940
}
4041

4142
public function process(ContainerBuilder $container)
@@ -46,12 +47,12 @@ public function process(ContainerBuilder $container)
4647

4748
$resolvers = $this->findAndSortTaggedServices($this->argumentValueResolverTag, $container);
4849

49-
if ($container->getParameter('kernel.debug') && class_exists(Stopwatch::class)) {
50+
if ($container->getParameter('kernel.debug') && class_exists(Stopwatch::class) && $container->has($this->traceableResolverStopwatch)) {
5051
foreach ($resolvers as $resolverReference) {
5152
$id = (string) $resolverReference;
5253
$container->register("debug.$id", TraceableValueResolver::class)
5354
->setDecoratedService($id)
54-
->setArguments(array(new Reference("debug.$id.inner"), new Reference('debug.stopwatch', ContainerInterface::NULL_ON_INVALID_REFERENCE)));
55+
->setArguments(array(new Reference("debug.$id.inner"), new Reference($this->traceableResolverStopwatch)));
5556
}
5657
}
5758

‎src/Symfony/Component/HttpKernel/Tests/DependencyInjection/ControllerArgumentValueResolverPassTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/Tests/DependencyInjection/ControllerArgumentValueResolverPassTest.php
+21-1Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Symfony\Component\DependencyInjection\Reference;
1818
use Symfony\Component\HttpKernel\Controller\ArgumentResolver;
1919
use Symfony\Component\HttpKernel\DependencyInjection\ControllerArgumentValueResolverPass;
20+
use Symfony\Component\Stopwatch\Stopwatch;
2021

2122
class ControllerArgumentValueResolverPassTest extends TestCase
2223
{
@@ -52,7 +53,7 @@ public function testServicesAreOrderedAccordingToPriority()
5253
$this->assertFalse($container->hasDefinition('n3.traceable'));
5354
}
5455

55-
public function testInDebug()
56+
public function testInDebugWithStopWatchDefinition()
5657
{
5758
$services = array(
5859
'n3' => array(array()),
@@ -68,6 +69,7 @@ public function testInDebug()
6869

6970
$definition = new Definition(ArgumentResolver::class, array(null, array()));
7071
$container = new ContainerBuilder();
72+
$container->register('debug.stopwatch', Stopwatch::class);
7173
$container->setDefinition('argument_resolver', $definition);
7274

7375
foreach ($services as $id => list($tag)) {
@@ -88,6 +90,24 @@ public function testInDebug()
8890
$this->assertTrue($container->hasDefinition('n3'));
8991
}
9092

93+
public function testInDebugWithouStopWatchDefinition()
94+
{
95+
$expected = array(new Reference('n1'));
96+
97+
$definition = new Definition(ArgumentResolver::class, array(null, array()));
98+
$container = new ContainerBuilder();
99+
$container->register('n1')->addTag('controller.argument_value_resolver');
100+
$container->setDefinition('argument_resolver', $definition);
101+
102+
$container->setParameter('kernel.debug', true);
103+
104+
(new ControllerArgumentValueResolverPass())->process($container);
105+
$this->assertEquals($expected, $definition->getArgument(1)->getValues());
106+
107+
$this->assertFalse($container->hasDefinition('debug.n1'));
108+
$this->assertTrue($container->hasDefinition('n1'));
109+
}
110+
91111
public function testReturningEmptyArrayWhenNoService()
92112
{
93113
$definition = new Definition(ArgumentResolver::class, array(null, array()));

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.