Completed
Push — master ( 717b1b...de6dfe )
by Dmitry
06:37
created

Tarantool::register()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 40
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 40
ccs 0
cts 11
cp 0
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 20
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Basis\Providers;
4
5
use League\Container\ServiceProvider\AbstractServiceProvider;
6
use Tarantool\Client\Client as TarantoolClient;
7
use Tarantool\Client\Connection\Connection;
8
use Tarantool\Client\Connection\StreamConnection;
9
use Tarantool\Client\Packer\Packer;
10
use Tarantool\Client\Packer\PurePacker;
11
use Tarantool\Mapper\Bootsrap;
12
use Tarantool\Mapper\Client;
13
use Tarantool\Mapper\Mapper;
14
use Tarantool\Mapper\Schema;
15
16
17
class Tarantool extends AbstractServiceProvider
18
{
19
    protected $provides = [
20
        Bootsrap::class,
21
        Client::class,
22
        Connection::class,
23
        Mapper::class,
24
        Packer::class,
25
        Schema::class,
26
        StreamConnection::class,
27
        TarantoolClient::class,
28
    ];
29
30
    public function register()
31
    {
32
        $this->container->share(Bootsrap::class, function() {
33
            return $this->container->get(Mapper::class)->getBootstrap();
34
        });
35
36
        $this->getContainer()->share(Client::class, function () {
37
            return new Client(
38
                $this->getContainer()->get(Connection::class),
39
                $this->getContainer()->get(Packer::class)
40
            );
41
        });
42
43
        $this->getContainer()->share(Connection::class, function () {
44
            return $this->getContainer()->get(StreamConnection::class);
45
        });
46
47
        $this->getContainer()->share(Mapper::class, function () {
48
            return new Mapper(
49
                $this->getContainer()->get(Client::class)
50
            );
51
        });
52
53
        $this->getContainer()->share(Packer::class, function () {
54
            return new PurePacker();
55
        });
56
57
        $this->getContainer()->share(Schema::class, function () {
58
            return $this->getContainer()->get(Mapper::class)->getSchema();
59
        });
60
61
        $this->getContainer()->share(StreamConnection::class, function () {
62
            return new StreamConnection('tcp://'.getenv('TARANTOOL_SERVICE_HOST').':'.getenv('TARANTOOL_SERVICE_PORT'));
63
        });
64
65
        $this->getContainer()->share(TarantoolClient::class, function() {
66
            return $this->getContainer()->get(Client::class);
67
        });
68
69
    }
70
}