Skip to content

Commit a95816a

Browse files
committed
[TwigComponent] Disable profiler integration with configuration
Add a new configuration key allowing to disable profiler integration (enabled per default in debug mode)
1 parent 653222c commit a95816a

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/TwigComponent/src/DependencyInjection/TwigComponentExtension.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ class_exists(AbstractArgument::class) ? new AbstractArgument(sprintf('Added in %
125125
$container->setAlias('console.command.stimulus_component_debug', 'ux.twig_component.command.debug')
126126
->setDeprecated('symfony/ux-twig-component', '2.13', '%alias_id%');
127127

128-
if ($container->getParameter('kernel.debug')) {
128+
if ($container->getParameter('kernel.debug') && $config['profiler']) {
129129
$loader->load('debug.php');
130130
}
131131
}
@@ -182,6 +182,10 @@ public function getConfigTreeBuilder(): TreeBuilder
182182
->scalarNode('anonymous_template_directory')
183183
->info('Defaults to `components`')
184184
->end()
185+
->booleanNode('profiler')
186+
->info('Enables the profiler for Twig Component (in debug mode)')
187+
->defaultValue('%kernel.debug%')
188+
->end()
185189
->end();
186190

187191
return $treeBuilder;

src/TwigComponent/tests/Unit/DependencyInjection/TwigComponentExtensionTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,21 @@ public function testDataCollectorWithDebugMode()
3636
$this->assertTrue($container->hasDefinition('ux.twig_component.data_collector'));
3737
}
3838

39+
public function testDataCollectorWithDebugModeCanBeDisabled()
40+
{
41+
$container = $this->createContainer();
42+
$container->setParameter('kernel.debug', true);
43+
$container->registerExtension(new TwigComponentExtension());
44+
$container->loadFromExtension('twig_component', [
45+
'defaults' => [],
46+
'anonymous_template_directory' => 'components/',
47+
'profiler' => false,
48+
]);
49+
$this->compileContainer($container);
50+
51+
$this->assertFalse($container->hasDefinition('ux.twig_component.data_collector'));
52+
}
53+
3954
public function testDataCollectorWithoutDebugMode()
4055
{
4156
$container = $this->createContainer();
@@ -44,6 +59,7 @@ public function testDataCollectorWithoutDebugMode()
4459
$container->loadFromExtension('twig_component', [
4560
'defaults' => [],
4661
'anonymous_template_directory' => 'components/',
62+
'profiler' => true,
4763
]);
4864
$this->compileContainer($container);
4965

0 commit comments

Comments
 (0)