Completed
Push — master ( 513898...595f7b )
by Łukasz
29:17
created

PlaceholderProviderPass   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 26
rs 10
c 0
b 0
f 0
wmc 5
lcom 0
cbo 3

1 Method

Rating   Name   Duplication   Size   Complexity  
B process() 0 20 5
1
<?php
2
3
/**
4
 * This file is part of the eZ Publish Kernel package.
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\Bundle\EzPublishCoreBundle\DependencyInjection\Compiler;
10
11
use LogicException;
12
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
13
use Symfony\Component\DependencyInjection\ContainerBuilder;
14
use Symfony\Component\DependencyInjection\Reference;
15
16
class PlaceholderProviderPass implements CompilerPassInterface
17
{
18
    const TAG_NAME = 'ezpublish.placeholder_provider';
19
    const REGISTRY_DEFINITION_ID = 'ezpublish.image_alias.imagine.placeholder_provider.registry';
20
21
    public function process(ContainerBuilder $container)
22
    {
23
        if (!$container->hasDefinition(self::REGISTRY_DEFINITION_ID)) {
24
            return;
25
        }
26
27
        $definition = $container->getDefinition(self::REGISTRY_DEFINITION_ID);
28
        foreach ($container->findTaggedServiceIds(self::TAG_NAME) as $id => $attributes) {
29
            foreach ($attributes as $attribute) {
30
                if (!isset($attribute['type'])) {
31
                    throw new LogicException(self::TAG_NAME . ' service tag needs a "type" attribute to identify the placeholder provider type. None given.');
32
                }
33
34
                $definition->addMethodCall(
35
                    'addProvider',
36
                    [$attribute['type'], new Reference($id)]
37
                );
38
            }
39
        }
40
    }
41
}
42