Annotation of embedaddon/php/ext/standard/tests/filters/read.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: stream filter - reading
3: --FILE--
4: <?php
5: echo "-TEST\n";
6: class filter extends php_user_filter {
7: function filter($in, $out, &$consumed, $closing)
8: {
9: $output = 0;
10: while ($bucket = stream_bucket_make_writeable($in)) {
11: $bucket->data = strtoupper($bucket->data);
12: $consumed += $bucket->datalen;
13: stream_bucket_append($out, $bucket);
14: $output = 1;
15: }
16: if ($closing) {
17: $bucket = stream_bucket_new($this->stream, "\n===close===\n");
18: stream_bucket_append($out, $bucket);
19: $output = 1;
20: }
21: return $output ? PSFS_PASS_ON : PSFS_FEED_ME;
22: }
23: }
24: stream_filter_register("strtoupper", "filter")
25: or die("Failed to register filter");
26:
27: if ($f = fopen(__FILE__, "rb")) {
28: stream_filter_append($f, "strtoupper");
29: while (!feof($f)) {
30: echo fread($f, 8192);
31: }
32: fclose($f);
33: }
34: echo "Done\n";
35: ?>
36: --EXPECTF--
37: %sTEST
38: <?PHP
39: ECHO "-TEST\N";
40: CLASS FILTER EXTENDS PHP_USER_FILTER {
41: FUNCTION FILTER($IN, $OUT, &$CONSUMED, $CLOSING)
42: {
43: $OUTPUT = 0;
44: WHILE ($BUCKET = STREAM_BUCKET_MAKE_WRITEABLE($IN)) {
45: $BUCKET->DATA = STRTOUPPER($BUCKET->DATA);
46: $CONSUMED += $BUCKET->DATALEN;
47: STREAM_BUCKET_APPEND($OUT, $BUCKET);
48: $OUTPUT = 1;
49: }
50: IF ($CLOSING) {
51: $BUCKET = STREAM_BUCKET_NEW($THIS->STREAM, "\N===CLOSE===\N");
52: STREAM_BUCKET_APPEND($OUT, $BUCKET);
53: $OUTPUT = 1;
54: }
55: RETURN $OUTPUT ? PSFS_PASS_ON : PSFS_FEED_ME;
56: }
57: }
58: STREAM_FILTER_REGISTER("STRTOUPPER", "FILTER")
59: OR DIE("FAILED TO REGISTER FILTER");
60:
61: IF ($F = FOPEN(__FILE__, "RB")) {
62: STREAM_FILTER_APPEND($F, "STRTOUPPER");
63: WHILE (!FEOF($F)) {
64: ECHO FREAD($F, 8192);
65: }
66: FCLOSE($F);
67: }
68: ECHO "DONE\N";
69: ?>
70:
71: ===close===
72: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>