Skip to content

Commit b75d468

Browse files
authored
EZP-31588: As a Developer I want to configure search engine features with tags which follows same convention (#51)
* EZP-31588: Introduced eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Compiler\TaggedServiceIdsIterator\BackwardCompatibleIterator * EZP-31588: Aligned search engine tags to convention
1 parent 8441b19 commit b75d468

File tree

16 files changed

+463
-146
lines changed

16 files changed

+463
-146
lines changed

eZ/Bundle/EzPublishCoreBundle/ApiLoader/SearchEngineFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function buildSearchEngine()
7373
) {
7474
throw new InvalidSearchEngine(
7575
"Invalid search engine '{$repositoryConfig['search']['engine']}'. " .
76-
"Could not find any service tagged with 'ezpublish.searchEngine' " .
76+
"Could not find any service tagged with 'ezplatform.search_engine' " .
7777
"with alias '{$repositoryConfig['search']['engine']}'."
7878
);
7979
}

eZ/Bundle/EzPublishCoreBundle/ApiLoader/SearchEngineIndexerFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function buildSearchEngineIndexer()
7373
) {
7474
throw new InvalidSearchEngineIndexer(
7575
"Invalid search engine '{$repositoryConfig['search']['engine']}'. " .
76-
"Could not find any service tagged with 'ezpublish.searchEngineIndexer' " .
76+
"Could not find any service tagged with 'ezplatform.search_engine.indexer' " .
7777
"with alias '{$repositoryConfig['search']['engine']}'."
7878
);
7979
}

eZ/Bundle/EzPublishCoreBundle/DependencyInjection/Compiler/FieldTypeParameterProviderRegistryPass.php

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77
namespace eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Compiler;
88

9+
use eZ\Publish\Core\Base\Container\Compiler\TaggedServiceIdsIterator\BackwardCompatibleIterator;
910
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
1011
use Symfony\Component\DependencyInjection\ContainerBuilder;
1112
use Symfony\Component\DependencyInjection\Reference;
@@ -31,20 +32,13 @@ public function process(ContainerBuilder $container)
3132

3233
$parameterProviderRegistryDef = $container->getDefinition('ezpublish.fieldType.parameterProviderRegistry');
3334

