|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace BinaryCube\CarrotMQ\Entity; |
|
6
|
|
|
|
|
7
|
|
|
use Psr\Log\LoggerInterface; |
|
8
|
|
|
use Interop\Amqp\AmqpContext; |
|
9
|
|
|
use BinaryCube\CarrotMQ\Component; |
|
10
|
|
|
use BinaryCube\CarrotMQ\Connection; |
|
11
|
|
|
use BinaryCube\CarrotMQ\Support\LoggerAwareTrait; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Class Entity |
|
15
|
|
|
*/ |
|
16
|
|
|
abstract class Entity extends Component |
|
17
|
|
|
{ |
|
18
|
|
|
use LoggerAwareTrait; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @var string |
|
22
|
|
|
*/ |
|
23
|
|
|
protected $name; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var Connection |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $connection; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var array |
|
32
|
|
|
*/ |
|
33
|
|
|
protected $config; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Constructor. |
|
37
|
|
|
* |
|
38
|
|
|
* @param string $id |
|
39
|
|
|
* @param string $name |
|
40
|
|
|
* @param Connection $connection |
|
41
|
|
|
* @param array $config |
|
42
|
|
|
* @param LoggerInterface|null $logger |
|
43
|
|
|
*/ |
|
44
|
|
|
public function __construct( |
|
45
|
|
|
string $id, |
|
46
|
|
|
string $name, |
|
47
|
|
|
Connection $connection, |
|
48
|
|
|
array $config = [], |
|
49
|
|
|
?LoggerInterface $logger = null |
|
50
|
|
|
) { |
|
51
|
|
|
parent::__construct($id, $logger); |
|
52
|
|
|
|
|
53
|
|
|
$this->id = $id; |
|
54
|
|
|
$this->name = $name; |
|
55
|
|
|
$this->connection = $connection; |
|
56
|
|
|
$this->config = $config; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @return string |
|
61
|
|
|
*/ |
|
62
|
|
|
public function name(): string |
|
63
|
|
|
{ |
|
64
|
|
|
return $this->name; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @return Connection |
|
69
|
|
|
*/ |
|
70
|
|
|
public function connection(): Connection |
|
71
|
|
|
{ |
|
72
|
|
|
return $this->connection; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @return array |
|
77
|
|
|
*/ |
|
78
|
|
|
public function config(): array |
|
79
|
|
|
{ |
|
80
|
|
|
return $this->config; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* @param bool $refresh |
|
85
|
|
|
* |
|
86
|
|
|
* @return AmqpContext |
|
87
|
|
|
*/ |
|
88
|
|
|
public function context(bool $refresh = false): AmqpContext |
|
89
|
|
|
{ |
|
90
|
|
|
return $this->connection->context($refresh); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* @return mixed |
|
95
|
|
|
*/ |
|
96
|
|
|
abstract public function model(); |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* @return $this |
|
100
|
|
|
*/ |
|
101
|
|
|
abstract protected function create(); |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* @return $this |
|
105
|
|
|
*/ |
|
106
|
|
|
abstract public function delete(); |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* @return $this |
|
110
|
|
|
*/ |
|
111
|
|
|
abstract protected function bind(); |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* @return boolean |
|
115
|
|
|
*/ |
|
116
|
|
|
abstract public function exists(): bool; |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* @return $this |
|
120
|
|
|
*/ |
|
121
|
|
|
abstract public function install(); |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* @return boolean |
|
125
|
|
|
*/ |
|
126
|
|
|
abstract public function canAutoCreate(): bool; |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* @return $this |
|
130
|
|
|
*/ |
|
131
|
|
|
public function reconnect() |
|
132
|
|
|
{ |
|
133
|
|
|
$this->connection->reconnect(); |
|
134
|
|
|
|
|
135
|
|
|
return $this; |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
} |
|
139
|
|
|
|