GaufretteFilesystemPass   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 3
c 2
b 0
f 0
lcom 0
cbo 3
dl 0
loc 41
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B process() 0 35 3
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\GaufretteFilesystemBridgeBundle\DependencyInjection\Compiler;
14
15
use BenGorFile\GaufretteFilesystemBridge\Infrastructure\Domain\Model\GaufretteFilesystem;
16
use Gaufrette\Filesystem;
17
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
18
use Symfony\Component\DependencyInjection\ContainerBuilder;
19
use Symfony\Component\DependencyInjection\Definition;
20
use Symfony\Component\DependencyInjection\Reference;
21
22
/**
23
 * Register Gaufrette filesystem services compiler pass.
24
 *
25
 * Service declaration via PHP allows more
26
 * flexibility with customization extend files.
27
 *
28
 * @author Beñat Espiña <[email protected]>
29
 */
30
class GaufretteFilesystemPass implements CompilerPassInterface
31
{
32
    /**
33
     * {@inheritdoc}
34
     */
35
    public function process(ContainerBuilder $container)
36
    {
37
        $config = $container->getParameter('bengor_file.config');
38
        foreach ($config['file_class'] as $key => $file) {
39
            if ('gaufrette' !== $file['storage']) {
40
                continue;
41
            }
42
43
            $container->setDefinition(
44
                'bengor_file.filesystem.gaufrette.' . $key,
45
                (new Definition(
46
                    Filesystem::class, [
47
                        $file['upload_destination'],
48
                    ]
49
                ))->setFactory([
50
                    new Reference('knp_gaufrette.filesystem_map'),
51
                    'get',
52
                ])
53
            )->setPublic(false);
54
55
            $container->setDefinition(
56
                'bengor.file.infrastructure.domain.model.' . $key . '_filesystem',
57
                new Definition(
58
                    GaufretteFilesystem::class, [
59
                        new Reference('bengor_file.filesystem.gaufrette.' . $key),
60
                    ]
61
                )
62
            )->setPublic(false);
63
64
            $container->setAlias(
65
                'bengor_file.' . $key . '.filesystem',
66
                'bengor.file.infrastructure.domain.model.' . $key . '_filesystem'
67
            );
68
        }
69
    }
70
}
71