34-
$deprecatedFieldTypeParameterProviderTags = $container->findTaggedServiceIds(self::DEPRECATED_FIELD_TYPE_PARAMETER_PROVIDER_SERVICE_TAG);
35-
foreach ($deprecatedFieldTypeParameterProviderTags as $deprecatedFieldTypeParameterProviderTag) {
36-
@trigger_error(
37-
sprintf(
38-
'Service tag `%s` is deprecated and will be removed in eZ Platform 4.0. Use `%s` instead.',
39-
self::DEPRECATED_FIELD_TYPE_PARAMETER_PROVIDER_SERVICE_TAG,
40-
self::FIELD_TYPE_PARAMETER_PROVIDER_SERVICE_TAG
41-
),
42-
E_USER_DEPRECATED
43-
);
44-
}
45-
$fieldTypeParameterProviderTags = $container->findTaggedServiceIds(self::FIELD_TYPE_PARAMETER_PROVIDER_SERVICE_TAG);
46-
$parameterProviderFieldTypesTags = array_merge($deprecatedFieldTypeParameterProviderTags, $fieldTypeParameterProviderTags);
47-
foreach ($parameterProviderFieldTypesTags as $id => $attributes) {
35+
$iterator = new BackwardCompatibleIterator(
36+
$container,
37+
self::FIELD_TYPE_PARAMETER_PROVIDER_SERVICE_TAG,
38+
self::DEPRECATED_FIELD_TYPE_PARAMETER_PROVIDER_SERVICE_TAG
39+
);
40+
41+
foreach ($iterator as $id => $attributes) {
4842
foreach ($attributes as $attribute) {
4943
if (!isset($attribute['alias'])) {
5044
throw new \LogicException(

eZ/Bundle/EzPublishCoreBundle/DependencyInjection/Compiler/QueryTypePass.php

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88

99
namespace eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Compiler;
1010

11-
use AppendIterator;
12-
use ArrayIterator;
13-
use Iterator;
11+
use eZ\Publish\Core\Base\Container\Compiler\TaggedServiceIdsIterator\BackwardCompatibleIterator;
1412
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
1513
use Symfony\Component\DependencyInjection\ContainerBuilder;
1614
use Symfony\Component\DependencyInjection\Reference;
@@ -31,7 +29,12 @@ public function process(ContainerBuilder $container): void
3129

3230
$queryTypes = [];
3331

34-
$iterator = $this->getTaggedServiceIdsIterator($container);
32+
$iterator = new BackwardCompatibleIterator(
33+
$container,
34+
self::QUERY_TYPE_SERVICE_TAG,
35+
self::DEPRECATED_QUERY_TYPE_SERVICE_TAG
36+
);
37+
3538
foreach ($iterator as $taggedServiceId => $tags) {
3639
$queryTypeDefinition = $container->getDefinition($taggedServiceId);
3740
$queryTypeClass = $container->getParameterBag()->resolveValue($queryTypeDefinition->getClass());
@@ -45,31 +48,4 @@ public function process(ContainerBuilder $container): void
4548
$aggregatorDefinition = $container->getDefinition('ezpublish.query_type.registry');
4649
$aggregatorDefinition->addMethodCall('addQueryTypes', [$queryTypes]);
4750
}
48-
49-
private function getTaggedServiceIdsIterator(ContainerBuilder $container): Iterator
50-
{
51-
$serviceIdsWithDeprecatedTags = $container->findTaggedServiceIds(
52-
self::DEPRECATED_QUERY_TYPE_SERVICE_TAG
53-
);
54-
55-
foreach ($serviceIdsWithDeprecatedTags as $serviceId => $tags) {
56-
@trigger_error(
57-
sprintf(
58-
'Service tag `%s` is deprecated and will be removed in eZ Platform 4.0. Tag %s with `%s` instead.',
59-
self::DEPRECATED_QUERY_TYPE_SERVICE_TAG,
60-
$serviceId,
61-
self::QUERY_TYPE_SERVICE_TAG
62-
),
63-
E_USER_DEPRECATED
64-
);
65-
}
66-
67-
$taggedServiceIds = $container->findTaggedServiceIds(self::QUERY_TYPE_SERVICE_TAG);
68-
69-
$iterator = new AppendIterator();
70-
$iterator->append(new ArrayIterator($serviceIdsWithDeprecatedTags));
71-
$iterator->append(new ArrayIterator($taggedServiceIds));
72-
73-
return $iterator;
74-
}
7551
}

eZ/Bundle/EzPublishCoreBundle/DependencyInjection/Compiler/RegisterSearchEngineIndexerPass.php

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,20 @@
66
*/
77
namespace eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Compiler;
88

9+
use eZ\Publish\Core\Base\Container\Compiler\TaggedServiceIdsIterator\BackwardCompatibleIterator;
10+
use LogicException;
911
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
1012
use Symfony\Component\DependencyInjection\ContainerBuilder;
1113
use Symfony\Component\DependencyInjection\Reference;
12-
use LogicException;
1314

1415
/**
1516
* This compiler pass registers eZ Publish search engines indexers.
1617
*/
1718
class RegisterSearchEngineIndexerPass implements CompilerPassInterface
1819
{
20+
public const SEARCH_ENGINE_INDEXER_SERVICE_TAG = 'ezplatform.search_engine.indexer';
21+
public const DEPRECATED_SEARCH_ENGINE_INDEXER_SERVICE_TAG = 'ezpublish.searchEngineIndexer';
22+
1923
/**
2024
* Container service id of the SearchEngineIndexerFactory.
2125
*
@@ -39,20 +43,31 @@ public function process(ContainerBuilder $container)
3943
}
4044

4145
$searchEngineIndexerFactoryDefinition = $container->getDefinition($this->factoryId);
42-
foreach ($container->findTaggedServiceIds('ezpublish.searchEngineIndexer') as $id => $attributes) {
46+
47+
$iterator = new BackwardCompatibleIterator(
48+
$container,
49+
self::SEARCH_ENGINE_INDEXER_SERVICE_TAG,
50+
self::DEPRECATED_SEARCH_ENGINE_INDEXER_SERVICE_TAG
51+
);
52+
53+
foreach ($iterator as $serviceId => $attributes) {
4354
foreach ($attributes as $attribute) {
4455
if (!isset($attribute['alias'])) {
4556
throw new LogicException(
46-
'ezpublish.searchEngineIndexer service tag needs an "alias" attribute to ' .
47-
'identify the search engine.'
57+
sprintf(
58+
'Service "%s" tagged with "%s" or "%s" needs an "alias" attribute to identify the search engine',
59+
$serviceId,
60+
self::SEARCH_ENGINE_INDEXER_SERVICE_TAG,
61+
self::DEPRECATED_SEARCH_ENGINE_INDEXER_SERVICE_TAG
62+
)
4863
);
4964
}
5065

5166
// Register the search engine with the search engine factory
5267
$searchEngineIndexerFactoryDefinition->addMethodCall(
5368
'registerSearchEngineIndexer',
5469
[
55-
new Reference($id),
70+
new Reference($serviceId),
5671
$attribute['alias'],
5772
]
5873
);

eZ/Bundle/EzPublishCoreBundle/DependencyInjection/Compiler/RegisterSearchEnginePass.php

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,20 @@
66
*/
77
namespace eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Compiler;
88

9+
use eZ\Publish\Core\Base\Container\Compiler\TaggedServiceIdsIterator\BackwardCompatibleIterator;
10+
use LogicException;
911
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
1012
use Symfony\Component\DependencyInjection\ContainerBuilder;
1113
use Symfony\Component\DependencyInjection\Reference;
12-
use LogicException;
1314

1415
/**
1516
* This compiler pass will register eZ Publish search engines.
1617
*/
1718
class RegisterSearchEnginePass implements CompilerPassInterface
1819
{
20+
public const SEARCH_ENGINE_SERVICE_TAG = 'ezplatform.search_engine';
21+
public const DEPRECATED_SEATCH_ENGINE_SERVICE_TAG = 'ezpublish.searchEngine';
22+
1923
/**
2024
* Container service id of the SearchEngineFactory.
2125
*
@@ -40,20 +44,30 @@ public function process(ContainerBuilder $container)
4044

4145
$searchEngineFactoryDefinition = $container->getDefinition($this->factoryId);
4246

43-
foreach ($container->findTaggedServiceIds('ezpublish.searchEngine') as $id => $attributes) {
47+
$iterator = new BackwardCompatibleIterator(
48+
$container,
49+
self::SEARCH_ENGINE_SERVICE_TAG,
50+
self::DEPRECATED_SEATCH_ENGINE_SERVICE_TAG
51+
);
52+
53+
foreach ($iterator as $serviceId => $attributes) {
4454
foreach ($attributes as $attribute) {
4555
if (!isset($attribute['alias'])) {
4656
throw new LogicException(
47-
'ezpublish.searchEngine service tag needs an "alias" attribute to ' .
48-
'identify the search engine.'
57+
sprintf(
58+
'Service "%s" tagged with "%s" or "%s" needs an "alias" attribute to identify the search engine',
59+
$serviceId,
60+
self::SEARCH_ENGINE_SERVICE_TAG,
61+
self::DEPRECATED_SEATCH_ENGINE_SERVICE_TAG
62+
)
4963
);
5064
}
5165

5266
// Register the search engine with the search engine factory
5367
$searchEngineFactoryDefinition->addMethodCall(
5468
'registerSearchEngine',
5569
[
56-
new Reference($id),
70+
new Reference($serviceId),
5771
$attribute['alias'],
5872
]
5973
);
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
3+
/**
4+
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
5+
* @license For full copyright and license information view LICENSE file distributed with this source code.
6+
*/
7+
declare(strict_types=1);
8+
9+
namespace eZ\Bundle\EzPublishCoreBundle\Tests\DependencyInjection\Compiler;
10+
11+
use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Compiler\RegisterSearchEngineIndexerPass;
12+
use LogicException;
13+
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractCompilerPassTestCase;
14+
use Symfony\Component\DependencyInjection\ContainerBuilder;
15+
use Symfony\Component\DependencyInjection\Definition;
16+
use Symfony\Component\DependencyInjection\Reference;
17+
18+
final class RegisterSearchEngineIndexerPassTest extends AbstractCompilerPassTestCase
19+
{
20+
private const EXAMPLE_SERVICE_ID = 'app.search_engine';
21+
private const EXAMPLE_ALIAS = 'foo';
22+
23+
protected function setUp(): void
24+
{
25+
parent::setUp();
26+
27+
$this->setDefinition('ezpublish.api.search_engine.indexer.factory', new Definition());
28+
}
29+
30+
protected function registerCompilerPass(ContainerBuilder $container): void
31+
{
32+
$container->addCompilerPass(new RegisterSearchEngineIndexerPass());
33+
}
34+
35+
/**
36+
* @dataProvider tagsProvider
37+
*/
38+
public function testRegisterSearchEngineIndexer(string $tag): void
39+
{
40+
$definition = new Definition();
41+
$definition->addTag($tag, [
42+
'alias' => self::EXAMPLE_ALIAS,
43+
]);
44+
45+
$this->setDefinition(self::EXAMPLE_SERVICE_ID, $definition);
46+
$this->compile();
47+
48+
$this->assertContainerBuilderHasServiceDefinitionWithMethodCall(
49+
'ezpublish.api.search_engine.indexer.factory',
50+
'registerSearchEngineIndexer',
51+
[
52+
new Reference(self::EXAMPLE_SERVICE_ID),
53+
self::EXAMPLE_ALIAS,
54+
]
55+
);
56+
}
57+
58+
/**
59+
* @dataProvider tagsProvider
60+
*/
61+
public function testRegisterSearchEngineIndexerWithoutAliasThrowsLogicException(string $tag): void
62+
{
63+
$this->expectException(LogicException::class);
64+
65+
$definition = new Definition();
66+
$definition->addTag($tag);
67+
68+
$this->setDefinition(self::EXAMPLE_SERVICE_ID, $definition);
69+
$this->compile();
70+
}
71+
72+
public function tagsProvider(): iterable
73+
{
74+
return [
75+
[RegisterSearchEngineIndexerPass::SEARCH_ENGINE_INDEXER_SERVICE_TAG],
76+
[RegisterSearchEngineIndexerPass::DEPRECATED_SEARCH_ENGINE_INDEXER_SERVICE_TAG],
77+
];
78+
}
79+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
3+
/**
4+
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
5+
* @license For full copyright and license information view LICENSE file distributed with this source code.
6+
*/
7+
declare(strict_types=1);
8+
9+
namespace eZ\Bundle\EzPublishCoreBundle\Tests\DependencyInjection\Compiler;
10+
11+
use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Compiler\RegisterSearchEnginePass;
12+
use LogicException;
13+
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractCompilerPassTestCase;
14+
use Symfony\Component\DependencyInjection\ContainerBuilder;
15+
use Symfony\Component\DependencyInjection\Definition;
16+
use Symfony\Component\DependencyInjection\Reference;
17+
18+
final class RegisterSearchEnginePassTest extends AbstractCompilerPassTestCase
19+
{
20+
private const EXAMPLE_SERVICE_ID = 'app.search_engine';
21+
private const EXAMPLE_ALIAS = 'foo';
22+
23+
protected function setUp(): void
24+
{
25+
parent::setUp();
26+
27+
$this->setDefinition('ezpublish.api.search_engine.factory', new Definition());
28+
}
29+
30+
protected function registerCompilerPass(ContainerBuilder $container): void
31+
{
32+
$container->addCompilerPass(new RegisterSearchEnginePass());
33+
}
34+
35+
/**
36+
* @dataProvider tagsProvider
37+
*/
38+
public function testRegisterSearchEngine(string $tag): void
39+
{
40+
$definition = new Definition();
41+
$definition->addTag($tag, [
42+
'alias' => self::EXAMPLE_ALIAS,
43+
]);
44+
45+
$this->setDefinition(self::EXAMPLE_SERVICE_ID, $definition);
46+
$this->compile();
47+
48+
$this->assertContainerBuilderHasServiceDefinitionWithMethodCall(
49+
'ezpublish.api.search_engine.factory',
50+
'registerSearchEngine',
51+
[
52+
new Reference(self::EXAMPLE_SERVICE_ID),
53+
self::EXAMPLE_ALIAS,
54+
]
55+
);
56+
}
57+
58+
/**
59+
* @dataProvider tagsProvider
60+
*/
61+
public function testRegisterSearchEngineWithoutAliasThrowsLogicException(string $tag): void
62+
{
63+
$this->expectException(LogicException::class);
64+
65+
$definition = new Definition();
66+
$definition->addTag($tag);
67+
68+
$this->setDefinition(self::EXAMPLE_SERVICE_ID, $definition);
69+
$this->compile();
70+
}
71+
72+
public function tagsProvider(): iterable
73+
{
74+
return [
75+
[RegisterSearchEnginePass::SEARCH_ENGINE_SERVICE_TAG],
76+
[RegisterSearchEnginePass::DEPRECATED_SEATCH_ENGINE_SERVICE_TAG],
77+
];
78+
}
79+
}

0 commit comments

Comments
 (0)