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

FieldValueConverterRegistryPass   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
dl 0
loc 46
rs 10
c 0
b 0
f 0
wmc 6
lcom 0
cbo 4

1 Method

Rating   Name   Duplication   Size   Complexity  
B process() 0 37 6
1
<?php
2
3
/**
4
 * File containing the FieldValueConverterRegistryPass 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\Storage\Legacy;
10
11
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
12
use Symfony\Component\DependencyInjection\ContainerBuilder;
13
use Symfony\Component\DependencyInjection\Exception\LogicException;
14
use Symfony\Component\DependencyInjection\Reference;
15
16
/**
17
 * This compiler pass will register Legacy Storage field value converters.
18
 */
19
class FieldValueConverterRegistryPass implements CompilerPassInterface
20
{
21
    public const EZPUBLISH_STORAGE_ENGINE_LEGACY_CONVERTER = 'ezpublish.storageEngine.legacy.converter';
22
    public const EZPLATFORM_FIELD_TYPE_LEGACY_STORAGE_CONVERTER = 'ezplatform.field_type.legacy_storage.converter';
23
24
    /**
25
     * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
26
     */
27
    public function process(ContainerBuilder $container)
28
    {
29
        if (!$container->hasDefinition('ezpublish.persistence.legacy.field_value_converter.registry')) {
30
            return;
31
        }
32
33
        $registry = $container->getDefinition('ezpublish.persistence.legacy.field_value_converter.registry');
34
35
        $ezpublishFieldTypeStorageConverterTags = $container->findTaggedServiceIds(self::EZPUBLISH_STORAGE_ENGINE_LEGACY_CONVERTER);
36
        foreach ($ezpublishFieldTypeStorageConverterTags as $ezpublishFieldTypeStorageConverterTag) {
37
            @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...
38
                sprintf(
39
                    '`%s` service tag is deprecated and will be removed in eZ Platform 4.0. Please use `%s` instead.',
40
                    self::EZPUBLISH_STORAGE_ENGINE_LEGACY_CONVERTER,
41
                    self::EZPLATFORM_FIELD_TYPE_LEGACY_STORAGE_CONVERTER
42
                ),
43
                E_USER_DEPRECATED
44
            );
45
        }
46
        $ezplatformFieldTypeStorageConverterTags = $container->findTaggedServiceIds(self::EZPLATFORM_FIELD_TYPE_LEGACY_STORAGE_CONVERTER);
47
        $storageConverterFieldTypesTags = array_merge($ezpublishFieldTypeStorageConverterTags, $ezplatformFieldTypeStorageConverterTags);
48
        foreach ($storageConverterFieldTypesTags as $id => $attributes) {
49
            foreach ($attributes as $attribute) {
50
                if (!isset($attribute['alias'])) {
51
                    throw new LogicException('ezpublish.storageEngine.legacy.converter or ezplatform.field_type.legacy_storage.converter service tag needs an "alias" attribute to identify the field type. None given.');
52
                }
53
54
                $registry->addMethodCall(
55
                    'register',
56
                    array(
57
                        $attribute['alias'],
58
                        new Reference($id),
59
                    )
60
                );
61
            }
62
        }
63
    }
64
}
65