1
|
|
|
<?php |
2
|
|
|
declare(strict_types = 1); |
3
|
|
|
|
4
|
|
|
namespace Innmind\AMQP\Transport\Protocol\v091; |
5
|
|
|
|
6
|
|
|
use Innmind\AMQP\{ |
7
|
|
|
Model\Basic\Ack, |
8
|
|
|
Model\Basic\Cancel, |
9
|
|
|
Model\Basic\Consume, |
10
|
|
|
Model\Basic\Get, |
11
|
|
|
Model\Basic\Publish, |
12
|
|
|
Model\Basic\Qos, |
13
|
|
|
Model\Basic\Recover, |
14
|
|
|
Model\Basic\Reject, |
15
|
|
|
Transport\Frame, |
16
|
|
|
Transport\Frame\Type, |
17
|
|
|
Transport\Frame\Channel as FrameChannel, |
18
|
|
|
Transport\Frame\Value, |
19
|
|
|
Transport\Frame\Value\UnsignedLongLongInteger, |
20
|
|
|
Transport\Frame\Value\UnsignedLongInteger, |
21
|
|
|
Transport\Frame\Value\Bits, |
22
|
|
|
Transport\Frame\Value\ShortString, |
23
|
|
|
Transport\Frame\Value\UnsignedShortInteger, |
24
|
|
|
Transport\Frame\Value\Table, |
25
|
|
|
Transport\Protocol\Basic as BasicInterface |
26
|
|
|
}; |
27
|
|
|
use Innmind\Math\Algebra\Integer; |
28
|
|
|
use Innmind\Immutable\{ |
29
|
|
|
Str, |
30
|
|
|
Map |
31
|
|
|
}; |
32
|
|
|
|
33
|
|
|
final class Basic implements BasicInterface |
34
|
|
|
{ |
35
|
|
View Code Duplication |
public function ack(FrameChannel $channel, Ack $command): Frame |
|
|
|
|
36
|
|
|
{ |
37
|
|
|
return new Frame( |
38
|
|
|
Type::method(), |
39
|
|
|
$channel, |
40
|
|
|
Methods::get('basic.ack'), |
41
|
|
|
new UnsignedLongLongInteger(new Integer($command->deliveryTag())), |
42
|
|
|
new Bits($command->isMultiple()) |
43
|
|
|
); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function cancel(FrameChannel $channel, Cancel $command): Frame |
47
|
|
|
{ |
48
|
|
|
return new Frame( |
49
|
|
|
Type::method(), |
50
|
|
|
$channel, |
51
|
|
|
Methods::get('basic.cancel'), |
52
|
|
|
new ShortString(new Str($command->consumerTag())), |
53
|
|
|
new Bits(!$command->shouldWait()) |
54
|
|
|
); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
View Code Duplication |
public function consume(FrameChannel $channel, Consume $command): Frame |
|
|
|
|
58
|
|
|
{ |
59
|
|
|
$consumerTag = ''; |
60
|
|
|
|
61
|
|
|
if (!$command->shouldAutoGenerateConsumerTag()) { |
62
|
|
|
$consumerTag = $command->consumerTag(); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
return new Frame( |
66
|
|
|
Type::method(), |
67
|
|
|
$channel, |
68
|
|
|
Methods::get('basic.consume'), |
69
|
|
|
new UnsignedShortInteger(new Integer(0)), //ticket (reserved) |
70
|
|
|
new ShortString(new Str($command->queue())), |
71
|
|
|
new ShortString(new Str($consumerTag)), |
72
|
|
|
new Bits(!$command->isLocal()), |
73
|
|
|
new Bits($command->shouldAutoAcknowledge()), |
74
|
|
|
new Bits($command->isExclusive()), |
75
|
|
|
new Bits(!$command->shouldWait()), |
76
|
|
|
new Table(new Map('string', Value::class)) //todo: use $command->arguments() |
|
|
|
|
77
|
|
|
); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function get(FrameChannel $channel, Get $command): Frame |
81
|
|
|
{ |
82
|
|
|
return new Frame( |
83
|
|
|
Type::method(), |
84
|
|
|
$channel, |
85
|
|
|
Methods::get('basic.get'), |
86
|
|
|
new UnsignedShortInteger(new Integer(0)), //ticket (reserved) |
87
|
|
|
new ShortString(new Str($command->queue())), |
88
|
|
|
new Bits($command->shouldAutoAcknowledge()) |
89
|
|
|
); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
public function publish(FrameChannel $channel, Publish $command): Frame |
93
|
|
|
{ |
94
|
|
|
return new Frame( |
95
|
|
|
Type::method(), |
96
|
|
|
$channel, |
97
|
|
|
Methods::get('basic.publish'), |
98
|
|
|
new UnsignedShortInteger(new Integer(0)), //ticket (reserved) |
99
|
|
|
new ShortString(new Str($command->exchange())), |
100
|
|
|
new ShortString(new Str($command->routingKey())), |
101
|
|
|
new Bits($command->mandatory()), |
102
|
|
|
new Bits($command->immediate()) |
103
|
|
|
); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
View Code Duplication |
public function qos(FrameChannel $channel, Qos $command): Frame |
|
|
|
|
107
|
|
|
{ |
108
|
|
|
return new Frame( |
109
|
|
|
Type::method(), |
110
|
|
|
$channel, |
111
|
|
|
Methods::get('basic.qos'), |
112
|
|
|
new UnsignedLongInteger(new Integer($command->prefetchSize())), |
113
|
|
|
new UnsignedShortInteger(new Integer($command->prefetchCount())), |
114
|
|
|
new Bits($command->isGlobal()) |
115
|
|
|
); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
public function recover(FrameChannel $channel, Recover $command): Frame |
119
|
|
|
{ |
120
|
|
|
return new Frame( |
121
|
|
|
Type::method(), |
122
|
|
|
$channel, |
123
|
|
|
Methods::get('basic.recover'), |
124
|
|
|
new Bits($command->shouldRequeue()) |
125
|
|
|
); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
View Code Duplication |
public function reject(FrameChannel $channel, Reject $command): Frame |
|
|
|
|
129
|
|
|
{ |
130
|
|
|
return new Frame( |
131
|
|
|
Type::method(), |
132
|
|
|
$channel, |
133
|
|
|
Methods::get('basic.reject'), |
134
|
|
|
new UnsignedLongLongInteger(new Integer($command->deliveryTag())), |
135
|
|
|
new Bits($command->shouldRequeue()) |
136
|
|
|
); |
137
|
|
|
} |
138
|
|
|
} |
139
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.