CurlCommandFormatter.php
6 months ago
FullHttpMessageFormatter.php
6 months ago
SimpleFormatter.php
6 months ago
SimpleFormatter.php
43 lines
| 1 | <?php |
| 2 | |
| 3 | namespace AmeliaHttp\Message\Formatter; |
| 4 | |
| 5 | use AmeliaHttp\Message\Formatter; |
| 6 | use AmeliaVendor\Psr\Http\Message\RequestInterface; |
| 7 | use AmeliaVendor\Psr\Http\Message\ResponseInterface; |
| 8 | |
| 9 | /** |
| 10 | * Normalize a request or a response into a string or an array. |
| 11 | * |
| 12 | * @author Joel Wurtz <joel.wurtz@gmail.com> |
| 13 | * @author Márk Sági-Kazár <mark.sagikazar@gmail.com> |
| 14 | */ |
| 15 | class SimpleFormatter implements Formatter |
| 16 | { |
| 17 | /** |
| 18 | * {@inheritdoc} |
| 19 | */ |
| 20 | public function formatRequest(RequestInterface $request) |
| 21 | { |
| 22 | return sprintf( |
| 23 | '%s %s %s', |
| 24 | $request->getMethod(), |
| 25 | $request->getUri()->__toString(), |
| 26 | $request->getProtocolVersion() |
| 27 | ); |
| 28 | } |
| 29 | |
| 30 | /** |
| 31 | * {@inheritdoc} |
| 32 | */ |
| 33 | public function formatResponse(ResponseInterface $response) |
| 34 | { |
| 35 | return sprintf( |
| 36 | '%s %s %s', |
| 37 | $response->getStatusCode(), |
| 38 | $response->getReasonPhrase(), |
| 39 | $response->getProtocolVersion() |
| 40 | ); |
| 41 | } |
| 42 | } |
| 43 |