| Conditions | 6 |
| Paths | 18 |
| Total Lines | 26 |
| Code Lines | 16 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| Bugs | 1 | Features | 1 |
| 1 | <?php |
||
| 19 | public function formatRequest(RequestInterface $request) |
||
| 20 | { |
||
| 21 | $command = sprintf('curl %s', escapeshellarg($request->getUri())); |
||
| 22 | if ($request->getProtocolVersion() === '1.0') { |
||
| 23 | $command .= ' --http1.0'; |
||
| 24 | } elseif ($request->getProtocolVersion() === '2.0') { |
||
| 25 | $command .= ' --http2'; |
||
| 26 | } |
||
| 27 | |||
| 28 | $command .= ' --request '.$request->getMethod(); |
||
| 29 | |||
| 30 | foreach ($request->getHeaders() as $name => $values) { |
||
| 31 | $command .= sprintf(' -H %s', escapeshellarg($name.': '.$request->getHeaderLine($name))); |
||
| 32 | } |
||
| 33 | |||
| 34 | $body = $request->getBody(); |
||
| 35 | if ($body->getSize() > 0) { |
||
| 36 | if (!$body->isSeekable()) { |
||
| 37 | throw new \RuntimeException('Cannot take data from a stream that is not seekable'); |
||
| 38 | } |
||
| 39 | $command .= sprintf(' --data %s', escapeshellarg($body->__toString())); |
||
| 40 | $body->rewind(); |
||
| 41 | } |
||
| 42 | |||
| 43 | return $command; |
||
| 44 | } |
||
| 45 | |||
| 54 |