Completed
Push — master ( 382c80...0287cb )
by Dmitry
04:23
created

TarantoolProvider   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 72
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 72
ccs 28
cts 28
cp 1
rs 10
c 0
b 0
f 0

1 Method

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