PHP code example of adinan-cenci / psr-17

1. Go to this page and download the library: Download adinan-cenci/psr-17 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/ */

    

adinan-cenci / psr-17 example snippets


use AdinanCenci\Psr17\ResponseFactory;

$responseFactory = new ResponseFactory();

// Returns an instance of Psr\Http\Message\ResponseInterface with 
// code 200
$factory->ok('your body here');

// 201
$factory->created('your body here');

// 301
$factory->movedPermanently('http://redirect.to');

// 302
$factory->movedTemporarily('http://redirect.to');

// 400
$factory->badRequest('your body here');

// 401
$factory->unauthorized('your body here');

// 403
$factory->forbidden('your body here');

// 404
$factory->notFound('your body here');

// 500
$factory->internalServerError('your body here');

// 501
$factory->notImplemented('your body here');

// 502
$factory->badGateway('your body here');

// 503
$factory->serviceUnavailable('your body here');

use AdinanCenci\Psr17\ServerRequestFactory;

$requestFactory = new ServerRequestFactory();

// Creates an instance of Psr\Http\Message\ServerRequestInterface
// out of the global values.
$request = $requestFactory->createFromGlobals();

use AdinanCenci\Psr17\UploadedFileFactory;

$filesFactory = new UploadedFileFactory();

// Will return the contents of $_FILES as 
// Psr\Http\Message\UploadedFileInterface instances.
$files = $filesFactory->getFilesFromGlobals();