SeoGeneratorPass::process()   B
last analyzed

Complexity

Conditions 6
Paths 6

Size

Total Lines 22
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 22
rs 8.6737
c 0
b 0
f 0
cc 6
eloc 15
nc 6
nop 1
1
<?php
2
3
namespace Leogout\Bundle\SeoBundle\DependencyInjection\Compiler;
4
5
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
8
/**
9
 * Description of SeoGeneratorPass.
10
 *
11
 * @author: leogout
12
 */
13
class SeoGeneratorPass implements CompilerPassInterface
14
{
15
    /**
16
     * {@inheritdoc}
17
     */
18
    public function process(ContainerBuilder $container)
19
    {
20
        $definition = $container->getDefinition('leogout_seo.provider.generator');
21
        $taggedServices = $container->findTaggedServiceIds('leogout_seo.generator');
22
        $seoGenerators = [];
23
        foreach ($taggedServices as $id => $tags) {
24
            $generatorDefinition = $container->getDefinition($id);
25
            if (!$generatorDefinition->isPublic()) {
26
                throw new \InvalidArgumentException(sprintf('Seo generator services must be public, but "%s" is not.', $id));
27
            }
28
            if ($generatorDefinition->isAbstract()) {
29
                throw new \InvalidArgumentException(sprintf('Seo generator services cannot be abstract but "%s" is.', $id));
30
            }
31
            foreach ($tags as $attributes) {
32
                if (empty($attributes['alias'])) {
33
                    throw new \InvalidArgumentException(sprintf('Tag "leogout_seo.generator" requires an "alias" field in "%s" definition.', $id));
34
                }
35
                $seoGenerators[$attributes['alias']] = $container->findDefinition($id);
36
            }
37
        }
38
        $definition->replaceArgument(0, $seoGenerators);
39
    }
40
}
41