ModelFactoryCollectionCompilerPass::process()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 6
nc 3
nop 1
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Xsolve\ModelFactoryBundle\DependencyInjection\CompilerPass;
4
5
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
use Symfony\Component\DependencyInjection\Reference;
8
9
class ModelFactoryCollectionCompilerPass implements CompilerPassInterface
10
{
11
    const TAG_NAME = 'xsolve.model_factory_bundle.model_factory';
12
    const ATTRIBUTE_NAME_MODEL_FACTORY_COLLECTION_SERVICE_ID = 'model-factory-collection-id';
13
14
    /**
15
     * @param ContainerBuilder $container
16
     */
17
    public function process(ContainerBuilder $container)
18
    {
19
        $modelFactoryServiceIdToTags = $container->findTaggedServiceIds(self::TAG_NAME);
20
        foreach ($modelFactoryServiceIdToTags as $modelFactoryServiceId => $tags) {
21
            foreach ($tags as $tag) {
22
                $container
23
                    ->getDefinition($tag[self::ATTRIBUTE_NAME_MODEL_FACTORY_COLLECTION_SERVICE_ID])
24
                    ->addMethodCall('addModelFactory', [new Reference($modelFactoryServiceId)]);
25
            }
26
        }
27
    }
28
}
29