1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Yiisoft\Queue\AMQP\Settings; |
6
|
|
|
|
7
|
|
|
use PhpAmqpLib\Wire\AMQPTable; |
8
|
|
|
use Yiisoft\Queue\QueueFactoryInterface; |
9
|
|
|
|
10
|
|
|
final class Queue implements QueueSettingsInterface |
11
|
|
|
{ |
12
|
|
|
public function __construct( |
13
|
|
|
private string $queueName = QueueFactoryInterface::DEFAULT_CHANNEL_NAME, |
14
|
|
|
private bool $passive = false, |
15
|
|
|
private bool $durable = false, |
16
|
|
|
private bool $exclusive = false, |
17
|
|
|
private bool $autoDelete = true, |
18
|
|
|
private bool $nowait = false, |
19
|
|
|
private AMQPTable|array $arguments = [], |
20
|
|
|
private ?int $ticket = null |
21
|
|
|
) { |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
public function getArguments(): AMQPTable|array |
25
|
|
|
{ |
26
|
|
|
return $this->arguments; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function getName(): string |
30
|
|
|
{ |
31
|
|
|
return $this->queueName; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function getTicket(): ?int |
35
|
|
|
{ |
36
|
|
|
return $this->ticket; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function isAutoDeletable(): bool |
40
|
|
|
{ |
41
|
|
|
return $this->autoDelete; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function isDurable(): bool |
45
|
|
|
{ |
46
|
|
|
return $this->durable; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function isExclusive(): bool |
50
|
|
|
{ |
51
|
|
|
return $this->exclusive; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function hasNowait(): bool |
55
|
|
|
{ |
56
|
|
|
return $this->nowait; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function isPassive(): bool |
60
|
|
|
{ |
61
|
|
|
return $this->passive; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @psalm-return array{0: string, 1: bool, 2: bool, 3: bool, 4: bool, 5: bool, 6: AMQPTable|array, 7: int|null} |
66
|
|
|
* |
67
|
|
|
* @psalm-suppress LessSpecificImplementedReturnType Can be removed after raise Psalm version to ^5.0 |
68
|
|
|
*/ |
69
|
|
|
public function getPositionalSettings(): array |
70
|
|
|
{ |
71
|
|
|
return [ |
72
|
|
|
$this->queueName, |
73
|
|
|
$this->passive, |
74
|
|
|
$this->durable, |
75
|
|
|
$this->exclusive, |
76
|
|
|
$this->autoDelete, |
77
|
|
|
$this->nowait, |
78
|
|
|
$this->arguments, |
79
|
|
|
$this->ticket, |
80
|
|
|
]; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function withName(string $name): self |
84
|
|
|
{ |
85
|
|
|
$instance = clone $this; |
86
|
|
|
$instance->queueName = $name; |
87
|
|
|
|
88
|
|
|
return $instance; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function withArguments(AMQPTable|array $arguments): self |
92
|
|
|
{ |
93
|
|
|
$new = clone $this; |
94
|
|
|
$new->arguments = $arguments; |
95
|
|
|
|
96
|
|
|
return $new; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
public function withTicket(?int $ticket): self |
100
|
|
|
{ |
101
|
|
|
$new = clone $this; |
102
|
|
|
$new->ticket = $ticket; |
103
|
|
|
|
104
|
|
|
return $new; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
public function withAutoDeletable(bool $autoDeletable): self |
108
|
|
|
{ |
109
|
|
|
$new = clone $this; |
110
|
|
|
$new->autoDelete = $autoDeletable; |
111
|
|
|
|
112
|
|
|
return $new; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
public function withDurable(bool $durable): self |
116
|
|
|
{ |
117
|
|
|
$new = clone $this; |
118
|
|
|
$new->durable = $durable; |
119
|
|
|
|
120
|
|
|
return $new; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
public function withExclusive(bool $exclusive): self |
124
|
|
|
{ |
125
|
|
|
$new = clone $this; |
126
|
|
|
$new->exclusive = $exclusive; |
127
|
|
|
|
128
|
|
|
return $new; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
public function withNowait(bool $nowait): self |
132
|
|
|
{ |
133
|
|
|
$new = clone $this; |
134
|
|
|
$new->nowait = $nowait; |
135
|
|
|
|
136
|
|
|
return $new; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
public function withPassive(bool $passive): self |
140
|
|
|
{ |
141
|
|
|
$new = clone $this; |
142
|
|
|
$new->passive = $passive; |
143
|
|
|
|
144
|
|
|
return $new; |
145
|
|
|
} |
146
|
|
|
} |
147
|
|
|
|