|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types = 1); |
|
3
|
|
|
|
|
4
|
|
|
namespace Innmind\AMQP\Transport\Frame\Value; |
|
5
|
|
|
|
|
6
|
|
|
use Innmind\Immutable\{ |
|
7
|
|
|
Map, |
|
8
|
|
|
Pair |
|
9
|
|
|
}; |
|
10
|
|
|
|
|
11
|
|
|
final class Symbols |
|
12
|
|
|
{ |
|
13
|
|
|
private static $symbols; |
|
14
|
|
|
private static $classes; |
|
15
|
|
|
|
|
16
|
|
|
private function __construct() |
|
17
|
|
|
{ |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
158 |
|
public static function symbol(string $class): string |
|
21
|
|
|
{ |
|
22
|
158 |
|
self::init(); |
|
23
|
|
|
|
|
24
|
158 |
|
return self::$classes->get($class); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public static function class(string $symbol): string |
|
|
|
|
|
|
28
|
|
|
{ |
|
29
|
|
|
self::init(); |
|
30
|
|
|
|
|
31
|
|
|
return self::$symbols->get($symbol); |
|
|
|
|
|
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
158 |
|
private static function init(): void |
|
35
|
|
|
{ |
|
36
|
158 |
|
if (!is_null(self::$symbols)) { |
|
37
|
158 |
|
return; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
2 |
|
self::$symbols = (new Map('string', 'string')) |
|
41
|
2 |
|
->put('b', SignedOctet::class) |
|
42
|
2 |
|
->put('B', UnsignedOctet::class) |
|
43
|
2 |
|
->put('U', SignedShortInteger::class) |
|
44
|
2 |
|
->put('u', UnsignedShortInteger::class) |
|
45
|
2 |
|
->put('I', SignedLongInteger::class) |
|
46
|
2 |
|
->put('i', UnsignedLongInteger::class) |
|
47
|
2 |
|
->put('L', SignedLongLongInteger::class) |
|
48
|
2 |
|
->put('l', UnsignedLongLongInteger::class) |
|
49
|
2 |
|
->put('D', Decimal::class) |
|
50
|
2 |
|
->put('T', Timestamp::class) |
|
51
|
2 |
|
->put('V', VoidValue::class) |
|
52
|
2 |
|
->put('t', Bits::class) |
|
53
|
2 |
|
->put('s', ShortString::class) |
|
54
|
2 |
|
->put('S', LongString::class) |
|
55
|
2 |
|
->put('A', Sequence::class) |
|
56
|
2 |
|
->put('F', Table::class); |
|
57
|
2 |
|
self::$classes = self::$symbols->map(static function(string $symbol, string $class): Pair { |
|
58
|
2 |
|
return new Pair($class, $symbol); |
|
59
|
2 |
|
}); |
|
60
|
2 |
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|