1
|
|
|
<?php |
2
|
|
|
declare(strict_types = 1); |
3
|
|
|
|
4
|
|
|
namespace Innmind\AMQP\Transport\Protocol\v091\Reader; |
5
|
|
|
|
6
|
|
|
use Innmind\AMQP\{ |
7
|
|
|
Transport\Frame\Method, |
8
|
|
|
Transport\Frame\Visitor\ChunkArguments, |
9
|
|
|
Transport\Frame\Value\LongString, |
10
|
|
|
Transport\Frame\Value\ShortString, |
11
|
|
|
Transport\Frame\Value\Table, |
12
|
|
|
Transport\Frame\Value\UnsignedLongInteger, |
13
|
|
|
Transport\Frame\Value\UnsignedOctet, |
14
|
|
|
Transport\Frame\Value\UnsignedShortInteger, |
15
|
|
|
Transport\Protocol\v091\Methods, |
16
|
|
|
Exception\UnknownMethod, |
17
|
|
|
}; |
18
|
|
|
use Innmind\Stream\Readable; |
19
|
|
|
use Innmind\Immutable\StreamInterface; |
20
|
|
|
|
21
|
|
|
final class Connection |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @return StreamInterface<Value> |
25
|
|
|
*/ |
26
|
118 |
|
public function __invoke(Method $method, Readable $arguments): StreamInterface |
27
|
|
|
{ |
28
|
|
|
switch (true) { |
29
|
118 |
|
case Methods::get('connection.start')->equals($method): |
30
|
96 |
|
$chunk = $this->start(); |
31
|
96 |
|
break; |
32
|
|
|
|
33
|
112 |
|
case Methods::get('connection.secure')->equals($method): |
34
|
4 |
|
$chunk = $this->secure(); |
35
|
4 |
|
break; |
36
|
|
|
|
37
|
108 |
|
case Methods::get('connection.tune')->equals($method): |
38
|
94 |
|
$chunk = $this->tune(); |
39
|
94 |
|
break; |
40
|
|
|
|
41
|
104 |
|
case Methods::get('connection.open-ok')->equals($method): |
42
|
94 |
|
$chunk = $this->openOk(); |
43
|
94 |
|
break; |
44
|
|
|
|
45
|
88 |
|
case Methods::get('connection.close')->equals($method): |
46
|
6 |
|
$chunk = $this->close(); |
47
|
6 |
|
break; |
48
|
|
|
|
49
|
82 |
|
case Methods::get('connection.close-ok')->equals($method): |
50
|
80 |
|
$chunk = $this->closeOk(); |
51
|
80 |
|
break; |
52
|
|
|
|
53
|
|
|
default: |
54
|
2 |
|
throw new UnknownMethod($method); |
55
|
|
|
} |
56
|
|
|
|
57
|
116 |
|
return $chunk($arguments); |
58
|
|
|
} |
59
|
|
|
|
60
|
96 |
|
private function start(): ChunkArguments |
61
|
|
|
{ |
62
|
96 |
|
return new ChunkArguments( |
63
|
96 |
|
UnsignedOctet::class, //major version |
64
|
96 |
|
UnsignedOctet::class, //minor version |
65
|
96 |
|
Table::class, //server properties |
66
|
96 |
|
LongString::class, //mechanisms |
67
|
96 |
|
LongString::class //locales |
68
|
|
|
); |
69
|
|
|
} |
70
|
|
|
|
71
|
4 |
|
private function secure(): ChunkArguments |
72
|
|
|
{ |
73
|
4 |
|
return new ChunkArguments( |
74
|
4 |
|
LongString::class //challenge |
75
|
|
|
); |
76
|
|
|
} |
77
|
|
|
|
78
|
94 |
|
private function tune(): ChunkArguments |
79
|
|
|
{ |
80
|
94 |
|
return new ChunkArguments( |
81
|
94 |
|
UnsignedShortInteger::class, //max channels |
82
|
94 |
|
UnsignedLongInteger::class, //max frame size |
83
|
94 |
|
UnsignedShortInteger::class //heartbeat delay |
84
|
|
|
); |
85
|
|
|
} |
86
|
|
|
|
87
|
94 |
|
private function openOk(): ChunkArguments |
88
|
|
|
{ |
89
|
94 |
|
return new ChunkArguments( |
90
|
94 |
|
ShortString::class //known hosts |
91
|
|
|
); |
92
|
|
|
} |
93
|
|
|
|
94
|
6 |
|
private function close(): ChunkArguments |
95
|
|
|
{ |
96
|
6 |
|
return new ChunkArguments( |
97
|
6 |
|
UnsignedShortInteger::class, //reply code |
98
|
6 |
|
ShortString::class, //reply text |
99
|
6 |
|
UnsignedShortInteger::class, //failing class id |
100
|
6 |
|
UnsignedShortInteger::class //failing method id |
101
|
|
|
); |
102
|
|
|
} |
103
|
|
|
|
104
|
80 |
|
private function closeOk(): ChunkArguments |
105
|
|
|
{ |
106
|
80 |
|
return new ChunkArguments; // no arguments |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|