Form.php
5 years ago
FormPart.php
5 years ago
Json.php
5 years ago
Multipart.php
5 years ago
Text.php
5 years ago
Text.php
39 lines
| 1 | <?php |
| 2 | |
| 3 | namespace PayPalHttp\Serializer; |
| 4 | |
| 5 | use PayPalHttp\HttpRequest; |
| 6 | use PayPalHttp\Serializer; |
| 7 | |
| 8 | /** |
| 9 | * Class Text |
| 10 | * @package PayPalHttp\Serializer |
| 11 | * |
| 12 | * Serializer for Text content types. |
| 13 | */ |
| 14 | class Text implements Serializer |
| 15 | { |
| 16 | |
| 17 | public function contentType() |
| 18 | { |
| 19 | return "/^text\\/.*/"; |
| 20 | } |
| 21 | |
| 22 | public function encode(HttpRequest $request) |
| 23 | { |
| 24 | $body = $request->body; |
| 25 | if (is_string($body)) { |
| 26 | return $body; |
| 27 | } |
| 28 | if (is_array($body)) { |
| 29 | return json_encode($body); |
| 30 | } |
| 31 | return implode(" ", $body); |
| 32 | } |
| 33 | |
| 34 | public function decode($data) |
| 35 | { |
| 36 | return $data; |
| 37 | } |
| 38 | } |
| 39 |