prewk/file-chainer

支持插入的链式文件流写入器

0.3.0 2014-12-14 11:06 UTC

This package is auto-updated.

Last update: 2024-08-29 03:35:47 UTC


README

这是什么?

这是一个针对一些PHP文件流函数的小型包装器,支持在不覆盖的情况下向流中插入数据。(也是:链式。)

安装

添加到composer

require: {
    "prewk/file-chainer": "dev-master"
}

然后运行 composer install

用法

两个新的文件流方法

  • finsert 在当前文件流位置插入字符串
  • finsertcsv 在当前文件流位置插入CSV(类似于 fputcsv)行

插入与链式操作

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

使用静态方法插入

$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