8000 bug #52604 [FrameworkBundle] register the virtual request stack toget… · symfony/symfony@80db691 · GitHub
[go: up one dir, main page]

Skip to content

Commit 80db691

Browse files
committed
bug #52604 [FrameworkBundle] register the virtual request stack together with common profiling services (xabbuh)
This PR was merged into the 6.4 branch. Discussion ---------- [FrameworkBundle] register the virtual request stack together with common profiling services | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix #52280 (comment) | License | MIT The debug.php file is never loaded when the Stopwatch component is not installed. However, the virtual request stack is always valuable as soon as the profiling feature is enabled. Commits ------- bf6186f register the virtual request stack together with common profiling services
2 parents 6f63e25 + bf6186f commit 80db691

File tree

5 files changed

+47
-5
lines changed

5 files changed

+47
-5
lines changed

src/Symfony/Bundle/FrameworkBundle/Console/Application.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@ protected function doRunCommand(Command $command, InputInterface $input, OutputI
108108
}
109109

110110
(new SymfonyStyle($input, $output))->warning('The "--profile" option needs the Stopwatch component. Try running "composer require symfony/stopwatch".');
111+
} elseif (!$container->has('.virtual_request_stack')) {
112+
if ($output instanceof ConsoleOutputInterface) {
113+
$output = $output->getErrorOutput();
114+
}
115+
116+
(new SymfonyStyle($input, $output))->warning('The "--profile" option needs the profiler integration. Try enabling the "framework.profiler" option.');
111117
} else {
112118
$command = new TraceableCommand($command, $container->get('debug.stopwatch'));
113119

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
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\Bundle\FrameworkBundle\DependencyInjection;
13+
14+
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
15+
use Symfony\Component\DependencyInjection\ContainerBuilder;
16+
use Symfony\Component\DependencyInjection\Reference;
17+
18+
class VirtualRequestStackPass implements CompilerPassInterface
19+
{
20+
public function process(ContainerBuilder $container): void
21+
{
22+
if ($container->has('.virtual_request_stack')) {
23+
return;
24+
}
25+
26+
if ($container->hasDefinition('debug.event_dispatcher')) {
27+
$container->getDefinition('debug.event_dispatcher')->replaceArgument(3, new Reference('request_stack', ContainerBuilder::NULL_ON_INVALID_REFERENCE));
28+
}
29+
30+
if ($container->hasDefinition('debug.log_processor')) {
31+
$container->getDefinition('debug.log_processor')->replaceArgument(0, new Reference('request_stack'));
32+
}
33+
}
34+
}

src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TestServiceContainerRealRefPass;
2222
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TestServiceContainerWeakRefPass;
2323
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\UnusedTagsPass;
24+
use Symfony\Bundle\FrameworkBundle\DependencyInjection\VirtualRequestStackPass;
2425
use Symfony\Component\Cache\Adapter\ApcuAdapter;
2526
use Symfony\Component\Cache\Adapter\ArrayAdapter;
2627
use Symfony\Component\Cache\Adapter\ChainAdapter;
@@ -184,6 +185,7 @@ public function build(ContainerBuilder $container)
184185
$container->addCompilerPass(new RemoveUnusedSessionMarshallingHandlerPass());
185186
// must be registered after MonologBundle's LoggerChannelPass
186187
$container->addCompilerPass(new ErrorLoggerCompilerPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, -32);
188+
$container->addCompilerPass(new VirtualRequestStackPass());
187189

188190
if ($container->getParameter('kernel.debug')) {
189191
$container->addCompilerPass(new AddDebugLogProcessorPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, 2);

src/Symfony/Bundle/FrameworkBundle/Resources/config/debug.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use Symfony\Component\HttpKernel\Controller\TraceableArgumentResolver;
1616
use Symfony\Component\HttpKernel\Controller\TraceableControllerResolver;
1717
use Symfony\Component\HttpKernel\Debug\TraceableEventDispatcher;
18-
use Symfony\Component\HttpKernel\Debug\VirtualRequestStack;
1918

2019
return static function (ContainerConfigurator $container) {
2120
$container->services()
@@ -47,9 +46,5 @@
4746
->set('argument_resolver.not_tagged_controller', NotTaggedControllerValueResolver::class)
4847
->args([abstract_arg('Controller argument, set in FrameworkExtension')])
4948
->tag('controller.argument_value_resolver', ['priority' => -200])
50-
51-
->set('.virtual_request_stack', VirtualRequestStack::class)
52-
->args([service('request_stack')])
53-
->public()
5449
;
5550
};

src/Symfony/Bundle/FrameworkBundle/Resources/config/profiling.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
1313

1414
use Symfony\Bundle\FrameworkBundle\EventListener\ConsoleProfilerListener;
15+
use Symfony\Component\HttpKernel\Debug\VirtualRequestStack;
1516
use Symfony\Component\HttpKernel\EventListener\ProfilerListener;
1617
use Symfony\Component\HttpKernel\Profiler\FileProfilerStorage;
1718
use Symfony\Component\HttpKernel\Profiler\Profiler;
@@ -45,5 +46,9 @@
4546
service('router'),
4647
])
4748
->tag('kernel.event_subscriber')
49+
50+
->set('.virtual_request_stack', VirtualRequestStack::class)
51+
->args([service('request_stack')])
52+
->public()
4853
;
4954
};

0 commit comments

Comments
 (0)
0