1
|
|
|
<?php |
2
|
|
|
declare(strict_types = 1); |
3
|
|
|
|
4
|
|
|
namespace Innmind\AMQP\Model\Exchange; |
5
|
|
|
|
6
|
|
|
use Innmind\AMQP\Exception\NotWaitingPassiveDeclarationDoesNothing; |
7
|
|
|
use Innmind\Immutable\{ |
8
|
|
|
MapInterface, |
9
|
|
|
Map, |
10
|
|
|
}; |
11
|
|
|
|
12
|
|
|
final class Declaration |
13
|
|
|
{ |
14
|
|
|
private $name; |
15
|
|
|
private $type; |
16
|
|
|
private $passive = false; |
17
|
|
|
private $durable = false; |
18
|
|
|
private $autoDelete = false; |
19
|
|
|
private $wait = true; |
20
|
|
|
private $arguments; |
21
|
|
|
|
22
|
28 |
|
private function __construct(string $name, Type $type) |
23
|
|
|
{ |
24
|
28 |
|
$this->name = $name; |
25
|
28 |
|
$this->type = $type; |
26
|
28 |
|
$this->arguments = new Map('string', 'mixed'); |
27
|
28 |
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Check if the exchange with the given name exists on the server |
31
|
|
|
*/ |
32
|
12 |
|
public static function passive(string $name, Type $type): self |
33
|
|
|
{ |
34
|
12 |
|
$self = new self($name, $type); |
35
|
12 |
|
$self->passive = true; |
36
|
|
|
|
37
|
12 |
|
return $self; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* The exchange will survive after a server restart |
42
|
|
|
*/ |
43
|
10 |
|
public static function durable(string $name, Type $type): self |
44
|
|
|
{ |
45
|
10 |
|
$self = new self($name, $type); |
46
|
10 |
|
$self->durable = true; |
47
|
|
|
|
48
|
10 |
|
return $self; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* The exchange will disappear after a server restart |
53
|
|
|
*/ |
54
|
8 |
|
public static function temporary(string $name, Type $type): self |
55
|
|
|
{ |
56
|
8 |
|
return new self($name, $type); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* The exchange will disappear once it's no longer used |
61
|
|
|
*/ |
62
|
4 |
|
public static function autoDelete(string $name, Type $type): self |
63
|
|
|
{ |
64
|
4 |
|
$self = new self($name, $type); |
65
|
4 |
|
$self->autoDelete = true; |
66
|
4 |
|
$self->durable = false; |
67
|
|
|
|
68
|
4 |
|
return $self; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Don't wait for the server to respond |
73
|
|
|
*/ |
74
|
8 |
|
public function dontWait(): self |
75
|
|
|
{ |
76
|
8 |
|
if ($this->isPassive()) { |
77
|
2 |
|
throw new NotWaitingPassiveDeclarationDoesNothing; |
78
|
|
|
} |
79
|
|
|
|
80
|
6 |
|
$self = clone $this; |
81
|
6 |
|
$self->wait = false; |
82
|
|
|
|
83
|
6 |
|
return $self; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Wait for the server to respond |
88
|
|
|
*/ |
89
|
2 |
|
public function wait(): self |
90
|
|
|
{ |
91
|
2 |
|
$self = clone $this; |
92
|
2 |
|
$self->wait = true; |
93
|
|
|
|
94
|
2 |
|
return $self; |
95
|
|
|
} |
96
|
|
|
|
97
|
4 |
|
public function withArgument(string $key, $value): self |
98
|
|
|
{ |
99
|
4 |
|
$self = clone $this; |
100
|
4 |
|
$self->arguments = $self->arguments->put($key, $value); |
101
|
|
|
|
102
|
4 |
|
return $self; |
103
|
|
|
} |
104
|
|
|
|
105
|
14 |
|
public function name(): string |
106
|
|
|
{ |
107
|
14 |
|
return $this->name; |
108
|
|
|
} |
109
|
|
|
|
110
|
12 |
|
public function type(): Type |
111
|
|
|
{ |
112
|
12 |
|
return $this->type; |
113
|
|
|
} |
114
|
|
|
|
115
|
16 |
|
public function isPassive(): bool |
116
|
|
|
{ |
117
|
16 |
|
return $this->passive; |
118
|
|
|
} |
119
|
|
|
|
120
|
12 |
|
public function isDurable(): bool |
121
|
|
|
{ |
122
|
12 |
|
return $this->durable; |
123
|
|
|
} |
124
|
|
|
|
125
|
12 |
|
public function isAutoDeleted(): bool |
126
|
|
|
{ |
127
|
12 |
|
return $this->autoDelete; |
128
|
|
|
} |
129
|
|
|
|
130
|
16 |
|
public function shouldWait(): bool |
131
|
|
|
{ |
132
|
16 |
|
return $this->wait; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* @return MapInterface<string, mixed> |
137
|
|
|
*/ |
138
|
14 |
|
public function arguments(): MapInterface |
139
|
|
|
{ |
140
|
14 |
|
return $this->arguments; |
141
|
|
|
} |
142
|
|
|
} |
143
|
|
|
|