This package provides a library to facilitate interacting with strings using the PSR-7 stream interface.
The goal of this package is to provide similar functionality in PHP to that of
C++'s iostream
; Analagous methods are intended to behave similarly.
To install this package using Composer, run the following command.
composer require clayfreeman/string-stream
Alternatively, the package may be downloaded from the release page on GitHub.
Some general usage examples are shown below. For more detailed information, please refer to the PSR-7 stream interface.
use ClayFreeman\StringStream\StringStream;
$stream = new StringStream('sample string');
var_export((string) $stream); // 'sample string'
// Reset the stream offset to the beginning.
var_export($stream->read(2)); // 'sa'
var_export($stream->getContents()); // 'mple string'
$stream->write('some more contents');
var_export((string) $stream); // 'sample stringsome more contents'
Tests for this package are written using PHPUnit 9. To run the tests, you'll need to have PHP 7.4 and Composer installed:
git clone https://github.com/clayfreeman/string-stream.git
cd string-stream && ./vendor/bin/phpunit
This project is subject to the terms of The MIT License. Please refer to
LICENSE.txt
for more information, or visit the following URL to get a copy of
the license: https://opensource.org/licenses/MIT