1 | <?php |
||
21 | class MessageFactory implements MessageFactoryInterface |
||
22 | { |
||
23 | /** |
||
24 | * @param string $method |
||
25 | * @param string $uri |
||
26 | * @param array $headers |
||
27 | * @param array $options |
||
28 | * |
||
29 | * @return RequestInterface |
||
30 | */ |
||
31 | 1 | public function createRequest($method, $uri, array $headers = [], array $options = []) |
|
32 | { |
||
33 | 1 | $body = JsonRpc\json_encode($this->addIdToRequest($method, $options)); |
|
34 | |||
35 | 1 | return new Request('POST', $uri, $headers, $body === false ? null : $body); |
|
36 | } |
||
37 | |||
38 | /** |
||
39 | * @param int $statusCode |
||
40 | * @param array $headers |
||
41 | * @param array $options |
||
42 | * |
||
43 | * @return ResponseInterface |
||
44 | */ |
||
45 | 2 | public function createResponse($statusCode, array $headers = [], array $options = []) |
|
46 | { |
||
47 | 2 | $body = JsonRpc\json_encode($options); |
|
48 | |||
49 | 2 | return new Response($statusCode, $headers, $body === false ? null : $body); |
|
50 | } |
||
51 | |||
52 | /** |
||
53 | * @param HttpRequestInterface $request |
||
54 | * |
||
55 | * @return RequestInterface |
||
56 | */ |
||
57 | public function fromRequest(HttpRequestInterface $request) |
||
66 | |||
67 | /** |
||
68 | * @param HttpResponseInterface $response |
||
69 | * |
||
70 | * @return ResponseInterface |
||
71 | */ |
||
72 | public function fromResponse(HttpResponseInterface $response) |
||
80 | |||
81 | /** |
||
82 | * @param string $method |
||
83 | * @param array $data |
||
84 | * |
||
85 | * @return array |
||
86 | */ |
||
87 | 1 | protected function addIdToRequest($method, array $data) |
|
95 | } |
||
96 |