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
|
|
|
} |