Download the PHP package sbsedv/input-converter without Composer
On this page you can find all versions of the php package sbsedv/input-converter. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download sbsedv/input-converter
More information about sbsedv/input-converter
Files in sbsedv/input-converter
Package input-converter
Short Description A minimal PHP library to nativly support PUT, PATCH and DELETE user input in form of mutlipart/form-data, application/x-www-form-urlencoded and various JSON types like application/json with complex data structures (nested html forms).
License MIT
Informations about the package input-converter
sbsedv/input-converter
A minimal PHP component to nativly support user input parsing on http methods other than POST.
PHP natively only supports the parsing of multipart/form-data and application/x-www-form-urlencoded on POST http requests.
Many modern web applications also want use / support a) other http methods like PUT or PATCH and b) other content encodings like JSON or XML.
This component provides a very simple and extensible object oriented api to support just that.
Internally this component uses the PHP native functions json_decode and parse_str (multpart/form-data gets "translated" to x-www-form-urlencoded) and therefore complex data structures (arrays and objects) are only limited by what those functions support.
This effectifly means that HTMLForms like the following are FULLY supported
.
How it Works
You should instantiate and call this component as early in your app lifecycle as possible.
You MUST either pass a PSR-7 or HTTP-Foundation request wrapper object to the "convert" method.
The decoded body data is automatically added to the underlying Psr7 or Http-Foundation request object.
Caution: Psr7 request are immutable. You can get the new object by calling $request->getRequest()
.
Converters
The actual parsing is handled by converter classes that implement SBSEDV\InputConverter\Converter\ConverterInterface.
You can always implement your own converter.
By default we support three customisable converters:
SBSEDV\InputConverter\Converter\UrlEncodedConverter
Via its constructor you can influence which http methods it supports.
SBSEDV\InputConverter\Converter\JsonConverter
Via its constructor you can influence which content types and http methods it supports.
SBSEDV\InputConverter\Converter\FormDataConverter
Via its constructor you can influence which content types and http methods it supports.
Internally this uses the riverline/multipart-parser library for parsing.