createAwsFacadeDecorator()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 6
ccs 5
cts 5
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 *  This file is part of the Micro framework package.
7
 *
8
 *  (c) Stanislau Komar <[email protected]>
9
 *
10
 *  For the full copyright and license information, please view the LICENSE
11
 *  file that was distributed with this source code.
12
 */
13
14
namespace Micro\Plugin\Filesystem\Adapter\Aws;
15
16
use Micro\Component\DependencyInjection\Container;
17
use Micro\Framework\Kernel\Plugin\ConfigurableInterface;
18
use Micro\Framework\Kernel\Plugin\DependencyProviderInterface;
19
use Micro\Framework\Kernel\Plugin\PluginConfigurationTrait;
20
use Micro\Framework\Kernel\Plugin\PluginDependedInterface;
21
use Micro\Plugin\Filesystem\Adapter\Aws\Business\Adapter\AdapterFactory;
22
use Micro\Plugin\Filesystem\Adapter\Aws\Configuration\FilesystemS3AdapterPluginConfigurationInterface;
23
use Micro\Plugin\Filesystem\Adapter\Aws\Decorator\AwsFilesystemFacadeDecorator;
24
use Micro\Plugin\Filesystem\Business\Adapter\AdapterFactoryInterface;
25
use Micro\Plugin\Filesystem\Business\FS\FsFactory;
26
use Micro\Plugin\Filesystem\Business\FS\FsFactoryInterface;
27
use Micro\Plugin\Filesystem\Facade\FilesystemFacadeInterface;
28
use Micro\Plugin\Filesystem\FilesystemPlugin;
29
30
/**
31
 * @method FilesystemS3AdapterPluginConfigurationInterface configuration()
32
 */
33
class FilesystemS3AdapterPlugin implements DependencyProviderInterface, ConfigurableInterface, PluginDependedInterface
34
{
35
    use PluginConfigurationTrait;
36
37
    /**
38
     * {@inheritDoc}
39
     */
40 1
    public function provideDependencies(Container $container): void
41
    {
42 1
        $container->decorate(FilesystemFacadeInterface::class, function (
43 1
            FilesystemFacadeInterface $filesystemFacade
44 1
        ): FilesystemFacadeInterface {
45 1
            return $this->createAwsFacadeDecorator($filesystemFacade);
46 1
        });
47
    }
48
49 1
    public function getDependedPlugins(): iterable
50
    {
51 1
        return [
52 1
            FilesystemPlugin::class,
53 1
        ];
54
    }
55
56
    /**
57
     * @return AdapterFactoryInterface
58
     */
59 1
    protected function createAdapterFactory(): AdapterFactoryInterface
60
    {
61 1
        return new AdapterFactory();
62
    }
63
64
    /**
65
     * @return FsFactoryInterface
66
     */
67 1
    protected function createFilesystemFactory(): FsFactoryInterface
68
    {
69 1
        return new FsFactory(
70 1
            $this->configuration(),
71 1
            $this->createAdapterFactory(),
72 1
        );
73
    }
74
75
    /**
76
     * @param FilesystemFacadeInterface $filesystemFacade
77
     *
78
     * @return FilesystemFacadeInterface
79
     */
80 1
    protected function createAwsFacadeDecorator(FilesystemFacadeInterface $filesystemFacade): FilesystemFacadeInterface
81
    {
82 1
        return new AwsFilesystemFacadeDecorator(
83 1
            $filesystemFacade,
84 1
            $this->createFilesystemFactory(),
85 1
            $this->configuration(),
86 1
        );
87
    }
88
}
89