Passed
Push — master ( 03c1a4...a8d346 )
by Stanislau
01:22 queued 14s
created

DTOPlugin::createDtoValidatorFacade()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
ccs 2
cts 2
cp 1
crap 1
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\DTO;
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\Kernel\App\AppKernelInterface;
22
use Micro\Library\DTO\SerializerFacadeDefault;
23
use Micro\Library\DTO\SerializerFacadeInterface;
24
use Micro\Library\DTO\ValidatorFacadeDefault;
25
use Micro\Library\DTO\ValidatorFacadeInterface;
26
use Micro\Plugin\DTO\Business\FileLocator\FileLocatorFactory;
27
use Micro\Plugin\DTO\Business\FileLocator\FileLocatorFactoryInterface;
28
use Micro\Plugin\DTO\Business\Generator\GeneratorFactory;
29
use Micro\Plugin\DTO\Business\Generator\GeneratorFactoryInterface;
30
use Micro\Plugin\DTO\Facade\DTOFacade;
31
use Micro\Plugin\DTO\Facade\DTOFacadeInterface;
32
use Micro\Plugin\Logger\Facade\LoggerFacadeInterface;
33
use Micro\Plugin\Logger\LoggerPlugin;
34
35
/**
36
 * @method DTOPluginConfigurationInterface configuration()
37
 */
38
class DTOPlugin implements DependencyProviderInterface, ConfigurableInterface, PluginDependedInterface
39
{
40
    use PluginConfigurationTrait;
41
42
    private AppKernelInterface $kernel;
43
44
    private LoggerFacadeInterface $loggerFacade;
45
46
    /**
47
     * {@inheritDoc}
48
     */
49 1
    public function provideDependencies(Container $container): void
50
    {
51 1
        $container->register(DTOFacadeInterface::class, function (
52 1
            AppKernelInterface $kernel,
53 1
            LoggerFacadeInterface $loggerFacade
54 1
        ) {
55 1
            $this->kernel = $kernel;
56 1
            $this->loggerFacade = $loggerFacade;
57
58 1
            return $this->createDTOGeneratorFacade();
59 1
        });
60
61 1
        $container->register(SerializerFacadeInterface::class, function () {
62 1
            return $this->createDTOSerializerFacade();
63 1
        });
64
65 1
        $container->register(ValidatorFacadeInterface::class, function () {
66 1
            return $this->createDtoValidatorFacade();
67 1
        });
68
    }
69
70 1
    public function getDependedPlugins(): iterable
71
    {
72 1
        return [
73 1
            LoggerPlugin::class,
74 1
        ];
75
    }
76
77
    /**
78
     * @return SerializerFacadeInterface
79
     */
80 1
    protected function createDTOSerializerFacade(): SerializerFacadeInterface
81
    {
82 1
        return new SerializerFacadeDefault();
83
    }
84
85 1
    protected function createDtoValidatorFacade(): ValidatorFacadeInterface
86
    {
87 1
        return new ValidatorFacadeDefault();
88
    }
89
90
    /**
91
     * @return DTOFacadeInterface
92
     */
93 1
    protected function createDTOGeneratorFacade(): DTOFacadeInterface
94
    {
95 1
        return new DTOFacade($this->createGeneratorFactory());
96
    }
97
98
    /**
99
     * @return GeneratorFactoryInterface
100
     */
101 1
    protected function createGeneratorFactory(): GeneratorFactoryInterface
102
    {
103 1
        return new GeneratorFactory(
104 1
            $this->createFileLocatorFactory(),
105 1
            $this->configuration(),
106 1
            $this->loggerFacade
107 1
        );
108
    }
109
110
    /**
111
     * @return FileLocatorFactoryInterface
112
     */
113 1
    protected function createFileLocatorFactory(): FileLocatorFactoryInterface
114
    {
115 1
        return new FileLocatorFactory(
116 1
            appKernel: $this->kernel,
117 1
            DTOPluginConfiguration: $this->configuration()
118 1
        );
119
    }
120
}
121