middlewares/method-override

Middleware to override the request method using the X-Http-Method-Override header

v1.1.0 2018-08-04 10:41 UTC

README

Latest Version on Packagist Software License Build Status Quality Score Total Downloads SensioLabs Insight

Middleware to override the request method using the X-Http-Method-Override header. This is useful for clients unable to send other methods than GET and POST.

Requirements

Installation

This package is installable and autoloadable via Composer as middlewares/method-override.

composer require middlewares/method-override

Example

$dispatcher = new Dispatcher([
	(new Middlewares\MethodOverride())
        ->getMethods(['HEAD', 'CONNECT', 'TRACE', 'OPTIONS'])
        ->postMethods(['PATCH', 'PUT', 'DELETE', 'COPY', 'LOCK', 'UNLOCK'])
		->queryParameter('method')
		->parsedBodyParameter('method')
]);

$response = $dispatcher->dispatch(new ServerRequest());

Options

getMethods(array $methods)

Array with the methods that can override the GET method. By default is ['HEAD', 'CONNECT', 'TRACE', 'OPTIONS'].

postMethods(array $methods)

Array with the methods that can override the POST method. By default is ['PATCH', 'PUT', 'DELETE', 'COPY', 'LOCK', 'UNLOCK'].

queryParameter(string $name)

Allows to use a query parameter in addition to the X-Http-Method-Override in GET requests.

parsedBodyParameter(string $name)

Allows to use a parsed body parameter in addition to the X-Http-Method-Override in POST.

responseFactory(Psr\Http\Message\ResponseFactoryInterface $responseFactory)

A PSR-17 factory to create 405 responses.

Please see CHANGELOG for more information about recent changes and CONTRIBUTING for contributing details.

The MIT License (MIT). Please see LICENSE for more information.