@@ -31,51 +31,51 @@ |
||
31 | 31 | */ |
32 | 32 | final class UrlEncodedRequest extends Request |
33 | 33 | { |
34 | - public const ENCODING_TYPE_RFC1738 = PHP_QUERY_RFC1738; |
|
35 | - public const ENCODING_TYPE_RFC3986 = PHP_QUERY_RFC3986; |
|
34 | + public const ENCODING_TYPE_RFC1738 = PHP_QUERY_RFC1738; |
|
35 | + public const ENCODING_TYPE_RFC3986 = PHP_QUERY_RFC3986; |
|
36 | 36 | |
37 | - /** |
|
38 | - * @param mixed $uri |
|
39 | - * @param array<array-key, mixed>|object $data |
|
40 | - * @param self::ENCODING_TYPE_* $encodingType |
|
41 | - * |
|
42 | - * @throws InvalidArgumentException |
|
43 | - */ |
|
44 | - public function __construct(string $method, $uri, $data, int $encodingType = self::ENCODING_TYPE_RFC1738) |
|
45 | - { |
|
46 | - /** |
|
47 | - * @psalm-suppress DocblockTypeContradiction |
|
48 | - * @phpstan-ignore-next-line |
|
49 | - */ |
|
50 | - if (!is_array($data) && !is_object($data)) { |
|
51 | - throw new TypeError(sprintf( |
|
52 | - 'Argument #3 ($data) must be of type string, %s given', |
|
53 | - gettype($data), |
|
54 | - )); |
|
55 | - } |
|
37 | + /** |
|
38 | + * @param mixed $uri |
|
39 | + * @param array<array-key, mixed>|object $data |
|
40 | + * @param self::ENCODING_TYPE_* $encodingType |
|
41 | + * |
|
42 | + * @throws InvalidArgumentException |
|
43 | + */ |
|
44 | + public function __construct(string $method, $uri, $data, int $encodingType = self::ENCODING_TYPE_RFC1738) |
|
45 | + { |
|
46 | + /** |
|
47 | + * @psalm-suppress DocblockTypeContradiction |
|
48 | + * @phpstan-ignore-next-line |
|
49 | + */ |
|
50 | + if (!is_array($data) && !is_object($data)) { |
|
51 | + throw new TypeError(sprintf( |
|
52 | + 'Argument #3 ($data) must be of type string, %s given', |
|
53 | + gettype($data), |
|
54 | + )); |
|
55 | + } |
|
56 | 56 | |
57 | - parent::__construct($method, $uri); |
|
57 | + parent::__construct($method, $uri); |
|
58 | 58 | |
59 | - $this->setBody(self::createBody($data, $encodingType)); |
|
60 | - $this->setHeader('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8'); |
|
61 | - } |
|
59 | + $this->setBody(self::createBody($data, $encodingType)); |
|
60 | + $this->setHeader('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8'); |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * @param array<array-key, mixed>|object $data |
|
65 | - * @param self::ENCODING_TYPE_* $encodingType |
|
66 | - */ |
|
67 | - private static function createBody($data, int $encodingType): StreamInterface |
|
68 | - { |
|
69 | - if ($data instanceof StreamInterface) { |
|
70 | - return $data; |
|
71 | - } |
|
63 | + /** |
|
64 | + * @param array<array-key, mixed>|object $data |
|
65 | + * @param self::ENCODING_TYPE_* $encodingType |
|
66 | + */ |
|
67 | + private static function createBody($data, int $encodingType): StreamInterface |
|
68 | + { |
|
69 | + if ($data instanceof StreamInterface) { |
|
70 | + return $data; |
|
71 | + } |
|
72 | 72 | |
73 | - $encodedData = http_build_query($data, '', '&', $encodingType); |
|
73 | + $encodedData = http_build_query($data, '', '&', $encodingType); |
|
74 | 74 | |
75 | - $stream = new PhpTempStream('r+b'); |
|
76 | - $stream->write($encodedData); |
|
77 | - $stream->rewind(); |
|
75 | + $stream = new PhpTempStream('r+b'); |
|
76 | + $stream->write($encodedData); |
|
77 | + $stream->rewind(); |
|
78 | 78 | |
79 | - return $stream; |
|
80 | - } |
|
79 | + return $stream; |
|
80 | + } |
|
81 | 81 | } |