Completed
Pull Request — master (#22)
by Sergey
23:00 queued 08:02
created

DI::init()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
namespace Isswp101\Persimmon\DI;
4
5
use Elasticsearch\ClientBuilder;
6
use Isswp101\Persimmon\Repository\ElasticsearchRepository;
7
8
final class DI
9
{
10
    const ELASTICSEARCH = 'elasticsearch';
11
12
    private static $containers = [];
13
14
    private static function init(): array
15
    {
16
        return DI::$containers = [
17
            DI::ELASTICSEARCH => function () {
18
                $client = ClientBuilder::create()->build();
19
                return new Container(new ElasticsearchRepository($client));
20
            }
21
        ];
22
    }
23
24
    public static function make(string $name): Container
25
    {
26
        $containers = !DI::$containers ? DI::init() : DI::$containers;
27
        return $containers[$name]();
28
    }
29
}