A set of generic stream wrappers
Find a file
Robin Appelman fd996aea9c Fix case
2014-07-24 01:44:48 +02:00
src Fix case 2014-07-24 01:44:48 +02:00
tests Fix case 2014-07-24 01:44:48 +02:00
.gitignore initial version 2014-07-23 23:02:10 +02:00
.travis.yml also test on 5.3 2014-07-23 23:03:36 +02:00
composer.json lower case package name 2014-07-24 00:18:30 +02:00
README.md Add Wrapper::wrap() convenience method 2014-07-24 01:07:35 +02:00

#Streams#

Build Status Coverage Status

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');

stream_wrapper_register('callback', '\Icewind\Streams\CallbackWrapper');

// 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()