PHP code example of rareloop / psr7-server-request-extension

1. Go to this page and download the library: Download rareloop/psr7-server-request-extension 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/ */

    

rareloop / psr7-server-request-extension example snippets




namespace App;

use Rareloop\Psr7ServerRequestExtension\InteractsWithInput;
use Rareloop\Psr7ServerRequestExtension\InteractsWithUri;
use Zend\Diactoros\ServerRequest;

class MyServerRequest extends ServerRequest
{
    use InteractsWithInput, InteractsWithUri;
}

$request->path();

$request->url(); // e.g. http://test.com/path
$request->fullUrl(); // e.g. http://test.com/path?foo=bar

$request->query();

$request->query('name');
$request->query('name', 'Jane'); // Defaults to "Jane" if not set

$request->post();

$request->post('name');
$request->post('name', 'Jane'); // Defaults to "Jane" if not set

$request->input();

$request->input('name');
$request->input('name', 'Jane'); // Defaults to "Jane" if not set

if ($request->has('name')) {
    // do something
}

if ($request->has(['name', 'age'])) {
    // do something if both 'name' and 'age' are present
}