DomainServicesPass::process()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 18
rs 9.4285
cc 2
eloc 12
nc 2
nop 1
1
<?php
2
3
/*
4
 * This file is part of the BenGorFile package.
5
 *
6
 * (c) Beñat Espiña <[email protected]>
7
 * (c) Gorka Laucirica <[email protected]>
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
namespace BenGorFile\FileBundle\DependencyInjection\Compiler;
14
15
use BenGorFile\File\Infrastructure\Domain\Model\FileFactory;
16
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
17
use Symfony\Component\DependencyInjection\ContainerBuilder;
18
use Symfony\Component\DependencyInjection\Definition;
19
20
/**
21
 * Register domain model services compiler pass.
22
 *
23
 * Service declaration via PHP allows
24
 * more flexibility with easy customization.
25
 *
26
 * @author Beñat Espiña <[email protected]>
27
 */
28
class DomainServicesPass implements CompilerPassInterface
29
{
30
    /**
31
     * {@inheritdoc}
32
     */
33
    public function process(ContainerBuilder $container)
34
    {
35
        $config = $container->getParameter('bengor_file.config');
36
        foreach ($config['file_class'] as $key => $file) {
37
            $container->setDefinition(
38
                'bengor.file.infrastructure.domain.model.' . $key . '_factory',
39
                (new Definition(
40
                    FileFactory::class, [
41
                        $file['class'],
42
                    ]
43
                ))->setPublic(false)
44
            );
45
            $container->setAlias(
46
                'bengor_file.' . $key . '.factory',
47
                'bengor.file.infrastructure.domain.model.' . $key . '_factory'
48
            );
49
        }
50
    }
51
}
52