1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Basis; |
4
|
|
|
|
5
|
|
|
use Tarantool\Mapper\Entity; |
6
|
|
|
use Tarantool\Mapper\Mapper; |
7
|
|
|
use Tarantool\Queue\Queue; |
8
|
|
|
|
9
|
|
|
trait Toolkit |
10
|
|
|
{ |
11
|
|
|
protected $app; |
12
|
|
|
|
13
|
42 |
|
public function __construct(Application $app) |
14
|
|
|
{ |
15
|
42 |
|
$this->app = $app; |
16
|
42 |
|
} |
17
|
|
|
|
18
|
2 |
|
protected function create(string $space, array $data) : Entity |
19
|
|
|
{ |
20
|
2 |
|
return $this->get(Mapper::class)->create($space, $data); |
21
|
|
|
} |
22
|
|
|
|
23
|
42 |
|
protected function dispatch(string $job, array $params = [], string $service = null) |
24
|
|
|
{ |
25
|
42 |
|
return $this->app->dispatch($job, $params, $service); |
26
|
|
|
} |
27
|
|
|
|
28
|
1 |
|
protected function find(string $space, $params = []) : array |
29
|
|
|
{ |
30
|
1 |
|
return $this->get(Mapper::class)->find($space, $params); |
31
|
|
|
} |
32
|
|
|
|
33
|
1 |
|
protected function findOne(string $space, $params = []) : ?Entity |
34
|
|
|
{ |
35
|
1 |
|
return $this->get(Mapper::class)->findOne($space, $params); |
36
|
|
|
} |
37
|
|
|
|
38
|
1 |
|
protected function findOrCreate(string $space, $params = []) : Entity |
39
|
|
|
{ |
40
|
1 |
|
return $this->get(Mapper::class)->findOrCreate($space, $params); |
41
|
|
|
} |
42
|
|
|
|
43
|
2 |
|
protected function findOrFail(string $space, $params = []) : Entity |
44
|
|
|
{ |
45
|
2 |
|
return $this->get(Mapper::class)->findOrFail($space, $params); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
protected function fire(string $event, array $context) |
49
|
|
|
{ |
50
|
|
|
return $this->get(Event::class)->fire($event, $context); |
51
|
|
|
} |
52
|
|
|
|
53
|
19 |
|
protected function get(string $class) |
54
|
|
|
{ |
55
|
19 |
|
return $this->app->get($class); |
56
|
|
|
} |
57
|
|
|
|
58
|
3 |
|
protected function getMapper() |
59
|
|
|
{ |
60
|
3 |
|
return $this->get(Mapper::class); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
protected function getQueue($tube) |
64
|
|
|
{ |
65
|
|
|
$alias = "queue.$tube"; |
66
|
|
|
if (!$this->app->hasShared($alias, true)) { |
67
|
|
|
$client = $this->getMapper()->getClient(); |
68
|
|
|
$client->evaluate(" |
69
|
|
|
if queue == nil then |
70
|
|
|
queue = require('queue') |
71
|
|
|
end |
72
|
|
|
"); |
73
|
|
|
$this->app->share($alias, new Queue($client, $tube)); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
return $this->app->get($alias); |
77
|
|
|
} |
78
|
|
|
|
79
|
1 |
|
protected function remove(string $space, array $params = []) |
80
|
|
|
{ |
81
|
1 |
|
return $this->get(Mapper::class)->remove($space, $params); |
82
|
|
|
} |
83
|
|
|
|
84
|
2 |
|
protected function select($fields, string $table, array $params) |
85
|
|
|
{ |
86
|
2 |
|
return $this->get(Clickhouse::class)->select($fields, $table, $params); |
87
|
|
|
} |
88
|
|
|
|
89
|
2 |
|
protected function insert(string $table, array $data, array $headers) |
90
|
|
|
{ |
91
|
2 |
|
return $this->get(Clickhouse::class)->insert($table, $data, $headers); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
public function __debugInfo() |
95
|
|
|
{ |
96
|
|
|
$info = get_object_vars($this); |
97
|
|
|
unset($info['app']); |
98
|
|
|
return $info; |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|