PHP code example of shieldon / psr-http

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

    

shieldon / psr-http example snippets


composer 


$serverRequest = ServerRequestFactory::fromGlobal();

$request = RequestFactory::fromNew();

$response = ResponseFactory::fromNew();

// Create a URI contains visitor's information.

/**
 *  Assume a visior is viewing your website page, 
 *  for example, https://yoursite/en/post1.html
 */
$uri = UriFactory::fromGlobal();

echo $uri->getPath();
// Outputs: /en/post1.html

// Create a URI just a new instance.
$uri = UriFactory::fromNew();

echo $uri->getPath();
// Outputs: 

// Create a stream just a new instance.
$stream = StreamFactory::fromNew();

// Let's see the following example, 
// assume we have a superglobal $_FILES looks like this.
$_FILES = [
    'foo' => [
        'name' => 'example1.jpg',
        'type' => 'image/jpeg',
        'tmp_name' => '/tmp/php200A.tmp',
        'error' => 0,
        'size' => 100000,
    ]
];

$uploadFileArr = UploadedFileFactory::fromGlobal();

echo $uploadFileArr['foo']->getClientFilename();
// Outputs: example1.jpg