1 | <?php |
||
7 | class Input |
||
8 | { |
||
9 | /** |
||
10 | * This is the minimal schema that all incoming payloads must |
||
11 | * conform to in order to be considered actual JSON-RPC requests. |
||
12 | */ |
||
13 | private const INPUT_SCHEMA = <<<'JSON' |
||
14 | { |
||
15 | "$schema": "https://json-schema.org/draft-07/schema#", |
||
16 | "description": "JSON-RPC 2.0 single request schema", |
||
17 | |||
18 | "type": "object", |
||
19 | "required": ["jsonrpc", "method"], |
||
20 | "additionalProperties": false, |
||
21 | "properties": { |
||
22 | "jsonrpc": { |
||
23 | "type": "string", |
||
24 | "enum": ["2.0"] |
||
25 | }, |
||
26 | "method": { |
||
27 | "type": "string" |
||
28 | }, |
||
29 | "params": { |
||
30 | "type": ["array", "object"] |
||
31 | }, |
||
32 | "id": { |
||
33 | "type": ["integer", "string"] |
||
34 | } |
||
35 | } |
||
36 | } |
||
37 | JSON; |
||
38 | |||
39 | /** |
||
40 | * @var \stdClass |
||
41 | */ |
||
42 | private static $schema; |
||
43 | |||
44 | /** |
||
45 | * @var mixed |
||
46 | */ |
||
47 | private $data; |
||
48 | |||
49 | /** |
||
50 | * @var int |
||
51 | */ |
||
52 | private $error; |
||
53 | |||
54 | 33 | private function __construct($data, int $error) |
|
59 | |||
60 | 33 | public static function fromString(string $raw): Input |
|
64 | |||
65 | 4 | public static function fromSafeData($data): Input |
|
71 | |||
72 | 29 | public function data() |
|
73 | { |
||
74 | 29 | return $this->data; |
|
75 | } |
||
76 | |||
77 | 33 | public function parsable(): bool |
|
81 | |||
82 | 31 | public function isArray(): bool |
|
86 | |||
87 | 18 | public function isRpcRequest(): bool |
|
95 | } |
||
96 |