1 | <?php |
||
24 | class PartStream |
||
25 | { |
||
26 | /** |
||
27 | * The protocol name used to register the stream with |
||
28 | * stream_wrapper_register |
||
29 | */ |
||
30 | const STREAM_WRAPPER_PROTOCOL = 'mmp-mime-message'; |
||
31 | |||
32 | /** |
||
33 | * @var int the message ID this PartStream belongs to |
||
34 | */ |
||
35 | protected $id; |
||
36 | |||
37 | /** |
||
38 | * @var resource The resource handle for the opened part. Essentially the |
||
39 | * MIME message's stream handle. |
||
40 | */ |
||
41 | protected $handle; |
||
42 | |||
43 | /** |
||
44 | * @var int The offset character position in $this->handle where the current |
||
45 | * mime part's content starts. |
||
46 | */ |
||
47 | protected $start; |
||
48 | |||
49 | /** |
||
50 | * @var int The offset character position in $this->handle where the current |
||
51 | * mime part's content ends. |
||
52 | */ |
||
53 | protected $end; |
||
54 | |||
55 | /** |
||
56 | * @var PartStreamRegistry The registry service object. |
||
57 | */ |
||
58 | protected $registry; |
||
59 | |||
60 | /** |
||
61 | * @var int the current read position. |
||
62 | */ |
||
63 | private $position; |
||
64 | |||
65 | /** |
||
66 | * Constructs a PartStream. |
||
67 | */ |
||
68 | 5 | public function __construct() |
|
73 | |||
74 | /** |
||
75 | * Extracts the PartStreamRegistry resource id, start, and end positions for |
||
76 | * the passed path and assigns them to the passed-by-reference parameters |
||
77 | * $id, $start and $end respectively. |
||
78 | * |
||
79 | * @param string $path |
||
80 | * @param string $id |
||
81 | * @param int $start |
||
82 | * @param int $end |
||
83 | */ |
||
84 | 5 | private function parseOpenPath($path, &$id, &$start, &$end) |
|
95 | |||
96 | /** |
||
97 | * Called in response to fopen, file_get_contents, etc... with a |
||
98 | * PartStream::STREAM_WRAPPER_PROTOCOL, e.g., |
||
99 | * fopen('mmp-mime-message://...'); |
||
100 | * |
||
101 | * The \ZBateson\MailMimeParser\Message object ID must be passed as the |
||
102 | * 'host' part in $path. The start and end boundaries of the part must be |
||
103 | * passed as query string parameters in the path, for example: |
||
104 | * |
||
105 | * fopen('mmp-mime-message://123456?start=0&end=20'); |
||
106 | * |
||
107 | * This would open a file handle to a MIME message with the ID 123456, with |
||
108 | * a start offset of 0, and an end offset of 20. |
||
109 | * |
||
110 | * TODO: $mode is not validated, although only read operations are |
||
|
|||
111 | * implemented in PartStream. $options are not checked for error reporting |
||
112 | * mode. |
||
113 | * |
||
114 | * @param string $path The requested path |
||
115 | * @param string $mode The requested open mode |
||
116 | * @param int $options Additional streams API flags |
||
117 | * @param string $opened_path The full path of the opened resource |
||
118 | * @return boolean true if the resource was opened successfully |
||
119 | */ |
||
120 | 5 | public function stream_open($path, $mode, $options, &$opened_path) |
|
128 | |||
129 | /** |
||
130 | * Decreases the ref count for the underlying resource handle, which allows |
||
131 | * the PartStreamRegistry to close it once no more references to it exist. |
||
132 | */ |
||
133 | 5 | public function stream_close() |
|
137 | |||
138 | /** |
||
139 | * Reads up to $count characters from the stream and returns them. |
||
140 | * |
||
141 | * @param int $count |
||
142 | * @return string |
||
143 | */ |
||
144 | 5 | public function stream_read($count) |
|
158 | |||
159 | /** |
||
160 | * Returns the current read position. |
||
161 | * |
||
162 | * @return int |
||
163 | */ |
||
164 | 1 | public function stream_tell() |
|
168 | |||
169 | /** |
||
170 | * Returns true if the end of the stream has been reached. |
||
171 | * |
||
172 | * @return boolean |
||
173 | */ |
||
174 | 5 | public function stream_eof() |
|
181 | |||
182 | /** |
||
183 | * Checks if the position is valid and seeks to it by setting |
||
184 | * $this->position |
||
185 | * |
||
186 | * @param int $pos |
||
187 | * @return boolean true if set |
||
188 | */ |
||
189 | 1 | private function streamSeekSet($pos) |
|
197 | |||
198 | /** |
||
199 | * Moves the pointer to the given offset, in accordance to $whence. |
||
200 | * |
||
201 | * @param int $offset |
||
202 | * @param int $whence One of SEEK_SET, SEEK_CUR and SEEK_END. |
||
203 | * @return boolean |
||
204 | */ |
||
205 | 1 | public function stream_seek($offset, $whence = SEEK_SET) |
|
223 | |||
224 | /** |
||
225 | * Returns information about the opened stream, as would be expected by |
||
226 | * fstat. |
||
227 | * |
||
228 | * @return array |
||
229 | */ |
||
230 | 5 | public function stream_stat() |
|
238 | } |
||
239 |