1 | <?php |
||
26 | class Client |
||
27 | { |
||
28 | /** |
||
29 | * Client will return null if server error happened |
||
30 | */ |
||
31 | const ERRMODE_SILENT = 0; |
||
32 | |||
33 | /** |
||
34 | * Client will throw exception if server error happened |
||
35 | */ |
||
36 | const ERRMODE_EXCEPTION = 2; |
||
37 | |||
38 | /** |
||
39 | * @var AbstractInvoke[] |
||
40 | */ |
||
41 | private $units = []; |
||
42 | |||
43 | /** |
||
44 | * @var bool |
||
45 | */ |
||
46 | private $isSingleRequest = true; |
||
47 | |||
48 | /** |
||
49 | * @var RequestBuilder |
||
50 | */ |
||
51 | private $requestBuilder; |
||
52 | |||
53 | /** |
||
54 | * @var AbstractTransport |
||
55 | */ |
||
56 | private $transport; |
||
57 | |||
58 | /** |
||
59 | * @var ResponseParser |
||
60 | */ |
||
61 | private $responseParser; |
||
62 | |||
63 | /** |
||
64 | * @var IdGeneratorInterface |
||
65 | */ |
||
66 | private $generatorId; |
||
67 | |||
68 | /** |
||
69 | * @var int |
||
70 | */ |
||
71 | private $serverErrorMode; |
||
72 | |||
73 | /** |
||
74 | * Client constructor. |
||
75 | * |
||
76 | * @param string $url |
||
77 | * @param int $serverErrorMode |
||
78 | */ |
||
79 | public function __construct(string $url, int $serverErrorMode = self::ERRMODE_SILENT) |
||
87 | |||
88 | /** |
||
89 | * @return RequestBuilder |
||
90 | */ |
||
91 | public function getRequestBuilder(): RequestBuilder |
||
95 | |||
96 | /** |
||
97 | * @return AbstractTransport |
||
98 | */ |
||
99 | public function getTransport(): AbstractTransport |
||
103 | |||
104 | /** |
||
105 | * Set transport engine |
||
106 | * |
||
107 | * @param AbstractTransport $transport |
||
108 | */ |
||
109 | public function setTransport(AbstractTransport $transport) |
||
113 | |||
114 | /** |
||
115 | * @return ResponseParser |
||
116 | */ |
||
117 | public function getResponseParser() |
||
121 | |||
122 | /** |
||
123 | * @param ResponseParser $responseParser |
||
124 | */ |
||
125 | public function setResponseParser($responseParser) |
||
129 | |||
130 | /** |
||
131 | * @return IdGeneratorInterface |
||
132 | */ |
||
133 | public function getGeneratorId(): IdGeneratorInterface |
||
137 | |||
138 | /** |
||
139 | * @param IdGeneratorInterface $idGenerator |
||
140 | */ |
||
141 | public function setIdGenerator(IdGeneratorInterface $idGenerator) |
||
145 | |||
146 | /** |
||
147 | * Make request |
||
148 | * |
||
149 | * @param string $method |
||
150 | * @param array $parameters |
||
151 | * |
||
152 | * @return $this|mixed |
||
153 | * @throws JsonRpcException |
||
154 | */ |
||
155 | public function call(string $method, array $parameters) |
||
187 | |||
188 | /** |
||
189 | * Make notification request |
||
190 | * |
||
191 | * @param string $method |
||
192 | * @param array $parameters |
||
193 | * |
||
194 | * @return $this|null |
||
195 | */ |
||
196 | public function notification(string $method, array $parameters) |
||
211 | |||
212 | /** |
||
213 | * Start batch request |
||
214 | * |
||
215 | * @return $this |
||
216 | */ |
||
217 | public function batch() |
||
223 | |||
224 | /** |
||
225 | * Execute batch request |
||
226 | * |
||
227 | * @return array |
||
228 | */ |
||
229 | public function batchExecute() |
||
263 | |||
264 | /** |
||
265 | * @param InvokeSpec $call |
||
266 | * |
||
267 | * @return ResultSpec |
||
268 | */ |
||
269 | private function execute(InvokeSpec $call): ResultSpec |
||
276 | } |
||
277 |