PHP code example of middlewares / method-override

1. Go to this page and download the library: Download middlewares/method-override library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

middlewares / method-override example snippets


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

$responseFactory = new MyOwnResponseFactory();

$override = new Middlewares\MethodOverride($responseFactory);

//The GET method can be overrided only with HEAD and CONNECT
$override = (new Middlewares\MethodOverride())->getMethods(['HEAD', 'CONNECT']);

//The POST method can be overrided only with DELETE and PUT 
$override = (new Middlewares\MethodOverride())->getMethods(['DELETE', 'PUT']);

//The method can be override with ?new_method=OPTIONS
$override = (new Middlewares\MethodOverride())->queryParameter('new_method');