Passed
Pull Request — main (#140)
by Daniel
07:55 queued 02:24
created

FlysystemCompilerPass::process()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 10
nc 3
nop 1
dl 0
loc 12
ccs 0
cts 10
cp 0
crap 12
rs 9.9332
c 1
b 0
f 0
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