zenstruck / stream
Object wrapper for PHP resources.
Fund package maintenance!
kbond
Installs: 7 514
Dependents: 1
Suggesters: 0
Security: 0
Stars: 3
Watchers: 3
Forks: 1
Open Issues: 0
Requires
- php: >=8.0
Requires (Dev)
- phpstan/phpstan: ^1.4
- phpunit/phpunit: ^9.5.0
- symfony/phpunit-bridge: ^6.1
- symfony/var-dumper: ^5.4|^6.0
README
Object wrapper for PHP resources.
Installation
composer require zenstruck/stream
API
Create Stream Object
use Zenstruck\Stream; // wrap $stream = Stream::wrap($resource); $stream = Stream::wrap('string'); $stream = Stream::wrap($stream); // open $stream = Stream::open('some/file.txt', 'r'); // php://memory $stream = Stream::inMemory(); // php://output $stream = Stream::inOutput(); // \tmpfile() $stream = Stream::tempFile(); // autoclose on $stream __destruct $stream->autoClose(); // Stream
Use Stream Object
/** @var \Zenstruck\Stream $stream */ // metadata $stream->id(); // int - the resource id $stream->type(); // string - the resource type $stream->metadata(); // array - the resources metadata $stream->metadata('wrapper_type'); // mixed - specific resource metadata key $stream->uri(); // string - shortcut for `$stream->metadata('uri')` // read $stream->get(); // resource - the raw, wrapped resource $stream->contents(); // string - the contents of the resource (auto-rewound) // write $stream->write($resource); // self - write another resource to the stream $stream->write('string'); // self - write a string to the stream $stream->write($anotherStream); // self - write another \Zenstruck\Stream instance to the stream // manipulate $stream->close(); // no-return - close the resource (if open) $stream->rewind(); // self - rewind the stream