A set of generic stream wrappers
Find a file
Vincent Petry 668abfee80
Prevent duplicate closeCallback calls in case of GC ghosts
Sometimes PHP 7 GC decides to call stream_close again even after the
PHP request has ended, and even if fclose was called before already.
2016-12-02 14:57:57 +01:00
src Prevent duplicate closeCallback calls in case of GC ghosts 2016-12-02 14:57:57 +01:00
tests add PathWrapper to get a virtual path for an existing file 2016-10-26 22:08:04 +02:00
.gitignore initial version 2014-07-23 23:02:10 +02:00
.travis.yml remove php7 from allowed failures 2016-03-17 13:32:25 +01:00
composer.json proper coverals version for older php support 2016-03-16 14:27:16 +01:00
LICENCE Create LICENCE 2015-09-01 16:56:35 +02:00
README.md Add scrutinizer badge 2014-08-27 12:45:15 +02:00

#Streams#

Build Status Coverage Status Scrutinizer Code Quality

Generic stream wrappers for php.

##CallBackWrapper##

A CallBackWrapper can be used to register callbacks on read, write and closing of the stream, it wraps an existing stream and can thus be used for any stream in php

The callbacks are passed in the stream context along with the source stream and can be any valid php callable

###Example###

<?php

use \Icewind\Streams\CallBackWrapper;

require('vendor/autoload.php');

// get an existing stream to wrap
$source = fopen('php://temp', 'r+');

// register the callbacks
$stream = CallbackWrapper::wrap($source,
	// read callback
	function ($count) {
		echo "read " . $count . "bytes\n";
	},
	// write callback
	function ($data) {
		echo "wrote '" . $data . "'\n";
	},
	// close callback
	function () {
		echo "stream closed\n";
	});

fwrite($stream, 'some dummy data');

rewind($stream);
fread($stream, 5);

fclose($stream);

Note: due to php's internal stream buffering the $count passed to the read callback will be equal to php's internal buffer size (8192 on default) an not the number of bytes requested by fopen()