# PHP package for managing HTTP Stream and base HTTP Message
The HttpSoft\Stream package implements Psr\Http\Message\StreamInterface and Psr\Http\Message\MessageInterface in accordance with the RFC 7230 and RFC 7231 specifications.
The HTTP stream and HTTP message are the basic components for implementing HTTP requests and HTTP responses. Independently, these components are rarely used, but this package gives such an opportunity.
This package requires PHP version 7.4 or later.
Package installation:
composer require httpsoft/http-stream # API
- HttpSoft\Stream\MessageTrait — trait implementing the methods defined in Psr\Http\Message\MessageInterface, used within HttpSoft\Stream\Stream and HttpSoft\Stream\StreamPhpInput.
- HttpSoft\Stream\Stream — class, that implements Psr\Http\Message\StreamInterface.
- HttpSoft\Stream\StreamFactory — factory for creating HttpSoft\Stream\Stream and HttpSoft\Stream\StreamPhpInput, implements Psr\Http\Message\StreamFactoryInterface.
- HttpSoft\Stream\StreamPhpInput — preferred implementation Psr\Http\Message\StreamInterface for reading the HTTP stream (
php://input) or file. - HttpSoft\Stream\StreamTrait — trait implementing the methods defined in Psr\Http\Message\StreamInterface.
# Usage
use HttpSoft\Stream\Stream;
use HttpSoft\Stream\StreamFactory;
$stream = new Stream('php://temp', 'wb+');
// equivalently to:
$stream = StreamFactory::create('php://temp', 'wb+');
$stream->getMetadata('uri'); // 'php://temp'
$stream->getMetadata('mode'); // 'w+b'
$stream->getContents(); // ''
$stream->isReadable(); // true
$stream->isSeekable(); // true
$stream->isWritable(); // true
$stream->write('content');
$stream->__toString(); // 'content'
// equivalently to:
(string) $stream; // echo $stream;
$stream->close();
$stream->isReadable(); // false
$stream->isSeekable(); // false
$stream->isWritable(); // false Detailed description of using HttpSoft\Stream\Stream see here.
use HttpSoft\Stream\StreamFactory;
use HttpSoft\Stream\StreamPhpInput;
$stream = new StreamPhpInput();
// equivalently to:
$stream = StreamFactory::create('php://input');
$stream->getMetadata('uri'); // 'php://input'
$stream->getMetadata('mode'); // 'rb'
$stream->getContents(); // ''
$stream->isReadable(); // true
$stream->isSeekable(); // true
$stream->isWritable(); // false
$stream = new StreamPhpInput('path/to/file');
$stream->read(1); // 'c'
$stream->getContents(); // 'ontent'
(string) $stream; // 'content' Detailed description of using HttpSoft\Stream\StreamPhpInput see here.
