krak / stream
PHP流和过滤变得简单。
v0.1.0
2017-04-20 23:03 UTC
Requires
- peridot-php/peridot: ^1.19
Requires (Dev)
- krak/crypto: ^0.1.3
Suggests
- krak/crypto: For encrypting and decrypting streams.
This package is auto-updated.
Last update: 2024-09-18 17:42:52 UTC
README
这个库提供了一个简单的抽象层,用于php流和过滤器,使开发者能够轻松地操作流。
安装
使用composer安装krak/stream
用法
此示例展示了一个示例,说明可用的过滤器有哪些以及如何使用它们。
<?php use Krak\Stream; use Krak\Crypto; $key = random_bytes(16); $crypt = new Crypto\OpenSSLCrypt($key); $src = Stream\fromStr('abc def ghi jkl'); $dst = Stream\toOutput(); Stream\pipe($src, [ Stream\uppercase(), // utilizes string.toupper filter Stream\chunkFilter(function($chunk) { return str_replace('ABC', 'XYZ', $chunk); }), Stream\chunkFilter('str_rot13'), // performs rot13 on stream Stream\hex(), // performs bin2hex Stream\encrypt($crypt), Stream\base64Encode(), // below are the inverse functions of above which will undo the transformations Stream\base64Decode(), Stream\decrypt($crypt), Stream\unhex(), Stream\createFilter('string.rot13'), // creates a filter from a registered php filter Stream\chunkFilter(function($chunk) { return str_replace('XYZ', 'ABC', $chunk); }), Stream\lowercase(), ], $dst);
此输出的结果将是:abc def ghi jkl
。