summaryrefslogtreecommitdiff
path: root/ext/standard/tests/file/userfilters.phpt
blob: 9c42e8e7f63cb9080d5baf5e528be7e4f6577301 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
--TEST--
User-space filters
--FILE--
<?php
# vim600:syn=php:

class UpperCaseFilter extends php_user_filter {
	function oncreate()
	{
		echo "oncreate:\n";
		var_dump($this->filtername);
		var_dump($this->params);
	}

	function flush($closing)
	{
		echo "flush:\n";
	}

	function onclose()
	{
		echo "onclose:\n";
	}

	function write($data)
	{
		echo "write:\n";
		$x = parent::write($data);
		return strlen($data);
	}

	function read($bytes)
	{
		echo "read:\n";
		$x = parent::read($bytes);
		return strtoupper($x);
	}
};

var_dump(stream_register_filter("string.uppercase", "UpperCaseFilter"));
$fp = tmpfile();

fwrite($fp, "hello there");
rewind($fp);

var_dump(stream_filter_prepend($fp, "string.uppercase"));
var_dump(fgets($fp));
fclose($fp);
?>
--EXPECT--
bool(true)
oncreate:
string(16) "string.uppercase"
NULL
bool(true)
read:
read:
string(11) "HELLO THERE"
flush:
onclose: