diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 1fca190834..ed8f382561 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -9306,12 +9306,6 @@ parameters: count: 1 path: src/lib/Base/Container/Compiler/Search/FieldRegistryPass.php - - - message: '#^Method Ibexa\\Core\\Base\\Container\\Compiler\\Search\\Legacy\\CriteriaConverterPass\:\:process\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: src/lib/Base/Container/Compiler/Search/Legacy/CriteriaConverterPass.php - - message: '#^Method Ibexa\\Core\\Base\\Container\\Compiler\\Search\\Legacy\\CriterionFieldValueHandlerRegistryPass\:\:process\(\) has no return type specified\.$#' identifier: missingType.return diff --git a/src/bundle/LegacySearchEngine/IbexaLegacySearchEngineBundle.php b/src/bundle/LegacySearchEngine/IbexaLegacySearchEngineBundle.php index 2110f94a71..c5cb953acd 100644 --- a/src/bundle/LegacySearchEngine/IbexaLegacySearchEngineBundle.php +++ b/src/bundle/LegacySearchEngine/IbexaLegacySearchEngineBundle.php @@ -7,7 +7,6 @@ namespace Ibexa\Bundle\LegacySearchEngine; use Ibexa\Core\Base\Container\Compiler\Search\FieldRegistryPass; -use Ibexa\Core\Base\Container\Compiler\Search\Legacy\CriteriaConverterPass; use Ibexa\Core\Base\Container\Compiler\Search\Legacy\CriterionFieldValueHandlerRegistryPass; use Ibexa\Core\Base\Container\Compiler\Search\Legacy\SortClauseConverterPass; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -19,7 +18,6 @@ public function build(ContainerBuilder $container) { parent::build($container); - $container->addCompilerPass(new CriteriaConverterPass()); $container->addCompilerPass(new CriterionFieldValueHandlerRegistryPass()); $container->addCompilerPass(new SortClauseConverterPass()); $container->addCompilerPass(new FieldRegistryPass()); diff --git a/src/lib/Base/Container/Compiler/Search/Legacy/CriteriaConverterPass.php b/src/lib/Base/Container/Compiler/Search/Legacy/CriteriaConverterPass.php deleted file mode 100644 index c351231308..0000000000 --- a/src/lib/Base/Container/Compiler/Search/Legacy/CriteriaConverterPass.php +++ /dev/null @@ -1,65 +0,0 @@ -setHandlersForConverter( - $container, - 'ibexa.search.legacy.gateway.criteria_converter.content', - 'ibexa.search.legacy.gateway.criterion_handler.content' - ); - - $this->setHandlersForConverter( - $container, - 'ibexa.search.legacy.gateway.criteria_converter.location', - 'ibexa.search.legacy.gateway.criterion_handler.location' - ); - - $this->setHandlersForConverter( - $container, - 'ibexa.core.trash.search.legacy.gateway.criteria_converter', - 'ibexa.search.legacy.trash.gateway.criterion.handler' - ); - - $this->setHandlersForConverter( - $container, - CriteriaConverter::class, - 'ibexa.storage.legacy.url.criterion.handler' - ); - } - - private function setHandlersForConverter( - ContainerBuilder $container, - string $serviceId, - string $handlersTag - ): void { - if (!$container->hasDefinition($serviceId)) { - return; - } - - $service = $container->getDefinition($serviceId); - $handlers = $this->findAndSortTaggedServices($handlersTag, $container); - foreach ($handlers as $handler) { - $service->addMethodCall('addHandler', [$handler]); - } - } -} - -class_alias(CriteriaConverterPass::class, 'eZ\Publish\Core\Base\Container\Compiler\Search\Legacy\CriteriaConverterPass'); diff --git a/src/lib/Persistence/Legacy/URL/Query/CriteriaConverter.php b/src/lib/Persistence/Legacy/URL/Query/CriteriaConverter.php index 21e7002ac7..14cceef9c4 100644 --- a/src/lib/Persistence/Legacy/URL/Query/CriteriaConverter.php +++ b/src/lib/Persistence/Legacy/URL/Query/CriteriaConverter.php @@ -9,33 +9,44 @@ use Doctrine\DBAL\Query\QueryBuilder; use Ibexa\Contracts\Core\Repository\Exceptions\NotImplementedException; use Ibexa\Contracts\Core\Repository\Values\URL\Query\Criterion; +use Traversable; class CriteriaConverter { /** * Criterion handlers. * - * @var \Ibexa\Core\Persistence\Legacy\URL\Query\CriterionHandler[] + * @var iterable<\Ibexa\Core\Persistence\Legacy\URL\Query\CriterionHandler> */ - protected $handlers; + protected iterable $handlers; /** * Construct from an optional array of Criterion handlers. * - * @param \Ibexa\Core\Persistence\Legacy\URL\Query\CriterionHandler[] $handlers + * @param iterable<\Ibexa\Core\Persistence\Legacy\URL\Query\CriterionHandler> $handlers */ - public function __construct(array $handlers = []) + public function __construct(iterable $handlers = []) { $this->handlers = $handlers; } /** - * Adds handler. - * - * @param \Ibexa\Core\Persistence\Legacy\URL\Query\CriterionHandler $handler + * @deprecated The "%s" method is deprecated. Use a service definition tag "ibexa.storage.legacy.url.criterion.handler" instead. */ public function addHandler(CriterionHandler $handler) { + trigger_deprecation( + 'ibexa/core', + '4.6.24', + 'The "%s" method is deprecated. Use a service definition tag ("%s") instead.', + __METHOD__, + 'ibexa.storage.legacy.url.criterion.handler', + ); + + if ($this->handlers instanceof Traversable) { + $this->handlers = iterator_to_array($this->handlers); + } + $this->handlers[] = $handler; } diff --git a/src/lib/Resources/settings/search_engines/legacy/criterion_handlers_content.yml b/src/lib/Resources/settings/search_engines/legacy/criterion_handlers_content.yml index dfe3a92f4b..bdc39a5448 100644 --- a/src/lib/Resources/settings/search_engines/legacy/criterion_handlers_content.yml +++ b/src/lib/Resources/settings/search_engines/legacy/criterion_handlers_content.yml @@ -1,10 +1,9 @@ services: - # Note: services tagged with: - # - ibexa.search.legacy.gateway.criterion_handler.content - # are registered to this one using compilation pass ibexa.search.legacy.gateway.criteria_converter.content: class: Ibexa\Core\Search\Legacy\Content\Common\Gateway\CriteriaConverter lazy: true + arguments: + $handlers: !tagged_iterator ibexa.search.legacy.gateway.criterion_handler.content Ibexa\Core\Search\Legacy\Content\Gateway\CriterionHandler\Ancestor: parent: Ibexa\Core\Search\Legacy\Content\Common\Gateway\CriterionHandler diff --git a/src/lib/Resources/settings/search_engines/legacy/criterion_handlers_location.yml b/src/lib/Resources/settings/search_engines/legacy/criterion_handlers_location.yml index 72d5f914fc..716e276972 100644 --- a/src/lib/Resources/settings/search_engines/legacy/criterion_handlers_location.yml +++ b/src/lib/Resources/settings/search_engines/legacy/criterion_handlers_location.yml @@ -1,10 +1,9 @@ services: - # Note: services tagged with: - # - ibexa.search.legacy.gateway.criterion_handler.location - # are registered to this one using compilation pass ibexa.search.legacy.gateway.criteria_converter.location: class: Ibexa\Core\Search\Legacy\Content\Common\Gateway\CriteriaConverter lazy: true + arguments: + $handlers: !tagged_iterator ibexa.search.legacy.gateway.criterion_handler.location Ibexa\Core\Search\Legacy\Content\Location\Gateway\CriterionHandler\Ancestor: parent: Ibexa\Core\Search\Legacy\Content\Common\Gateway\CriterionHandler diff --git a/src/lib/Resources/settings/storage_engines/legacy/trash.yml b/src/lib/Resources/settings/storage_engines/legacy/trash.yml index 02be99bc24..c35d09c453 100644 --- a/src/lib/Resources/settings/storage_engines/legacy/trash.yml +++ b/src/lib/Resources/settings/storage_engines/legacy/trash.yml @@ -12,6 +12,8 @@ services: ibexa.core.trash.search.legacy.gateway.criteria_converter: class: Ibexa\Core\Search\Legacy\Content\Common\Gateway\CriteriaConverter lazy: true + arguments: + $handlers: !tagged_iterator ibexa.search.legacy.trash.gateway.criterion.handler ibexa.core.trash.search.legacy.gateway.sort_clause_converter: class: Ibexa\Core\Search\Legacy\Content\Common\Gateway\SortClauseConverter diff --git a/src/lib/Resources/settings/storage_engines/legacy/url.yml b/src/lib/Resources/settings/storage_engines/legacy/url.yml index c61b5d5269..869b88afbf 100644 --- a/src/lib/Resources/settings/storage_engines/legacy/url.yml +++ b/src/lib/Resources/settings/storage_engines/legacy/url.yml @@ -27,3 +27,5 @@ services: Ibexa\Core\Persistence\Legacy\URL\Query\CriteriaConverter: class: Ibexa\Core\Persistence\Legacy\URL\Query\CriteriaConverter lazy: true + arguments: + $handlers: !tagged_iterator ibexa.storage.legacy.url.criterion.handler diff --git a/src/lib/Search/Legacy/Content/Common/Gateway/CriteriaConverter.php b/src/lib/Search/Legacy/Content/Common/Gateway/CriteriaConverter.php index dd474e2fb9..616cb5f512 100644 --- a/src/lib/Search/Legacy/Content/Common/Gateway/CriteriaConverter.php +++ b/src/lib/Search/Legacy/Content/Common/Gateway/CriteriaConverter.php @@ -9,6 +9,7 @@ use Doctrine\DBAL\Query\QueryBuilder; use Ibexa\Contracts\Core\Repository\Exceptions\NotImplementedException; use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion; +use Traversable; /** * Content locator gateway implementation using the DoctrineDatabase. @@ -20,25 +21,41 @@ class CriteriaConverter * * @var \Ibexa\Core\Search\Legacy\Content\Common\Gateway\CriterionHandler[] */ - protected $handlers; + protected iterable $handlers; /** * Construct from an optional array of Criterion handlers. * * @param \Ibexa\Core\Search\Legacy\Content\Common\Gateway\CriterionHandler[] $handlers */ - public function __construct(array $handlers = []) + public function __construct(iterable $handlers = []) { $this->handlers = $handlers; } /** - * Adds handler. - * - * @param \Ibexa\Core\Search\Legacy\Content\Common\Gateway\CriterionHandler $handler + * @deprecated The "%s" method is deprecated. Use a service definition tag instead (one of + * "ibexa.search.legacy.gateway.criterion_handler.content", + * "ibexa.search.legacy.gateway.criterion_handler.location", + * "ibexa.search.legacy.trash.gateway.criterion.handler"). */ public function addHandler(CriterionHandler $handler) { + trigger_deprecation( + 'ibexa/core', + '4.6.24', + 'The "%s" method is deprecated. Use a service definition tag instead (one of "%s").', + __METHOD__, + implode('", "', [ + 'ibexa.search.legacy.gateway.criterion_handler.content', + 'ibexa.search.legacy.gateway.criterion_handler.location', + 'ibexa.search.legacy.trash.gateway.criterion.handler', + ]), + ); + + if ($this->handlers instanceof Traversable) { + $this->handlers = iterator_to_array($this->handlers); + } $this->handlers[] = $handler; } diff --git a/tests/integration/Core/LegacyTestContainerBuilder.php b/tests/integration/Core/LegacyTestContainerBuilder.php index 09d0ca3339..132f9e57ae 100644 --- a/tests/integration/Core/LegacyTestContainerBuilder.php +++ b/tests/integration/Core/LegacyTestContainerBuilder.php @@ -124,7 +124,6 @@ private function registerCompilerPasses(): void $this->addCompilerPass(new Compiler\Storage\Legacy\FieldValueConverterRegistryPass()); $this->addCompilerPass(new Compiler\Storage\Legacy\RoleLimitationConverterPass()); - $this->addCompilerPass(new Compiler\Search\Legacy\CriteriaConverterPass()); $this->addCompilerPass(new Compiler\Search\Legacy\CriterionFieldValueHandlerRegistryPass()); $this->addCompilerPass(new Compiler\Search\Legacy\SortClauseConverterPass()); diff --git a/tests/lib/Base/Container/Compiler/Search/Legacy/CriteriaConverterPassTest.php b/tests/lib/Base/Container/Compiler/Search/Legacy/CriteriaConverterPassTest.php deleted file mode 100644 index fc63ded6d5..0000000000 --- a/tests/lib/Base/Container/Compiler/Search/Legacy/CriteriaConverterPassTest.php +++ /dev/null @@ -1,154 +0,0 @@ -addCompilerPass(new MyCompilerPass()); - */ - protected function registerCompilerPass(ContainerBuilder $container): void - { - $container->addCompilerPass(new CriteriaConverterPass()); - } - - /** - * @dataProvider provideDescribedServiceToTagName - */ - public function testAddHandlers(string $serviceId, string $tag): void - { - $this->setDefinition( - $serviceId, - new Definition() - ); - - $def = new Definition(); - $def->addTag($tag); - $this->setDefinition('service_id', $def); - - $this->compile(); - - $this->assertContainerBuilderHasServiceDefinitionWithMethodCall( - $serviceId, - 'addHandler', - [new Reference('service_id')] - ); - } - - /** - * @dataProvider provideDescribedServiceToTagName - */ - public function testAddContentHandlersWithPriority(string $serviceId, string $tag): void - { - $this->setDefinition( - $serviceId, - new Definition() - ); - - $def = new Definition(); - $def->addTag($tag, ['priority' => 0]); - $this->setDefinition('service_1_id', $def); - - $def = new Definition(); - $def->addTag($tag, ['priority' => 100]); - $this->setDefinition('service_with_priority', $def); - - $this->compile(); - - $this->assertContainerBuilderHasServiceDefinitionWithMethodCall( - $serviceId, - 'addHandler', - [new Reference('service_with_priority')], - 0, - ); - $this->assertContainerBuilderHasServiceDefinitionWithMethodCall( - $serviceId, - 'addHandler', - [new Reference('service_1_id')], - 1, - ); - } - - /** - * @return iterable - */ - public static function provideServiceToTagName(): iterable - { - yield 'ibexa.search.legacy.gateway.criteria_converter.content' => 'ibexa.search.legacy.gateway.criterion_handler.content'; - - yield 'ibexa.search.legacy.gateway.criteria_converter.location' => 'ibexa.search.legacy.gateway.criterion_handler.location'; - - yield 'ibexa.core.trash.search.legacy.gateway.criteria_converter' => 'ibexa.search.legacy.trash.gateway.criterion.handler'; - - yield CriteriaConverter::class => 'ibexa.storage.legacy.url.criterion.handler'; - } - - /** - * @return iterable - */ - public static function provideDescribedServiceToTagName(): iterable - { - foreach (self::provideServiceToTagName() as $serviceId => $tag) { - yield sprintf('Service "%s" with tag "%s"', $serviceId, $tag) => [$serviceId, $tag]; - } - } - - public function testAddMultipleHandlers(): void - { - $this->setDefinition( - 'ibexa.search.legacy.gateway.criteria_converter.content', - new Definition() - ); - $this->setDefinition( - 'ibexa.search.legacy.gateway.criteria_converter.location', - new Definition() - ); - $this->setDefinition( - 'ibexa.core.trash.search.legacy.gateway.criteria_converter', - new Definition() - ); - - $commonServiceId = 'common_service_id'; - $def = new Definition(); - $def->addTag('ibexa.search.legacy.gateway.criterion_handler.content'); - $def->addTag('ibexa.search.legacy.gateway.criterion_handler.location'); - $def->addTag('ibexa.search.legacy.trash.gateway.criterion.handler'); - $this->setDefinition($commonServiceId, $def); - - $this->compile(); - - $this->assertContainerBuilderHasServiceDefinitionWithMethodCall( - 'ibexa.search.legacy.gateway.criteria_converter.content', - 'addHandler', - [new Reference($commonServiceId)] - ); - - $this->assertContainerBuilderHasServiceDefinitionWithMethodCall( - 'ibexa.search.legacy.gateway.criteria_converter.location', - 'addHandler', - [new Reference($commonServiceId)] - ); - - $this->assertContainerBuilderHasServiceDefinitionWithMethodCall( - 'ibexa.core.trash.search.legacy.gateway.criteria_converter', - 'addHandler', - [new Reference($commonServiceId)] - ); - } -} - -class_alias(CriteriaConverterPassTest::class, 'eZ\Publish\Core\Base\Tests\Container\Compiler\Search\Legacy\CriteriaConverterPassTest'); diff --git a/tests/lib/Persistence/Legacy/HandlerTest.php b/tests/lib/Persistence/Legacy/HandlerTest.php index 3000d07044..5f513bbdd7 100644 --- a/tests/lib/Persistence/Legacy/HandlerTest.php +++ b/tests/lib/Persistence/Legacy/HandlerTest.php @@ -227,13 +227,7 @@ public function testTransactionHandlerTwice(): void protected function getHandlerFixture(): Handler { - if (!isset(self::$legacyHandler)) { - $container = $this->getContainer(); - - self::$legacyHandler = $container->get(Handler::class); - } - - return self::$legacyHandler; + return self::$legacyHandler ??= $this->getContainer()->get(Handler::class); } protected static Container $container;