| @@ 26-47 (lines=22) @@ | ||
| 23 | /** |
|
| 24 | * @return \Closure |
|
| 25 | */ |
|
| 26 | public static function request() |
|
| 27 | { |
|
| 28 | return function (RequestInterface $request) { |
|
| 29 | echo chr(27) . '[33m' . "REQUEST: " . $request->getMethod() . ' ' . $request->getRequestTarget() . chr( |
|
| 30 | 27 |
|
| 31 | ) . "[0m\n"; |
|
| 32 | ||
| 33 | foreach ($request->getHeaders() as $key => $headers) { |
|
| 34 | foreach ($headers as $header) { |
|
| 35 | echo "${key}: ${header}\n"; |
|
| 36 | } |
|
| 37 | } |
|
| 38 | ||
| 39 | $body = (string)$request->getBody(); |
|
| 40 | echo $body; |
|
| 41 | $json = @json_decode($body, true); |
|
| 42 | if ($json === null) { |
|
| 43 | $json = []; |
|
| 44 | } |
|
| 45 | print_r($json); |
|
| 46 | }; |
|
| 47 | } |
|
| 48 | ||
| 49 | /** |
|
| 50 | * @return \Closure |
|
| @@ 56-71 (lines=16) @@ | ||
| 53 | { |
|
| 54 | return function (RequestInterface $request, $options, FulfilledPromise $responsePromise) { |
|
| 55 | $responsePromise->then( |
|
| 56 | function (ResponseInterface $response) { |
|
| 57 | echo chr(27) . '[33m' . "RESPONSE: HTTP/" . $response->getProtocolVersion() . ' ' . $response->getStatusCode() . ' ' . $response->getReasonPhrase() . chr(27) . "[0m\n"; |
|
| 58 | ||
| 59 | foreach ($response->getHeaders() as $key => $headers) { |
|
| 60 | foreach ($headers as $header) { |
|
| 61 | echo "${key}: ${header}\n"; |
|
| 62 | } |
|
| 63 | } |
|
| 64 | ||
| 65 | $body = (string)$response->getBody(); |
|
| 66 | $json = @json_decode($body, true); |
|
| 67 | if ($json === null) { |
|
| 68 | $json = []; |
|
| 69 | } |
|
| 70 | print_r($json); |
|
| 71 | } |
|
| 72 | ); |
|
| 73 | }; |
|
| 74 | } |
|