Completed
Push — EZP-30462 ( 48a474 )
by
unknown
17:07
created

FieldRegistryPass::process()   B

Complexity

Conditions 6
Paths 9

Size

Total Lines 40

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
nc 9
nop 1
dl 0
loc 40
rs 8.6577
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * File containing the FieldRegistryPass 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;
10
11
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
12
use Symfony\Component\DependencyInjection\ContainerBuilder;
13
use Symfony\Component\DependencyInjection\Reference;
14
use LogicException;
15
16
/**
17
 * This compiler pass will register eZ Publish indexable field types.
18
 */
19
class FieldRegistryPass implements CompilerPassInterface
20
{
21
    public const EZPUBLISH_FIELD_TYPE_INDEXABLE = 'ezpublish.fieldType.indexable';
22
    public const EZPLATFORM_FIELD_TYPE_INDEXABLE = 'ezplatform.field_type.indexable';
23
24
    /**
25
     * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
26
     *
27
     * @throws \LogicException
28
     */
29
    public function process(ContainerBuilder $container)
30
    {
31
        if (!$container->hasDefinition('ezpublish.search.common.field_registry')) {
32
            return;
33
        }
34
35
        $fieldRegistryDefinition = $container->getDefinition('ezpublish.search.common.field_registry');
36
37
        $ezpublishIndexableFieldTypeTags = $container->findTaggedServiceIds(self::EZPUBLISH_FIELD_TYPE_INDEXABLE);
38
        foreach ($ezpublishIndexableFieldTypeTags as $ezpublishIndexableFieldTypeTag) {
39
            @trigger_error(
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
40
                sprintf(
41
                    '`%s` service tag is deprecated and will be removed in eZ Platform 4.0. Please use `%s`. instead.',
42
                    self::EZPUBLISH_FIELD_TYPE_INDEXABLE,
43
                    self::EZPLATFORM_FIELD_TYPE_INDEXABLE
44
                ),
45
                E_USER_DEPRECATED
46
            );
47
        }
48
        $ezplatformIndexableFieldTypeTags = $container->findTaggedServiceIds(self::EZPLATFORM_FIELD_TYPE_INDEXABLE);
49
        $fieldTypesTags = array_merge($ezpublishIndexableFieldTypeTags, $ezplatformIndexableFieldTypeTags);
50
        foreach ($fieldTypesTags as $id => $attributes) {
51
            foreach ($attributes as $attribute) {
52
                if (!isset($attribute['alias'])) {
53
                    throw new LogicException(
54
                        'ezpublish.fieldType.indexable or ezplatform.field_type.indexable service tag needs an "alias" attribute to ' .
55
                        'identify the indexable field type. None given.'
56
                    );
57
                }
58
59
                $fieldRegistryDefinition->addMethodCall(
60
                    'registerType',
61
                    array(
62
                        $attribute['alias'],
63
                        new Reference($id),
64
                    )
65
                );
66
            }
67
        }
68
    }
69
}
70