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