Completed
Push — master ( bca2c3...1c94f2 )
by Dmitry
03:47
created

TarantoolProvider   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 6
dl 0
loc 71
ccs 30
cts 30
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A register() 0 56 3
1
<?php
2
3
namespace Basis\Provider;
4
5
use Basis\Config;
6
use Basis\Filesystem;
7
use League\Container\ServiceProvider\AbstractServiceProvider;
8
use Tarantool\Client\Client as TarantoolClient;
9
use Tarantool\Client\Connection\Connection;
10
use Tarantool\Client\Connection\StreamConnection;
11
use Tarantool\Client\Packer\Packer;
12
use Tarantool\Client\Packer\PurePacker;
13
use Tarantool\Mapper\Bootsrap;
14
use Tarantool\Mapper\Client;
15
use Tarantool\Mapper\Mapper;
16
use Tarantool\Mapper\Plugin\Annotation;
17
use Tarantool\Mapper\Plugin\Sequence;
18
use Tarantool\Mapper\Plugin\Spy;
19
use Tarantool\Mapper\Schema;
20
21
class TarantoolProvider extends AbstractServiceProvider
22
{
23
    protected $provides = [
24
        Bootsrap::class,
25
        Client::class,
26
        Connection::class,
27
        Mapper::class,
28
        Packer::class,
29
        Schema::class,
30
        Spy::class,
31
        StreamConnection::class,
32
        TarantoolClient::class,
33
    ];
34
35 3
    public function register()
36
    {
37
        $this->container->share(Bootsrap::class, function () {
38
            return $this->container->get(Mapper::class)->getBootstrap();
39 3
        });
40
41
        $this->getContainer()->share(Client::class, function () {
42 3
            return new Client(
43 3
                $this->getContainer()->get(Connection::class),
44 3
                $this->getContainer()->get(Packer::class)
45
            );
46 3
        });
47
48
        $this->getContainer()->share(Connection::class, function () {
49 3
            return $this->getContainer()->get(StreamConnection::class);
50 3
        });
51
52
        $this->getContainer()->share(Mapper::class, function () {
53 3
            $mapper = new Mapper($this->getContainer()->get(Client::class));
54
55 3
            $annotation = $mapper->addPlugin(Annotation::class);
56
57 3
            $filesystem = $this->getContainer()->get(Filesystem::class);
58 3
            foreach ($filesystem->listClasses('Entity') as $class) {
59 3
                $annotation->register($class);
60
            }
61 3
            foreach ($filesystem->listClasses('Repository') as $class) {
62 3
                $annotation->register($class);
63
            }
64
65 3
            $mapper->addPlugin(Sequence::class);
66 3
            $mapper->addPlugin(Spy::class);
67 3
            return $mapper;
68 3
        });
69
70
        $this->getContainer()->share(Spy::class, function () {
71 1
            return $this->getContainer()->get(Mapper::class)->getPlugin(Spy::class);
72 3
        });
73
74
        $this->getContainer()->share(Packer::class, function () {
75 3
            return new PurePacker();
76 3
        });
77
78
        $this->getContainer()->share(Schema::class, function () {
79
            return $this->getContainer()->get(Mapper::class)->getSchema();
80 3
        });
81
82
        $this->getContainer()->share(StreamConnection::class, function () {
83 3
            $config = $this->getContainer()->get(Config::class);
84 3
            return new StreamConnection($config['tarantool']);
85 3
        });
86
87 3
        $this->getContainer()->share(TarantoolClient::class, function () {
88
            return $this->getContainer()->get(Client::class);
89 3
        });
90 3
    }
91
}
92