|
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
|
45 |
|
public function __construct(Application $app) |
|
14
|
|
|
{ |
|
15
|
45 |
|
$this->app = $app; |
|
16
|
45 |
|
} |
|
17
|
|
|
|
|
18
|
3 |
|
protected function create(string $space, array $data) : Entity |
|
19
|
|
|
{ |
|
20
|
3 |
|
return $this->get(Mapper::class)->create($space, $data); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
45 |
|
protected function dispatch(string $job, array $params = [], string $service = null) |
|
24
|
|
|
{ |
|
25
|
45 |
|
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
|
23 |
|
protected function get(string $class) |
|
54
|
|
|
{ |
|
55
|
23 |
|
return $this->app->get($class); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
1 |
|
protected function getDate() |
|
59
|
|
|
{ |
|
60
|
1 |
|
return call_user_func_array([$this->get(Converter::class), 'getDate'], func_get_args()); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
4 |
|
protected function getMapper() |
|
64
|
|
|
{ |
|
65
|
4 |
|
return $this->get(Mapper::class); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
protected function getQueue($tube) |
|
69
|
|
|
{ |
|
70
|
|
|
$alias = "queue.$tube"; |
|
71
|
|
|
if (!$this->app->hasShared($alias, true)) { |
|
72
|
|
|
$client = $this->getMapper()->getClient(); |
|
73
|
|
|
$client->evaluate(" |
|
74
|
|
|
if queue == nil then |
|
75
|
|
|
queue = require('queue') |
|
76
|
|
|
end |
|
77
|
|
|
"); |
|
78
|
|
|
$this->app->share($alias, new Queue($client, $tube)); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
return $this->app->get($alias); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
1 |
|
protected function remove(string $space, array $params = []) |
|
85
|
|
|
{ |
|
86
|
1 |
|
return $this->get(Mapper::class)->remove($space, $params); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
2 |
|
protected function select($fields, string $table, array $params) |
|
90
|
|
|
{ |
|
91
|
2 |
|
return $this->get(Clickhouse::class)->select($fields, $table, $params); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
2 |
|
protected function insert(string $table, array $data, array $headers) |
|
95
|
|
|
{ |
|
96
|
2 |
|
return $this->get(Clickhouse::class)->insert($table, $data, $headers); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
public function __debugInfo() |
|
100
|
|
|
{ |
|
101
|
|
|
$info = get_object_vars($this); |
|
102
|
|
|
unset($info['app']); |
|
103
|
|
|
return $info; |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
|