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