ElasticPlugin::createElasticClientFactory()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 2
b 0
f 0
nc 1
nop 0
dl 0
loc 5
ccs 4
cts 4
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\Elastic;
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\Elastic\Client\Factory\ElasticClientFactory;
22
use Micro\Plugin\Elastic\Client\Factory\ElasticClientFactoryInterface;
23
use Micro\Plugin\Elastic\Configuration\ElasticPluginConfigurationInterface;
24
use Micro\Plugin\Elastic\Facade\ElasticFacade;
25
use Micro\Plugin\Elastic\Facade\ElasticFacadeInterface;
26
use Micro\Plugin\Logger\Facade\LoggerFacadeInterface;
27
use Micro\Plugin\Logger\LoggerPlugin;
28
29
/**
30
 * @method ElasticPluginConfigurationInterface configuration()
31
 */
32
class ElasticPlugin implements DependencyProviderInterface, ConfigurableInterface, PluginDependedInterface
33
{
34
    use PluginConfigurationTrait;
35
36
    /**
37
     * @var LoggerFacadeInterface
38
     */
39
    private LoggerFacadeInterface $loggerFacade;
40
41
    /**
42
     * {@inheritDoc}
43
     */
44 1
    public function provideDependencies(Container $container): void
45
    {
46 1
        $container->register(ElasticFacadeInterface::class, function (
47 1
            LoggerFacadeInterface $loggerFacade
48 1
        ) {
49 1
            $this->loggerFacade = $loggerFacade;
50
51 1
            return $this->createFacade();
52 1
        });
53
    }
54
55
    /**
56
     * @return ElasticClientFactoryInterface
57
     */
58 1
    public function createElasticClientFactory(): ElasticClientFactoryInterface
59
    {
60 1
        return new ElasticClientFactory(
61 1
            $this->configuration(),
62 1
            $this->loggerFacade
63 1
        );
64
    }
65
66
    /**
67
     * @return ElasticFacadeInterface
68
     */
69 1
    public function createFacade(): ElasticFacadeInterface
70
    {
71 1
        return new ElasticFacade(
72 1
            $this->createElasticClientFactory()
73 1
        );
74
    }
75
76 1
    public function getDependedPlugins(): iterable
77
    {
78 1
        return [
79 1
            LoggerPlugin::class,
80 1
        ];
81
    }
82
}
83