prewk / file-chainer
Chainable file stream writer with insert support
0.3.0
2014-12-14 11:06 UTC
Requires
- php: >=5.3.0
Requires (Dev)
- mockery/mockery: dev-master
README
What is it?
A small wrapper for some php file streaming functions with support for inserting data into streams without overwriting. (Also: chainable.)
Installation
Add to composer:
require: { "prewk/file-chainer": "dev-master" }
And run composer install
.
Usage
Two new file stream methods:
finsert
inserts a string at the current file stream positionfinsertcsv
inserts a csv (like fputcsv) line at the current file stream position
Inserting & chaining
Prewk\FileChainer::make() ->fopen("/foo/bar.txt", "w+") ->fwrite("foo") ->rewind() ->finsert("bar") ->fclose(); echo file_get_contents("/foo/bar.txt"); // Output: barfoo // The handle's file pointer = 3
Inserting with static method
$handle = fopen("/foo/bar.txt", "w+"); fwrite($handle, "foo"); rewind($handle); // Statically, using the default "temporary file stream" method Prewk\FileChainer\Inserters\File::finsert($handle, "bar"); fclose($handle); echo file_get_contents("/foo/bar.txt"); // Output: barfoo // The handle's file pointer = 3