1
|
|
|
<?php |
2
|
|
|
declare(strict_types = 1); |
3
|
|
|
|
4
|
|
|
namespace Innmind\AMQP\Transport\Protocol\v091; |
5
|
|
|
|
6
|
|
|
use Innmind\AMQP\{ |
7
|
|
|
Model\Channel\Flow, |
8
|
|
|
Model\Channel\FlowOk, |
9
|
|
|
Model\Channel\Close, |
10
|
|
|
Transport\Protocol\Channel as ChannelInterface, |
11
|
|
|
Transport\Frame, |
12
|
|
|
Transport\Frame\Method, |
13
|
|
|
Transport\Frame\Channel as FrameChannel, |
14
|
|
|
Transport\Frame\Type, |
15
|
|
|
Transport\Frame\Value\ShortString, |
16
|
|
|
Transport\Frame\Value\Bits, |
17
|
|
|
Transport\Frame\Value\UnsignedShortInteger |
18
|
|
|
}; |
19
|
|
|
use Innmind\Math\Algebra\Integer; |
20
|
|
|
use Innmind\Immutable\Str; |
21
|
|
|
|
22
|
|
|
final class Channel implements ChannelInterface |
23
|
|
|
{ |
24
|
|
|
public function open(FrameChannel $channel): Frame |
25
|
|
|
{ |
26
|
|
|
return new Frame( |
27
|
|
|
Type::method(), |
28
|
|
|
$channel, |
29
|
|
|
Methods::get('channel.open'), |
30
|
|
|
new ShortString(new Str('')) //out of band (reserved) |
31
|
|
|
); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
View Code Duplication |
public function flow(FrameChannel $channel, Flow $command): Frame |
|
|
|
|
35
|
|
|
{ |
36
|
|
|
return new Frame( |
37
|
|
|
Type::method(), |
38
|
|
|
$channel, |
39
|
|
|
Methods::get('channel.flow'), |
40
|
|
|
new Bits($command->active()) |
41
|
|
|
); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
View Code Duplication |
public function flowOk(FrameChannel $channel, FlowOk $command): Frame |
|
|
|
|
45
|
|
|
{ |
46
|
|
|
return new Frame( |
47
|
|
|
Type::method(), |
48
|
|
|
$channel, |
49
|
|
|
Methods::get('channel.flow-ok'), |
50
|
|
|
new Bits($command->active()) |
51
|
|
|
); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
View Code Duplication |
public function close(FrameChannel $channel, Close $command): Frame |
|
|
|
|
55
|
|
|
{ |
56
|
|
|
$replyCode = 0; |
57
|
|
|
$replyText = ''; |
58
|
|
|
$method = new Method(0, 0); |
59
|
|
|
|
60
|
|
|
if ($command->hasReply()) { |
61
|
|
|
$replyCode = $command->replyCode(); |
62
|
|
|
$replyText = $command->replyText(); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
if ($command->causedKnown()) { |
66
|
|
|
$method = Methods::get($command->cause()); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
return new Frame( |
70
|
|
|
Type::method(), |
71
|
|
|
$channel, |
72
|
|
|
Methods::get('channel.close'), |
73
|
|
|
new UnsignedShortInteger(new Integer($replyCode)), |
74
|
|
|
new ShortString(new Str($replyText)), |
75
|
|
|
new UnsignedShortInteger(new Integer($method->class())), |
76
|
|
|
new UnsignedShortInteger(new Integer($method->method())) |
77
|
|
|
); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function closeOk(FrameChannel $channel): Frame |
81
|
|
|
{ |
82
|
|
|
return new Frame( |
83
|
|
|
Type::method(), |
84
|
|
|
$channel, |
85
|
|
|
Methods::get('channel.close-ok') |
86
|
|
|
); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
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.