1: <?php
2: 3: 4: 5: 6: 7: 8: 9:
10:
11: 12: 13: 14: 15: 16:
17: class Horde_Stream_Wrapper_String
18: {
19: 20: 21:
22: public $context;
23:
24: 25: 26:
27: protected $_string;
28:
29: 30: 31:
32: protected $_length;
33:
34: 35: 36:
37: protected $_position;
38:
39: 40: 41: 42: 43: 44:
45: public function stream_open($path, $mode, $options, &$opened_path)
46: {
47: $options = stream_context_get_options($this->context);
48: if (empty($options['horde-string']['string']) || ! $options['horde-string']['string'] instanceof Horde_Stream_Wrapper_StringStream) {
49: throw new Exception('String streams must be created using the Horde_Stream_Wrapper_StringStream interface');
50: }
51:
52: $this->_string =& $options['horde-string']['string']->getString();
53: if (is_null($this->_string)) {
54: return false;
55: }
56:
57: $this->_length = strlen($this->_string);
58: $this->_position = 0;
59: return true;
60: }
61:
62: 63: 64: 65: 66:
67: public function stream_read($count)
68: {
69: $current = $this->_position;
70: $this->_position += $count;
71: return substr($this->_string, $current, $count);
72: }
73:
74: 75: 76: 77: 78:
79: public function stream_write($data)
80: {
81: return strlen($data);
82: }
83:
84: 85: 86:
87: public function stream_tell()
88: {
89: return $this->_position;
90: }
91:
92: 93: 94:
95: public function stream_eof()
96: {
97: return ($this->_position > $this->_length);
98: }
99:
100: 101: 102: 103: 104:
105: public function stream_stat()
106: {
107: return array(
108: 'dev' => 0,
109: 'ino' => 0,
110: 'mode' => 0,
111: 'nlink' => 0,
112: 'uid' => 0,
113: 'gid' => 0,
114: 'rdev' => 0,
115: 'size' => $this->_length,
116: 'atime' => 0,
117: 'mtime' => 0,
118: 'ctime' => 0,
119: 'blksize' => 0,
120: 'blocks' => 0
121: );
122: }
123:
124: 125: 126: 127:
128: public function stream_seek($offset, $whence)
129: {
130: if ($offset > $this->_length) {
131: return false;
132: }
133:
134: switch ($whence) {
135: case SEEK_SET:
136: $this->_position = $offset;
137: break;
138:
139: case SEEK_CUR:
140: $target = $this->_position + $offset;
141: if ($target < $this->_length) {
142: $this->_position = $target;
143: } else {
144: return false;
145: }
146: break;
147:
148: case SEEK_END:
149: $this->_position = $this->_length - $offset;
150: break;
151: }
152:
153: return true;
154: }
155:
156: }
157: