1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Yiisoft\Queue\AMQP\Settings; |
6
|
|
|
|
7
|
|
|
use PhpAmqpLib\Exchange\AMQPExchangeType; |
8
|
|
|
use PhpAmqpLib\Wire\AMQPTable; |
9
|
|
|
|
10
|
|
|
final class Exchange implements ExchangeSettingsInterface |
11
|
|
|
{ |
12
|
|
|
public function __construct( |
13
|
|
|
private string $exchangeName, |
14
|
|
|
private string $type = AMQPExchangeType::DIRECT, |
15
|
|
|
private bool $passive = false, |
16
|
|
|
private bool $durable = false, |
17
|
|
|
private bool $autoDelete = true, |
18
|
|
|
private bool $internal = false, |
19
|
|
|
private bool $nowait = false, |
20
|
|
|
private AMQPTable|array $arguments = [], |
21
|
|
|
private ?int $ticket = null |
22
|
|
|
) { |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function getArguments(): AMQPTable|array |
26
|
|
|
{ |
27
|
|
|
return $this->arguments; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function getName(): string |
31
|
|
|
{ |
32
|
|
|
return $this->exchangeName; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function getTicket(): ?int |
36
|
|
|
{ |
37
|
|
|
return $this->ticket; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function getType(): string |
41
|
|
|
{ |
42
|
|
|
return $this->type; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function isAutoDelete(): bool |
46
|
|
|
{ |
47
|
|
|
return $this->autoDelete; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function isDurable(): bool |
51
|
|
|
{ |
52
|
|
|
return $this->durable; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function isInternal(): bool |
56
|
|
|
{ |
57
|
|
|
return $this->internal; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function hasNowait(): bool |
61
|
|
|
{ |
62
|
|
|
return $this->nowait; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function isPassive(): bool |
66
|
|
|
{ |
67
|
|
|
return $this->passive; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function getPositionalSettings(): array |
71
|
|
|
{ |
72
|
|
|
return [ |
73
|
|
|
$this->exchangeName, |
74
|
|
|
$this->type, |
75
|
|
|
$this->passive, |
76
|
|
|
$this->durable, |
77
|
|
|
$this->autoDelete, |
78
|
|
|
$this->internal, |
79
|
|
|
$this->nowait, |
80
|
|
|
$this->arguments, |
81
|
|
|
$this->ticket, |
82
|
|
|
]; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @return self |
87
|
|
|
*/ |
88
|
|
|
public function withArguments(AMQPTable|array $arguments): ExchangeSettingsInterface |
89
|
|
|
{ |
90
|
|
|
$new = clone $this; |
91
|
|
|
$new->arguments = $arguments; |
92
|
|
|
|
93
|
|
|
return $new; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @return self |
98
|
|
|
*/ |
99
|
|
|
public function withName(string $name): ExchangeSettingsInterface |
100
|
|
|
{ |
101
|
|
|
$new = clone $this; |
102
|
|
|
$new->exchangeName = $name; |
103
|
|
|
|
104
|
|
|
return $new; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @return self |
109
|
|
|
*/ |
110
|
|
|
public function withTicket(?int $ticket): ExchangeSettingsInterface |
111
|
|
|
{ |
112
|
|
|
$new = clone $this; |
113
|
|
|
$new->ticket = $ticket; |
114
|
|
|
|
115
|
|
|
return $new; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @return self |
120
|
|
|
*/ |
121
|
|
|
public function withType(string $type): ExchangeSettingsInterface |
122
|
|
|
{ |
123
|
|
|
$new = clone $this; |
124
|
|
|
$new->type = $type; |
125
|
|
|
|
126
|
|
|
return $new; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @return self |
131
|
|
|
*/ |
132
|
|
|
public function withAutoDelete(bool $autoDelete): ExchangeSettingsInterface |
133
|
|
|
{ |
134
|
|
|
$new = clone $this; |
135
|
|
|
$new->autoDelete = $autoDelete; |
136
|
|
|
|
137
|
|
|
return $new; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* @return self |
142
|
|
|
*/ |
143
|
|
|
public function withDurable(bool $durable): ExchangeSettingsInterface |
144
|
|
|
{ |
145
|
|
|
$new = clone $this; |
146
|
|
|
$new->durable = $durable; |
147
|
|
|
|
148
|
|
|
return $new; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* @return self |
153
|
|
|
*/ |
154
|
|
|
public function withInternal(bool $internal): ExchangeSettingsInterface |
155
|
|
|
{ |
156
|
|
|
$new = clone $this; |
157
|
|
|
$new->internal = $internal; |
158
|
|
|
|
159
|
|
|
return $new; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* @return self |
164
|
|
|
*/ |
165
|
|
|
public function withNowait(bool $nowait): ExchangeSettingsInterface |
166
|
|
|
{ |
167
|
|
|
$new = clone $this; |
168
|
|
|
$new->nowait = $nowait; |
169
|
|
|
|
170
|
|
|
return $new; |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* @return self |
175
|
|
|
*/ |
176
|
|
|
public function withPassive(bool $passive): ExchangeSettingsInterface |
177
|
|
|
{ |
178
|
|
|
$new = clone $this; |
179
|
|
|
$new->passive = $passive; |
180
|
|
|
|
181
|
|
|
return $new; |
182
|
|
|
} |
183
|
|
|
} |
184
|
|
|
|