FlysystemCompilerPass   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
dl 0
loc 19
ccs 0
cts 16
cp 0
rs 10
c 1
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 17 3
1
<?php
2
3
/*
4
 * This file is part of the Silverback API Components Bundle Project
5
 *
6
 * (c) Daniel West <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Silverback\ApiComponentsBundle\DependencyInjection\CompilerPass;
15
16
use League\Flysystem\Filesystem;
17
use Silverback\ApiComponentsBundle\Flysystem\FilesystemFactory;
18
use Silverback\ApiComponentsBundle\Flysystem\FilesystemProvider;
19
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
20
use Symfony\Component\DependencyInjection\ContainerBuilder;
21
use Symfony\Component\DependencyInjection\Definition;
22
use Symfony\Component\DependencyInjection\Reference;
23
24
/**
25
 * @author Daniel West <[email protected]>
26
 */
27
class FlysystemCompilerPass implements CompilerPassInterface
28
{
29
    public function process(ContainerBuilder $container): void
30
    {
31
        $adapters = $container->findTaggedServiceIds(FilesystemProvider::FILESYSTEM_ADAPTER_TAG);
32
        foreach ($adapters as $adaperId => $tags) {
33
            foreach ($tags as $attributes) {
34
                $definition = new Definition();
35
                $definition
36
                    ->setClass(Filesystem::class)
37
                    ->setFactory([new Reference(FilesystemFactory::class), 'create'])
38
                    ->setArguments([
39
                        $attributes['alias'],
40
                        $attributes['config'] ?? [],
41
                    ]);
42
                $serviceName = sprintf('api_components.filesystem.%s', $attributes['alias']);
43
                $container
44
                    ->setDefinition($serviceName, $definition)
45
                    ->addTag(FilesystemProvider::FILESYSTEM_TAG, ['alias' => $attributes['alias']]);
46
            }
47
        }
48
    }
49
}
50