PHP code example of sbsedv / input-converter

1. Go to this page and download the library: Download sbsedv/input-converter 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/ */

    

sbsedv / input-converter example snippets


 declare(strict_types=1);

use SBSEDV\InputConverter\InputConverter;
use SBSEDV\InputConverter\Request\HttpFoundationRequest;
use SBSEDV\InputConverter\Request\Psr7Request;

$request = new HttpFoundationRequest($request);
// $request = new Psr7Request($request);

try {
    (new InputConverter())
        ->addConverter(...) // your converters
        ->convert($request);
} catch (MalformedContentException $e) {
    // a converter supported the request
    // but encountered an error while parsing

    http_status_code(400);
    exit();
} catch (UnsupportedRequestException) {
    // no converter supported the request
}

public function __construct(
    array $methods = ['PUT', 'PATCH', 'DELETE']
);

public function __construct(
    array $contentTypes = ['application/json'],
    array $methods = ['POST', 'PUT', 'PATCH', 'DELETE']
);

public function __construct(
    array $methods = ['PUT', 'PATCH', 'DELETE'],
    bool $fileSupport = false
);