1
|
|
|
<?php |
2
|
|
|
declare(strict_types = 1); |
3
|
|
|
|
4
|
|
|
namespace Innmind\AMQP\Model\Basic; |
5
|
|
|
|
6
|
|
|
final class Publish |
7
|
|
|
{ |
8
|
|
|
private $message; |
9
|
|
|
private $exchange = ''; |
10
|
|
|
private $routingKey = ''; |
11
|
|
|
private $mandatory = false; |
12
|
|
|
private $immediate = false; |
13
|
|
|
|
14
|
6 |
|
public function __construct(Message $message) |
15
|
|
|
{ |
16
|
6 |
|
$this->message = $message; |
17
|
6 |
|
} |
18
|
|
|
|
19
|
2 |
|
public function to(string $exchange): self |
20
|
|
|
{ |
21
|
2 |
|
$self = clone $this; |
22
|
2 |
|
$self->exchange = $exchange; |
23
|
|
|
|
24
|
2 |
|
return $self; |
25
|
|
|
} |
26
|
|
|
|
27
|
1 |
|
public function toDefaultExchange(): self |
28
|
|
|
{ |
29
|
1 |
|
$self = clone $this; |
30
|
1 |
|
$self->exchange = ''; |
31
|
|
|
|
32
|
1 |
|
return $self; |
33
|
|
|
} |
34
|
|
|
|
35
|
2 |
|
public function withRoutingKey(string $key): self |
36
|
|
|
{ |
37
|
2 |
|
$self = clone $this; |
38
|
2 |
|
$self->routingKey = $key; |
39
|
|
|
|
40
|
2 |
|
return $self; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* This will raise an error if the message can't be routed |
45
|
|
|
*/ |
46
|
2 |
|
public function flagAsMandatory(): self |
47
|
|
|
{ |
48
|
2 |
|
$self = clone $this; |
49
|
2 |
|
$self->mandatory = true; |
50
|
|
|
|
51
|
2 |
|
return $self; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* This will fail silently if the message can't be routed |
56
|
|
|
*/ |
57
|
1 |
|
public function flagAsNotMandatory(): self |
58
|
|
|
{ |
59
|
1 |
|
$self = clone $this; |
60
|
1 |
|
$self->mandatory = false; |
61
|
|
|
|
62
|
1 |
|
return $self; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* This will raise an error if the message can't be delivered immediately |
67
|
|
|
*/ |
68
|
2 |
|
public function flagAsImmediate(): self |
69
|
|
|
{ |
70
|
2 |
|
$self = clone $this; |
71
|
2 |
|
$self->immediate = true; |
72
|
|
|
|
73
|
2 |
|
return $self; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* This will fail silently if the message can't be delivered immediately |
78
|
|
|
*/ |
79
|
1 |
|
public function flagAsNotImmediate(): self |
80
|
|
|
{ |
81
|
1 |
|
$self = clone $this; |
82
|
1 |
|
$self->immediate = false; |
83
|
|
|
|
84
|
1 |
|
return $self; |
85
|
|
|
} |
86
|
|
|
|
87
|
1 |
|
public function message(): Message |
88
|
|
|
{ |
89
|
1 |
|
return $this->message; |
90
|
|
|
} |
91
|
|
|
|
92
|
3 |
|
public function exchange(): string |
93
|
|
|
{ |
94
|
3 |
|
return $this->exchange; |
95
|
|
|
} |
96
|
|
|
|
97
|
3 |
|
public function routingKey(): string |
98
|
|
|
{ |
99
|
3 |
|
return $this->routingKey; |
100
|
|
|
} |
101
|
|
|
|
102
|
3 |
|
public function mandatory(): bool |
103
|
|
|
{ |
104
|
3 |
|
return $this->mandatory; |
105
|
|
|
} |
106
|
|
|
|
107
|
3 |
|
public function immediate(): bool |
108
|
|
|
{ |
109
|
3 |
|
return $this->immediate; |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|