1
|
|
|
<?php |
2
|
|
|
declare(strict_types = 1); |
3
|
|
|
|
4
|
|
|
namespace Innmind\AMQP\Transport\Protocol\v091; |
5
|
|
|
|
6
|
|
|
use Innmind\AMQP\{ |
7
|
|
|
Model\Queue\Declaration, |
8
|
|
|
Model\Queue\Deletion, |
9
|
|
|
Model\Queue\Binding, |
10
|
|
|
Model\Queue\Unbinding, |
11
|
|
|
Model\Queue\Purge, |
12
|
|
|
Transport\Frame, |
13
|
|
|
Transport\Frame\Channel as FrameChannel, |
14
|
|
|
Transport\Frame\Type, |
15
|
|
|
Transport\Frame\Value, |
16
|
|
|
Transport\Frame\Value\UnsignedShortInteger, |
17
|
|
|
Transport\Frame\Value\ShortString, |
18
|
|
|
Transport\Frame\Value\Bits, |
19
|
|
|
Transport\Frame\Value\Table, |
20
|
|
|
Transport\Protocol\Queue as QueueInterface, |
21
|
|
|
Transport\Protocol\ArgumentTranslator, |
22
|
|
|
}; |
23
|
|
|
use Innmind\Math\Algebra\Integer; |
24
|
|
|
use Innmind\Immutable\{ |
25
|
|
|
Str, |
26
|
|
|
MapInterface, |
27
|
|
|
Map, |
28
|
|
|
}; |
29
|
|
|
|
30
|
|
|
final class Queue implements QueueInterface |
31
|
|
|
{ |
32
|
|
|
private $translate; |
33
|
|
|
|
34
|
250 |
|
public function __construct(ArgumentTranslator $translator) |
35
|
|
|
{ |
36
|
250 |
|
$this->translate = $translator; |
37
|
250 |
|
} |
38
|
|
|
|
39
|
50 |
|
public function declare(FrameChannel $channel, Declaration $command): Frame |
40
|
|
|
{ |
41
|
50 |
|
$name = ''; |
42
|
|
|
|
43
|
50 |
|
if (!$command->shouldAutoGenerateName()) { |
44
|
40 |
|
$name = $command->name(); |
45
|
|
|
} |
46
|
|
|
|
47
|
50 |
|
return Frame::method( |
48
|
50 |
|
$channel, |
49
|
50 |
|
Methods::get('queue.declare'), |
50
|
50 |
|
new UnsignedShortInteger(new Integer(0)), //ticket (reserved) |
51
|
50 |
|
ShortString::of(new Str($name)), |
52
|
50 |
|
new Bits( |
53
|
50 |
|
$command->isPassive(), |
54
|
50 |
|
$command->isDurable(), |
55
|
50 |
|
$command->isExclusive(), |
56
|
50 |
|
$command->isAutoDeleted(), |
57
|
50 |
|
!$command->shouldWait() |
58
|
|
|
), |
59
|
50 |
|
$this->translate($command->arguments()) |
60
|
|
|
); |
61
|
|
|
} |
62
|
|
|
|
63
|
4 |
|
public function delete(FrameChannel $channel, Deletion $command): Frame |
64
|
|
|
{ |
65
|
4 |
|
return Frame::method( |
66
|
4 |
|
$channel, |
67
|
4 |
|
Methods::get('queue.delete'), |
68
|
4 |
|
new UnsignedShortInteger(new Integer(0)), //ticket (reserved) |
69
|
4 |
|
ShortString::of(new Str($command->name())), |
70
|
4 |
|
new Bits( |
71
|
4 |
|
$command->onlyIfUnused(), |
72
|
4 |
|
$command->onlyIfEmpty(), |
73
|
4 |
|
!$command->shouldWait() |
74
|
|
|
) |
75
|
|
|
); |
76
|
|
|
} |
77
|
|
|
|
78
|
38 |
|
public function bind(FrameChannel $channel, Binding $command): Frame |
79
|
|
|
{ |
80
|
38 |
|
return Frame::method( |
81
|
38 |
|
$channel, |
82
|
38 |
|
Methods::get('queue.bind'), |
83
|
38 |
|
new UnsignedShortInteger(new Integer(0)), //ticket (reserved) |
84
|
38 |
|
ShortString::of(new Str($command->queue())), |
85
|
38 |
|
ShortString::of(new Str($command->exchange())), |
86
|
38 |
|
ShortString::of(new Str($command->routingKey())), |
87
|
38 |
|
new Bits(!$command->shouldWait()), |
88
|
38 |
|
$this->translate($command->arguments()) |
89
|
|
|
); |
90
|
|
|
} |
91
|
|
|
|
92
|
4 |
|
public function unbind(FrameChannel $channel, Unbinding $command): Frame |
93
|
|
|
{ |
94
|
4 |
|
return Frame::method( |
95
|
4 |
|
$channel, |
96
|
4 |
|
Methods::get('queue.unbind'), |
97
|
4 |
|
new UnsignedShortInteger(new Integer(0)), //ticket (reserved) |
98
|
4 |
|
ShortString::of(new Str($command->queue())), |
99
|
4 |
|
ShortString::of(new Str($command->exchange())), |
100
|
4 |
|
ShortString::of(new Str($command->routingKey())), |
101
|
4 |
|
$this->translate($command->arguments()) |
102
|
|
|
); |
103
|
|
|
} |
104
|
|
|
|
105
|
4 |
|
public function purge(FrameChannel $channel, Purge $command): Frame |
106
|
|
|
{ |
107
|
4 |
|
return Frame::method( |
108
|
4 |
|
$channel, |
109
|
4 |
|
Methods::get('queue.purge'), |
110
|
4 |
|
new UnsignedShortInteger(new Integer(0)), //ticket (reserved) |
111
|
4 |
|
ShortString::of(new Str($command->name())), |
112
|
4 |
|
new Bits(!$command->shouldWait()) |
113
|
|
|
); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @param MapInterface<string, mixed> $arguments |
118
|
|
|
*/ |
119
|
54 |
|
private function translate(MapInterface $arguments): Table |
120
|
|
|
{ |
121
|
54 |
|
return new Table( |
122
|
54 |
|
$arguments->reduce( |
123
|
54 |
|
new Map('string', Value::class), |
124
|
|
|
function(Map $carry, string $key, $value): Map { |
125
|
6 |
|
return $carry->put( |
126
|
6 |
|
$key, |
127
|
6 |
|
($this->translate)($value) |
128
|
|
|
); |
129
|
54 |
|
} |
130
|
|
|
) |
131
|
|
|
); |
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
|