|
| 1 | +# HTTP |
| 2 | + |
| 3 | +## Form data |
| 4 | + |
| 5 | +There are several methods in [salient/http][] and [salient/curler][] (see the |
| 6 | +[list below][methods]) where data received via `mixed[] $query` and/or |
| 7 | +`mixed[]|object $data` parameters is encoded as HTML form data before it is |
| 8 | +applied to an HTTP message. |
| 9 | + |
| 10 | +`true` and `false` are encoded as `1` and `0` respectively. |
| 11 | + |
| 12 | +Keys other than `list` keys are preserved by default, but form data flags can be |
| 13 | +used to modify this behaviour, e.g. via [Curler::withFormDataFlags()][]. |
| 14 | + |
| 15 | +`DateTimeInterface` instances are converted to ISO-8601 strings unless a date |
| 16 | +formatter is given, e.g. via [Curler::withDateFormatter()][]. |
| 17 | + |
| 18 | +Before recursion, other objects are processed as follows: |
| 19 | + |
| 20 | +1. `Arrayable`: replaced with return value of [toArray()][] |
| 21 | +2. `JsonSerializable`: serialized with [Json::encode()][] and deserialized with |
| 22 | + [Json::objectAsArray()][] |
| 23 | +3. `Jsonable`: replaced with return value of [toJson()][] after it is |
| 24 | + deserialized with [Json::objectAsArray()][] |
| 25 | +4. `Traversable`: passed to `iterator_to_array()` and replaced with its return |
| 26 | + value |
| 27 | +5. `object` with at least one public property: replaced with an array that maps |
| 28 | + public property names to values |
| 29 | +6. `Stringable`: cast to `string` |
| 30 | + |
| 31 | +> Internally, [FormDataEncoder][] instances are used to recurse into query and |
| 32 | +> body data. |
| 33 | +> |
| 34 | +> If given, a callback is applied to objects other than `DateTimeInterface` |
| 35 | +> instances. It must return one of the following: |
| 36 | +> |
| 37 | +> - `null` to skip the value |
| 38 | +> - `false` to process the value as if no callback had been given |
| 39 | +> - the value as a `string` |
| 40 | +> - an `array` to recurse into |
| 41 | +> - an `object` to return without encoding |
| 42 | +> |
| 43 | +> If a `DateTimeInterface` is returned, it is converted to a string as above. |
| 44 | +
|
| 45 | +### Methods that encode HTTP message data |
| 46 | + |
| 47 | +#### `Http` |
| 48 | + |
| 49 | +- [HttpUtil::mergeQuery()][] |
| 50 | +- [HttpUtil::replaceQuery()][] |
| 51 | +- [Stream::fromData()][] |
| 52 | + |
| 53 | +#### `Curler` |
| 54 | + |
| 55 | +- [Curler::replaceQuery()][] |
| 56 | +- [Curler][] request methods: `head()`, `get()`, `post()`, `put()`, `patch()`, |
| 57 | + `delete()` |
| 58 | +- Paginated variants: `getP()`, `postP()`, `putP()`, `patchP()`, `deleteP()` |
| 59 | +- Raw variants (`$query` only): `postR()`, `putR()`, `patchR()`, `deleteR()` |
| 60 | + |
| 61 | +[Curler]: https://salient-labs.github.io/toolkit/Salient.Curler.Curler.html |
| 62 | +[Curler::replaceQuery()]: |
| 63 | + https://salient-labs.github.io/toolkit/Salient.Curler.Curler.html#_replaceQuery |
| 64 | +[Curler::withDateFormatter()]: |
| 65 | + https://salient-labs.github.io/toolkit/Salient.Curler.Curler.html#_withDateFormatter |
| 66 | +[Curler::withFormDataFlags()]: |
| 67 | + https://salient-labs.github.io/toolkit/Salient.Curler.Curler.html#_withFormDataFlags |
| 68 | +[FormDataEncoder]: ../src/Toolkit/Http/Internal/FormDataEncoder.php |
| 69 | +[HttpUtil::mergeQuery()]: |
| 70 | + https://salient-labs.github.io/toolkit/Salient.Http.HttpUtil.html#_mergeQuery |
| 71 | +[HttpUtil::replaceQuery()]: |
| 72 | + https://salient-labs.github.io/toolkit/Salient.Http.HttpUtil.html#_replaceQuery |
| 73 | +[Json::encode()]: |
| 74 | + https://salient-labs.github.io/toolkit/Salient.Utility.Json.html#_encode |
| 75 | +[Json::objectAsArray()]: |
| 76 | + https://salient-labs.github.io/toolkit/Salient.Utility.Json.html#_objectAsArray |
| 77 | +[methods]: #methods-that-encode-http-message-data |
| 78 | +[salient/curler]: https://packagist.org/packages/salient/curler |
| 79 | +[salient/http]: https://packagist.org/packages/salient/http |
| 80 | +[Stream::fromData()]: |
| 81 | + https://salient-labs.github.io/toolkit/Salient.Http.Message.Stream.html#_fromData |
| 82 | +[toArray()]: |
| 83 | + https://salient-labs.github.io/toolkit/Salient.Contract.Core.Arrayable.html#_toArray |
| 84 | +[toJson()]: |
| 85 | + https://salient-labs.github.io/toolkit/Salient.Contract.Core.Jsonable.html#_toJson |
0 commit comments