Passed
Push — main ( 964870...8374cd )
by Daniel
08:40 queued 03:10
created

FlysystemCompilerPass   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 12 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\FilesystemProvider;
18
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
19
use Symfony\Component\DependencyInjection\ContainerBuilder;
20
use Symfony\Component\DependencyInjection\Definition;
21
use Symfony\Component\DependencyInjection\Reference;
22
23
/**
24
 * @author Daniel West <[email protected]>
25
 */
26
class FlysystemCompilerPass implements CompilerPassInterface
27
{
28
    public function process(ContainerBuilder $container): void
29
    {
30
        $adapters = $container->findTaggedServiceIds(FilesystemProvider::FILESYSTEM_ADAPTER_TAG);
31
        foreach ($adapters as $adaperId => $tags) {
32
            foreach ($tags as $attributes) {
33
                $definition = new Definition();
34
                $definition
35
                    ->setClass(Filesystem::class)
36
                    ->setFactory([new Reference(FilesystemProvider::class), 'getFilesystem'])
37
                    ->addArgument($attributes['alias']);
38
                $serviceName = sprintf('api_components.filesystem.%s', $attributes['alias']);
39
                $container->setDefinition($serviceName, $definition);
40
            }
41
        }
42
    }
43
}
44