|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* File containing the CriteriaConverterPass class. |
|
5
|
|
|
* |
|
6
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
|
7
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
|
8
|
|
|
*/ |
|
9
|
|
|
namespace eZ\Publish\Core\Base\Container\Compiler\Search\Legacy; |
|
10
|
|
|
|
|
11
|
|
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
|
12
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
13
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
|
14
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* This compiler pass will register Legacy Search Engine criterion handlers. |
|
18
|
|
|
*/ |
|
19
|
|
View Code Duplication |
class CriteriaConverterPass implements CompilerPassInterface |
|
|
|
|
|
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container |
|
23
|
|
|
*/ |
|
24
|
|
|
public function process(ContainerBuilder $container) |
|
25
|
|
|
{ |
|
26
|
|
|
if ( |
|
27
|
|
|
!$container->hasDefinition('ezpublish.search.legacy.gateway.criteria_converter.content') && |
|
28
|
|
|
!$container->hasDefinition('ezpublish.search.legacy.gateway.criteria_converter.location') |
|
29
|
|
|
) { |
|
30
|
|
|
return; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
if ($container->hasDefinition('ezpublish.search.legacy.gateway.criteria_converter.content')) { |
|
34
|
|
|
$criteriaConverterContent = $container->getDefinition('ezpublish.search.legacy.gateway.criteria_converter.content'); |
|
35
|
|
|
|
|
36
|
|
|
$contentHandlers = $container->findTaggedServiceIds('ezpublish.search.legacy.gateway.criterion_handler.content'); |
|
37
|
|
|
|
|
38
|
|
|
$this->addHandlers($criteriaConverterContent, $contentHandlers); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
if ($container->hasDefinition('ezpublish.search.legacy.gateway.criteria_converter.location')) { |
|
42
|
|
|
$criteriaConverterLocation = $container->getDefinition('ezpublish.search.legacy.gateway.criteria_converter.location'); |
|
43
|
|
|
|
|
44
|
|
|
$locationHandlers = $container->findTaggedServiceIds('ezpublish.search.legacy.gateway.criterion_handler.location'); |
|
45
|
|
|
|
|
46
|
|
|
$this->addHandlers($criteriaConverterLocation, $locationHandlers); |
|
47
|
|
|
} |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
protected function addHandlers(Definition $definition, $handlers) |
|
51
|
|
|
{ |
|
52
|
|
|
foreach ($handlers as $id => $attributes) { |
|
53
|
|
|
$definition->addMethodCall('addHandler', array(new Reference($id))); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.