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\Arguments, |
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\Immutable\{ |
19
|
|
|
Str, |
20
|
|
|
StreamInterface |
21
|
|
|
}; |
22
|
|
|
|
23
|
|
|
final class Connection |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @return StreamInterface<Value> |
|
|
|
|
27
|
|
|
*/ |
28
|
1 |
|
public function __invoke(Method $method, Str $arguments): StreamInterface |
29
|
|
|
{ |
30
|
|
|
switch (true) { |
31
|
1 |
|
case Methods::get('connection.start')->equals($method): |
32
|
|
|
$visit = $this->start(); |
33
|
|
|
break; |
34
|
|
|
|
35
|
|
|
case Methods::get('connection.secure')->equals($method): |
36
|
|
|
$visit = $this->secure(); |
37
|
|
|
break; |
38
|
|
|
|
39
|
|
|
case Methods::get('connection.tune')->equals($method): |
40
|
|
|
$visit = $this->tune(); |
41
|
|
|
break; |
42
|
|
|
|
43
|
|
|
case Methods::get('connection.open-ok')->equals($method): |
44
|
|
|
$visit = $this->openOk(); |
45
|
|
|
break; |
46
|
|
|
|
47
|
|
|
case Methods::get('connection.close')->equals($method): |
48
|
|
|
$visit = $this->close(); |
49
|
|
|
break; |
50
|
|
|
|
51
|
|
|
case Methods::get('connection.close-ok')->equals($method): |
52
|
|
|
$visit = $this->closeOk(); |
53
|
|
|
break; |
54
|
|
|
|
55
|
|
|
default: |
56
|
|
|
throw new UnknownMethod($method); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
return $visit($arguments); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
private function start(): Arguments |
63
|
|
|
{ |
64
|
|
|
return new Arguments( |
65
|
|
|
UnsignedOctet::class, //major version |
66
|
|
|
UnsignedOctet::class, //minor version |
67
|
|
|
Table::class, //server properties |
68
|
|
|
LongString::class, //mechanisms |
69
|
|
|
LongString::class //locales |
70
|
|
|
); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
private function secure(): Arguments |
74
|
|
|
{ |
75
|
|
|
return new Arguments( |
76
|
|
|
LongString::class //challenge |
77
|
|
|
); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
private function tune(): Arguments |
81
|
|
|
{ |
82
|
|
|
return new Arguments( |
83
|
|
|
UnsignedShortInteger::class, //max channels |
84
|
|
|
UnsignedLongInteger::class, //max frame size |
85
|
|
|
UnsignedShortInteger::class //heartbeat delay |
86
|
|
|
); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
private function openOk(): Arguments |
90
|
|
|
{ |
91
|
|
|
return new Arguments( |
92
|
|
|
ShortString::class //known hosts |
93
|
|
|
); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
private function close(): Arguments |
97
|
|
|
{ |
98
|
|
|
return new Arguments( |
99
|
|
|
UnsignedShortInteger::class, //reply code |
100
|
|
|
ShortString::class, //reply text |
101
|
|
|
UnsignedShortInteger::class, //failing class id |
102
|
|
|
UnsignedShortInteger::class //failing method id |
103
|
|
|
); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
private function closeOk(): Arguments |
107
|
|
|
{ |
108
|
|
|
return new Arguments; // no arguments |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.