PHP code example of kuyoto / psr7-streams

1. Go to this page and download the library: Download kuyoto/psr7-streams 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/ */

    

kuyoto / psr7-streams example snippets


use Kuyoto\Psr7\Stream\StringStream;
use Kuyoto\Psr7\Stream\ConcatenatedStream;

$a = new StringStream('foo');
$b = new StringStream('bar');

$composed = new ConcatenatedStream([$a, $b]);

echo $composed; // foobar.

use Kuyoto\Psr7\Stream\StringStream;
use Kuyoto\Psr7\Stream\NoSeekStream;

$stream = new StringStream('foo');
$noSeek = new NoSeekStream($stream);

echo $noSeek->read(3); // foo

var_export($noSeek->isSeekable()); // false

$noSeek->seek(0);

var_export($noSeek->read(3)); // NULL

use Kuyoto\Psr7\Stream\NullStream;

$stream = new NullStream();

echo $stream->read(3); // ''
var_export($stream->getSize()); // NULL

use Kuyoto\Psr7\Stream\StringStream;

$stream = new StringStream('foo');

echo $stream->read(2); // fo

var_export($stream->getSize()); // 3