Total Complexity | 6 |
Total Lines | 56 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
1 | <?php |
||
9 | class ProtocolTool |
||
10 | { |
||
11 | /** |
||
12 | * protocol request code |
||
13 | */ |
||
14 | public const PRODUCE_REQUEST = 0; |
||
15 | public const METADATA_REQUEST = 3; |
||
16 | |||
17 | /** |
||
18 | * @var Protocol[] |
||
19 | */ |
||
20 | protected static $objects = []; |
||
21 | |||
22 | /** |
||
23 | * @param string $version |
||
24 | */ |
||
25 | public static function init(string $version): void |
||
26 | { |
||
27 | $class = [ |
||
28 | Protocol::PRODUCE_REQUEST => Produce::class, |
||
29 | Protocol::METADATA_REQUEST => Metadata::class, |
||
30 | ]; |
||
31 | |||
32 | foreach ($class as $key => $className) { |
||
33 | self::$objects[$key] = new $className($version); |
||
34 | } |
||
35 | } |
||
36 | |||
37 | /** |
||
38 | * @param int $key |
||
39 | * @param array $payloads |
||
40 | * @return string |
||
41 | * @throws Exception |
||
42 | */ |
||
43 | public static function encode(int $key, array $payloads): string |
||
50 | } |
||
51 | |||
52 | /** |
||
53 | * @param int $key |
||
54 | * @param string $data |
||
55 | * @return array |
||
56 | * @throws Exception |
||
57 | */ |
||
58 | public static function decode(int $key, string $data): array |
||
67 |