1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Basis\Provider; |
4
|
|
|
|
5
|
|
|
use Basis\Service; |
6
|
|
|
use League\Container\ServiceProvider\AbstractServiceProvider; |
7
|
|
|
use Tarantool\Client\Connection\StreamConnection; |
8
|
|
|
use Tarantool\Client\Packer\PurePacker; |
9
|
|
|
use Tarantool\Client\Request\DeleteRequest; |
10
|
|
|
use Tarantool\Client\Request\InsertRequest; |
11
|
|
|
use Tarantool\Client\Request\ReplaceRequest; |
12
|
|
|
use Tarantool\Client\Request\UpdateRequest; |
13
|
|
|
use Tarantool\Mapper\Client; |
14
|
|
|
use Tarantool\Mapper\Mapper; |
15
|
|
|
use Tarantool\Mapper\Plugin; |
16
|
|
|
use Tarantool\Mapper\Plugin\Sequence; |
17
|
|
|
use Tarantool\Mapper\Plugin\Spy; |
18
|
|
|
use Tarantool\Mapper\Plugin\Temporal; |
19
|
|
|
use Tarantool\Mapper\Pool; |
20
|
|
|
use Tarantool\Mapper\Schema; |
21
|
|
|
|
22
|
|
|
class PoolProvider extends AbstractServiceProvider |
23
|
|
|
{ |
24
|
|
|
protected $provides = [ |
25
|
|
|
Pool::class, |
26
|
|
|
]; |
27
|
|
|
|
28
|
|
|
public function register() |
29
|
|
|
{ |
30
|
|
|
$this->getContainer()->share(Pool::class, function () { |
31
|
|
|
$container = $this->getContainer(); |
32
|
|
|
|
33
|
|
|
$mapper = $container->get(Mapper::class); |
34
|
|
|
|
35
|
|
|
$service = $container->get(Service::class); |
36
|
|
|
$mapper->serviceName = $service->getName(); |
37
|
|
|
|
38
|
|
|
$pool = new Pool(); |
39
|
|
|
$pool->register('default', $mapper); |
40
|
|
|
$pool->register($mapper->serviceName, $mapper); |
41
|
|
|
|
42
|
|
|
$pool->registerResolver(function ($name) use ($service) { |
43
|
|
|
if (in_array($name, $service->listServices())) { |
44
|
|
|
$connection = new StreamConnection('tcp://'.$name.'-db:3301'); |
45
|
|
|
$packer = new PurePacker(); |
46
|
|
|
$client = new Client($connection, $packer); |
47
|
|
|
$client->disableRequest(DeleteRequest::class); |
48
|
|
|
$client->disableRequest(InsertRequest::class); |
49
|
|
|
$client->disableRequest(ReplaceRequest::class); |
50
|
|
|
$client->disableRequest(UpdateRequest::class); |
51
|
|
|
$mapper = new Mapper($client); |
52
|
|
|
$mapper->getPlugin(Sequence::class); |
53
|
|
|
$mapper->getPlugin(Spy::class); |
54
|
|
|
$mapper->getPlugin(Temporal::class); |
55
|
|
|
$mapper->serviceName = $name; |
|
|
|
|
56
|
|
|
return $mapper; |
57
|
|
|
} |
58
|
|
|
}); |
59
|
|
|
|
60
|
|
|
return $pool; |
61
|
|
|
}); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.
If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.