Skip to content
Open
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
2 changes: 2 additions & 0 deletions src/TwigComponent/config/debug.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Symfony\UX\TwigComponent\DataCollector\TwigComponentDataCollector;
use Symfony\UX\TwigComponent\EventListener\TwigComponentLoggerListener;

use function Symfony\Component\DependencyInjection\Loader\Configurator\abstract_arg;
use function Symfony\Component\DependencyInjection\Loader\Configurator\service;

return static function (ContainerConfigurator $container) {
Expand All @@ -27,6 +28,7 @@
->args([
service('ux.twig_component.component_logger_listener'),
service('twig'),
abstract_arg('profiler dump components'),
])
->tag('data_collector', [
'template' => '@TwigComponent/Collector/twig_component.html.twig',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ final class TwigComponentDataCollector extends AbstractDataCollector implements
public function __construct(
private readonly TwigComponentLoggerListener $logger,
private readonly Environment $twig,
private readonly bool $dumpComponents = true,
) {
$this->hasStub = class_exists(ClassStub::class);
}
Expand Down Expand Up @@ -130,12 +131,15 @@ private function collectDataFromLogger(): void
'input_props' => $mountedComponent->getInputProps(),
'attributes' => $mountedComponent->getAttributes()->all(),
'template_index' => $event->getTemplateIndex(),
'component' => $mountedComponent->getComponent(),
'depth' => \count($ongoingRenders),
'children' => [],
'render_start' => $profile[0],
];

if ($this->dumpComponents) {
$renders[$renderId]['component'] = $mountedComponent->getComponent();
}

if ($parentId = end($ongoingRenders)) {
$renders[$parentId]['children'][] = $renderId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ static function (ChildDefinition $definition, AsTwigComponent $attribute) {

if ($container->getParameter('kernel.debug') && $config['profiler']) {
$loader->load('debug.php');
$container->getDefinition('ux.twig_component.data_collector')
->setArgument(2, $config['profiler_dump_components'] ?? true);
}

$loader->load('cache.php');
Expand Down Expand Up @@ -219,6 +221,10 @@ public function getConfigTreeBuilder(): TreeBuilder
->info('Enables the profiler for Twig Component (in debug mode)')
->defaultValue('%kernel.debug%')
->end()
->booleanNode('profiler_dump_components')
->info('Dump components in the Twig Component profiler panel')
->defaultTrue()
->end()
->scalarNode('controllers_json')
->setDeprecated('symfony/ux-twig-component', '2.18', 'The "twig_component.controllers_json" config option is deprecated, and will be removed in 3.0.')
->defaultNull()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,10 +293,12 @@
<th scope="row">Attributes</th>
<td colspan="4">{{ profiler_dump(render.attributes) }}</td>
</tr>
{% if render.component is defined %}
<tr>
<th scope="row">Component</th>
<td colspan="4">{{ profiler_dump(render.component) }}</td>
</tr>
{% endif %}
</tbody>
</table>
{% endfor %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,23 @@ public function testDataCollectorWithDebugMode()
$this->compileContainer($container);

$this->assertTrue($container->hasDefinition('ux.twig_component.data_collector'));
$this->assertTrue($container->getDefinition('ux.twig_component.data_collector')->getArgument(2));
}

public function testDataCollectorWithDumpComponentsDisabled()
{
$container = $this->createContainer();
$container->setParameter('kernel.debug', true);
$container->registerExtension(new TwigComponentExtension());
$container->loadFromExtension('twig_component', [
'defaults' => [],
'anonymous_template_directory' => 'components/',
'profiler_dump_components' => false,
]);
$this->compileContainer($container);

$this->assertTrue($container->hasDefinition('ux.twig_component.data_collector'));
$this->assertFalse($container->getDefinition('ux.twig_component.data_collector')->getArgument(2));
}

public function testDataCollectorWithDebugModeCanBeDisabled()
Expand Down
Loading