1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Basis; |
4
|
|
|
|
5
|
|
|
use Exception; |
6
|
|
|
use Tarantool\Mapper\Mapper; |
7
|
|
|
use Tarantool\Mapper\Entity; |
8
|
|
|
|
9
|
|
|
abstract class Job |
10
|
|
|
{ |
11
|
|
|
protected $app; |
12
|
|
|
|
13
|
7 |
|
public function __construct(Application $app) |
14
|
|
|
{ |
15
|
7 |
|
$this->app = $app; |
16
|
7 |
|
} |
17
|
|
|
|
18
|
|
|
protected function confirm($message) |
19
|
|
|
{ |
20
|
|
|
$hash = md5($message); |
21
|
|
|
if (!is_array($this->_confirmations) || !in_array($hash, $this->_confirmations)) { |
|
|
|
|
22
|
|
|
throw new Exception(json_encode([ |
23
|
|
|
'type' => 'confirm', |
24
|
|
|
'message' => $message, |
25
|
|
|
'hash' => $hash |
26
|
|
|
])); |
27
|
|
|
} |
28
|
|
|
} |
29
|
|
|
|
30
|
1 |
|
public function create(string $space, array $data) : Entity |
31
|
|
|
{ |
32
|
1 |
|
return $this->get(Mapper::class)->create($space, $data); |
33
|
|
|
} |
34
|
|
|
|
35
|
1 |
|
public function dispatch(string $job, array $params = [], string $service = null) |
36
|
|
|
{ |
37
|
1 |
|
return $this->app->dispatch($job, $params, $service); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function fire(string $event, array $context) |
41
|
|
|
{ |
42
|
|
|
return $this->get(Event::class)->fire($event, $context); |
43
|
|
|
} |
44
|
|
|
|
45
|
1 |
|
public function get(string $class) |
46
|
|
|
{ |
47
|
1 |
|
return $this->app->get($class); |
48
|
|
|
} |
49
|
|
|
|
50
|
1 |
|
public function find(string $space, $params = []) : array |
51
|
|
|
{ |
52
|
1 |
|
return $this->get(Mapper::class)->find($space, $params); |
53
|
|
|
} |
54
|
|
|
|
55
|
1 |
|
public function findOrCreate(string $space, $params = []) : Entity |
56
|
|
|
{ |
57
|
1 |
|
return $this->get(Mapper::class)->findOrCreate($space, $params); |
58
|
|
|
} |
59
|
|
|
|
60
|
1 |
|
public function findOne(string $space, $params = []) : ?Entity |
61
|
|
|
{ |
62
|
1 |
|
return $this->get(Mapper::class)->findOne($space, $params); |
63
|
|
|
} |
64
|
|
|
|
65
|
1 |
|
public function findOrFail(string $space, $params = []) : Entity |
66
|
|
|
{ |
67
|
1 |
|
return $this->get(Mapper::class)->findOrFail($space, $params); |
68
|
|
|
} |
69
|
|
|
|
70
|
1 |
|
public function remove(string $space, array $params = []) |
71
|
|
|
{ |
72
|
1 |
|
return $this->get(Mapper::class)->remove($space, $params); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function __debugInfo() |
76
|
|
|
{ |
77
|
|
|
$info = get_object_vars($this); |
78
|
|
|
unset($info['app']); |
79
|
|
|
return $info; |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: