8000 [HttpKernel] Make TraceableValueResolver $stopwatch mandatory by ogizanagi · Pull Request #27252 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[HttpKernel] Make TraceableValueResolver $stopwatch mandatory #27252

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ final class TraceableValueResolver implements ArgumentValueResolverInterface
private $inner;
private $stopwatch;

public function __construct(ArgumentValueResolverInterface $inner, ?Stopwatch $stopwatch = null)
public function __construct(ArgumentValueResolverInterface $inner, Stopwatch $stopwatch)
{
$this->inner = $inner;
$this->stopwatch = $stopwatch ?? new Stopwatch();
$this->stopwatch = $stopwatch;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\Compiler\PriorityTaggedServiceTrait;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\HttpKernel\Controller\ArgumentResolver\TraceableValueResolver;
use Symfony\Component\Stopwatch\Stopwatch;
Expand All @@ -31,11 +30,13 @@ class ControllerArgumentValueResolverPass implements CompilerPassInterface

private $argumentResolverService;
private $argumentValueResolverTag;
private $traceableResolverStopwatch;

public function __construct(string $argumentResolverService = 'argument_resolver', string $argumentValueResolverTag = 'controller.argument_value_resolver')
public function __construct(string $argumentResolverService = 'argument_resolver', string $argumentValueResolverTag = 'controller.argument_value_resolver', string $traceableResolverStopwatch = 'debug.stopwatch')
{
$this->argumentResolverService = $argumentResolverService;
$this->argumentValueResolverTag = $argumentValueResolverTag;
$this->traceableResolverStopwatch = $traceableResolverStopwatch;
}

public function process(ContainerBuilder $container)
Expand All @@ -46,12 +47,12 @@ public function process(ContainerBuilder $container)

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

if ($container->getParameter('kernel.debug') && class_exists(Stopwatch::class)) {
if ($container->getParameter('kernel.debug') && class_exists(Stopwatch::class) && $container->has($this->traceableResolverStopwatch)) {
foreach ($resolvers as $resolverReference) {
$id = (string) $resolverReference;
$container->register("debug.$id", TraceableValueResolver::class)
->setDecoratedService($id)
->setArguments(array(new Reference("debug.$id.inner"), new Reference('debug.stopwatch', ContainerInterface::NULL_ON_INVALID_REFERENCE)));
->setArguments(array(new Reference("debug.$id.inner"), new Reference($this->traceableResolverStopwatch)));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\HttpKernel\Controller\ArgumentResolver;
use Symfony\Component\HttpKernel\DependencyInjection\ControllerArgumentValueResolverPass;
use Symfony\Component\Stopwatch\Stopwatch;

class ControllerArgumentValueResolverPassTest extends TestCase
{
Expand Down Expand Up @@ -52,7 +53,7 @@ public function testServicesAreOrderedAccordingToPriority()
$this->assertFalse($container->hasDefinition('n3.traceable'));
}

public function testInDebug()
public function testInDebugWithStopWatchDefinition()
{
$services = array(< 9EDA /span>
'n3' => array(array()),
Expand All @@ -68,6 +69,7 @@ public function testInDebug()

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

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

public function testInDebugWithouStopWatchDefinition()
{
$expected = array(new Reference('n1'));

$definition = new Definition(ArgumentResolver::class, array(null, array()));
$container = new ContainerBuilder();
$container->register('n1')->addTag('controller.argument_value_resolver');
$container->setDefinition('argument_resolver', $definition);

$container->setParameter('kernel.debug', true);

(new ControllerArgumentValueResolverPass())->process($container);
$this->assertEquals($expected, $definition->getArgument(1)->getValues());

$this->assertFalse($container->hasDefinition('debug.n1'));
$this->assertTrue($container->hasDefinition('n1'));
}

public function testReturningEmptyArrayWhenNoService()
{
$definition = new Definition(ArgumentResolver::class, array(null, array()));
Expand Down
0