File tree Expand file tree Collapse file tree 1 file changed +55
-0
lines changed
Expand file tree Collapse file tree 1 file changed +55
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php declare (strict_types=1 );
2+ /*
3+ * This file is part of Aplus Framework CLI Library.
4+ *
5+ * (c) Natan Felles <natanfelles@gmail.com>
6+ *
7+ * For the full copyright and license information, please view the LICENSE
8+ * file that was distributed with this source code.
9+ */
10+ namespace Framework \CLI \Streams ;
11+
12+ use JetBrains \PhpStorm \Pure ;
13+
14+ /**
15+ * Trait FilterStream.
16+ *
17+ * @package cli
18+ *
19+ * @since 2.4
20+ */
21+ trait FilterStream
22+ {
23+ protected static string $ contents = '' ;
24+
25+ /**
26+ * @param resource $in
27+ * @param resource $out
28+ * @param int $consumed
29+ * @param bool $closing
30+ *
31+ * @see https://php.net/manual/en/php-user-filter.filter.php
32+ *
33+ * @return int
34+ */
35+ public function filter ($ in , $ out , &$ consumed , $ closing ) : int
36+ {
37+ while ($ bucket = \stream_bucket_make_writeable ($ in )) {
38+ static ::$ contents .= $ bucket ->data ;
39+ $ consumed += $ bucket ->datalen ;
40+ \stream_bucket_append ($ out , $ bucket );
41+ }
42+ return \PSFS_FEED_ME ;
43+ }
44+
45+ #[Pure]
46+ public static function getContents () : string
47+ {
48+ return static ::$ contents ;
49+ }
50+
51+ public static function reset () : void
52+ {
53+ static ::$ contents = '' ;
54+ }
55+ }
You can’t perform that action at this time.
0 commit comments