Extends middlewares/payload to add support for parsing the CSV body of the request.
- PHP >= 7.0
- A PSR-7 http message implementation (Diactoros, Guzzle, Slim, etc...)
- A PSR-15 middleware dispatcher
This package is installable and autoloadable via Composer as middlewares/csv-payload.
composer require middlewares/csv-payloadParses the CSV payload of the request. Uses league/csv to read the CSV values. Contains the following options to configure the CSV Reader object:
To configure the CSV delimiter control character (one character only). If the submitted character is invalid an InvalidArgumentException exception is thrown.
To configure the CSV enclosure control character (one character only). If the submitted character is invalid an InvalidArgumentException exception is thrown.
To configure the CSV escape control character (one character only). If the submitted character is invalid an InvalidArgumentException exception is thrown.
To configure the CSV header line. If the submitted header value is less than 0 an InvalidArgumentException exception is thrown.
To configure the allowed methods. By default only the requests with the method POST, PUT, PATCH, DELETE, COPY, LOCK, UNLOCK are handled.
To configure all Content-Type headers used in the request. By default is text/csv
To override the previous parsed body if exists (false by default)
$dispatcher = new Dispatcher([
(new \Middlewares\CsvPayload())
->delimiter(";")
->enclosure("'")
->escape("\\")
]);
$response = $dispatcher->dispatch(new ServerRequest());Please see CHANGELOG for more information about recent changes and CONTRIBUTING for contributing details.
The MIT License (MIT). Please see LICENSE for more information.