Skip to content

Commit afaaaad

Browse files
committed
[TwigComponent] Merge profiler and profiler_collect_components config options
1 parent cb8f1a1 commit afaaaad

File tree

5 files changed

+22
-29
lines changed

5 files changed

+22
-29
lines changed

src/TwigComponent/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# CHANGELOG
22

3+
## 2.32
4+
5+
- Add option `profiler.collect_components` to control component data collection
6+
in the profiler (enabled in debug mode by default)
7+
38
## 2.30
49

510
- Ensure compatibility with PHP 8.5

src/TwigComponent/config/debug.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
->args([
2929
service('ux.twig_component.component_logger_listener'),
3030
service('twig'),
31-
abstract_arg('profiler dump components'),
31+
abstract_arg('profiler collect components'),
3232
])
3333
->tag('data_collector', [
3434
'template' => '@TwigComponent/Collector/twig_component.html.twig',

src/TwigComponent/src/DataCollector/TwigComponentDataCollector.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ final class TwigComponentDataCollector extends AbstractDataCollector implements
3535
public function __construct(
3636
private readonly TwigComponentLoggerListener $logger,
3737
private readonly Environment $twig,
38-
private readonly bool $dumpComponents = true,
38+
private readonly bool $collectComponents = true,
3939
) {
4040
$this->hasStub = class_exists(ClassStub::class);
4141
}
@@ -136,7 +136,7 @@ private function collectDataFromLogger(): void
136136
'render_start' => $profile[0],
137137
];
138138

139-
if ($this->dumpComponents) {
139+
if ($this->collectComponents) {
140140
$renders[$renderId]['component'] = $mountedComponent->getComponent();
141141
}
142142

src/TwigComponent/src/DependencyInjection/TwigComponentExtension.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,11 @@ static function (ChildDefinition $definition, AsTwigComponent $attribute) {
150150
$container->setAlias('console.command.stimulus_component_debug', 'ux.twig_component.command.debug')
151151
->setDeprecated('symfony/ux-twig-component', '2.13', '%alias_id%');
152152

153-
if ($container->getParameter('kernel.debug') && $config['profiler']) {
153+
if ($config['profiler']['enabled']) {
154154
$loader->load('debug.php');
155+
155156
$container->getDefinition('ux.twig_component.data_collector')
156-
->setArgument(2, $config['profiler_dump_components'] ?? true);
157+
->setArgument(2, $config['profiler']['collect_components']);
157158
}
158159

159160
$loader->load('cache.php');
@@ -217,13 +218,13 @@ public function getConfigTreeBuilder(): TreeBuilder
217218
->scalarNode('anonymous_template_directory')
218219
->info('Defaults to `components`')
219220
->end()
220-
->booleanNode('profiler')
221-
->info('Enables the profiler for Twig Component (in debug mode)')
222-
->defaultValue('%kernel.debug%')
223-
->end()
224-
->booleanNode('profiler_dump_components')
225-
->info('Dump components in the Twig Component profiler panel')
226-
->defaultTrue()
221+
->arrayNode('profiler')
222+
->info('Enables the profiler for Twig Component')
223+
->canBeEnabled()
224+
->children()
225+
->booleanNode('enabled')->defaultValue('%kernel.debug%')->end()
226+
->booleanNode('collect_components')->info('Collect components instances')->defaultTrue()->end()
227+
->end()
227228
->end()
228229
->scalarNode('controllers_json')
229230
->setDeprecated('symfony/ux-twig-component', '2.18', 'The "twig_component.controllers_json" config option is deprecated, and will be removed in 3.0.')

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

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,17 @@ public function testDataCollectorWithDebugMode()
4040
$this->assertTrue($container->getDefinition('ux.twig_component.data_collector')->getArgument(2));
4141
}
4242

43-
public function testDataCollectorWithDumpComponentsDisabled()
43+
public function testDataCollectorWithCollectComponentsDisabled()
4444
{
4545
$container = $this->createContainer();
4646
$container->setParameter('kernel.debug', true);
4747
$container->registerExtension(new TwigComponentExtension());
4848
$container->loadFromExtension('twig_component', [
4949
'defaults' => [],
5050
'anonymous_template_directory' => 'components/',
51-
'profiler_dump_components' => false,
51+
'profiler' => [
52+
'collect_components' => false,
53+
],
5254
]);
5355
$this->compileContainer($container);
5456

@@ -71,21 +73,6 @@ public function testDataCollectorWithDebugModeCanBeDisabled()
7173
$this->assertFalse($container->hasDefinition('ux.twig_component.data_collector'));
7274
}
7375

74-
public function testDataCollectorWithoutDebugMode()
75-
{
76-
$container = $this->createContainer();
77-
$container->setParameter('kernel.debug', false);
78-
$container->registerExtension(new TwigComponentExtension());
79-
$container->loadFromExtension('twig_component', [
80-
'defaults' => [],
81-
'anonymous_template_directory' => 'components/',
82-
'profiler' => true,
83-
]);
84-
$this->compileContainer($container);
85-
86-
$this->assertFalse($container->hasDefinition('ux.twig_component.data_collector'));
87-
}
88-
8976
/**
9077
* @group legacy
9178
*/

0 commit comments

Comments
 (0)