Skip to content
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
8 changes: 7 additions & 1 deletion phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -30061,7 +30061,7 @@ parameters:
path: tests/bundle/Core/EventListener/BackgroundIndexingTerminateListenerTest.php

-
message: '#^Parameter \#1 \$stub of method PHPUnit\\Framework\\MockObject\\Builder\\InvocationMocker\<Ibexa\\Contracts\\Core\\Persistence\\Content\\Handler\>\:\:will\(\) expects PHPUnit\\Framework\\MockObject\\Stub\\Stub, PHPUnit\\Framework\\MockObject\\Stub given\.$#'
message: '#^Parameter \#1 \$stub of method PHPUnit\\Framework\\MockObject\\Builder\\InvocationMocker\:\:will\(\) expects PHPUnit\\Framework\\MockObject\\Stub\\Stub, PHPUnit\\Framework\\MockObject\\Stub given\.$#'
identifier: argument.type
count: 2
path: tests/bundle/Core/EventListener/BackgroundIndexingTerminateListenerTest.php
Expand Down Expand Up @@ -46554,6 +46554,12 @@ parameters:
count: 1
path: tests/integration/Core/Repository/SearchServiceTest.php

-
message: '#^Parameter \#1 \$query of method Ibexa\\Contracts\\Core\\Repository\\SearchService\:\:findLocations\(\) expects Ibexa\\Contracts\\Core\\Repository\\Values\\Content\\LocationQuery, Ibexa\\Contracts\\Core\\Repository\\Values\\Content\\Query given\.$#'
identifier: argument.type
count: 1
path: tests/integration/Core/Repository/SearchServiceTest.php

-
message: '#^Property Ibexa\\Contracts\\Core\\Repository\\Values\\Content\\Search\\SearchHit\:\:\$valueObject \(Ibexa\\Contracts\\Core\\Repository\\Values\\ValueObject\) does not accept array\<string, int\|string\>\.$#'
identifier: assign.propertyType
Expand Down
32 changes: 22 additions & 10 deletions src/bundle/Debug/DependencyInjection/Compiler/DataCollectorPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,30 @@ public function process(ContainerBuilder $container)
}

$dataCollectorDef = $container->getDefinition(IbexaCoreCollector::class);
foreach ($container->findTaggedServiceIds('ibexa.debug.data_collector') as $id => $attributes) {
foreach ($attributes as $attribute) {
$dataCollectorDef->addMethodCall(
'addCollector',
[
new Reference($id),
isset($attribute['panelTemplate']) ? $attribute['panelTemplate'] : null,
isset($attribute['toolbarTemplate']) ? $attribute['toolbarTemplate'] : null,
]
);
$collectors = [];

foreach ($container->findTaggedServiceIds('ibexa.debug.data_collector') as $id => $tags) {
foreach ($tags as $attributes) {
$priority = $attributes['priority'] ?? 0;
$collectors[] = [
'id' => $id,
'priority' => $priority,
'panelTemplate' => $attributes['panelTemplate'] ?? null,
'toolbarTemplate' => $attributes['toolbarTemplate'] ?? null,
];
}
}

/** @var list<array{id: string, priority: int, panelTemplate: string|null, toolbarTemplate: string|null}> $collectors */
usort($collectors, static fn (array $a, array $b): int => $b['priority'] <=> $a['priority']);

foreach ($collectors as $collector) {
$dataCollectorDef->addMethodCall('addCollector', [
new Reference($collector['id']),
$collector['panelTemplate'],
$collector['toolbarTemplate'],
]);
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/bundle/Debug/Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ services:
id: "ezpublish.debug.siteaccess"
panelTemplate: '@IbexaDebug/Profiler/siteaccess/panel.html.twig'
toolbarTemplate: '@IbexaDebug/Profiler/siteaccess/toolbar.html.twig'
priority: 200

Ibexa\Bundle\Debug\Collector\PersistenceCacheCollector:
class: Ibexa\Bundle\Debug\Collector\PersistenceCacheCollector
Expand All @@ -25,3 +26,4 @@ services:
id: "ezpublish.debug.persistence"
panelTemplate: '@IbexaDebug/Profiler/persistence/panel.html.twig'
toolbarTemplate: '@IbexaDebug/Profiler/persistence/toolbar.html.twig'
priority: 100
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,44 @@ protected function registerCompilerPass(ContainerBuilder $container): void

public function testAddCollector()
{
$panelTemplate = 'panel.html.twig';
$toolbarTemplate = 'toolbar.html.twig';
$definition = new Definition();
$definition->addTag(
'ibexa.debug.data_collector',
['panelTemplate' => $panelTemplate, 'toolbarTemplate' => $toolbarTemplate]
);
$defA = new Definition();
$defA->addTag('ibexa.debug.data_collector', [
'panelTemplate' => 'panel_a.html.twig',
'toolbarTemplate' => 'toolbar_a.html.twig',
'priority' => 5,
]);
$this->setDefinition('collector_a', $defA);

$defB = new Definition();
$defB->addTag('ibexa.debug.data_collector', [
'panelTemplate' => 'panel_b.html.twig',
'toolbarTemplate' => 'toolbar_b.html.twig',
'priority' => 10,
]);
$this->setDefinition('collector_b', $defB);

$serviceId = 'service_id';
$this->setDefinition($serviceId, $definition);
$this->compile();

$this->assertContainerBuilderHasServiceDefinitionWithMethodCall(
self::assertContainerBuilderHasServiceDefinitionWithMethodCall(
IbexaCoreCollector::class,
'addCollector',
[new Reference($serviceId), $panelTemplate, $toolbarTemplate]
[new Reference('collector_b'), 'panel_b.html.twig', 'toolbar_b.html.twig']
);

self::assertContainerBuilderHasServiceDefinitionWithMethodCall(
IbexaCoreCollector::class,
'addCollector',
[new Reference('collector_a'), 'panel_a.html.twig', 'toolbar_a.html.twig']
);

$calls = $this->container->getDefinition(IbexaCoreCollector::class)->getMethodCalls();

self::assertCount(2, $calls);
self::assertSame('addCollector', $calls[0][0]);
self::assertEquals(new Reference('collector_b'), $calls[0][1][0]);

self::assertSame('addCollector', $calls[1][0]);
self::assertEquals(new Reference('collector_a'), $calls[1][1][0]);
}
}

Expand Down
Loading