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 resource The resource handle for the opened part. Essentially the |
||
34 | * MIME message's stream handle. |
||
35 | */ |
||
36 | protected $handle; |
||
37 | |||
38 | /** |
||
39 | * @var int The offset character position in $this->handle where the current |
||
40 | * mime part's content starts. |
||
41 | */ |
||
42 | protected $start; |
||
43 | |||
44 | /** |
||
45 | * @var int The offset character position in $this->handle where the current |
||
46 | * mime part's content ends. |
||
47 | */ |
||
48 | protected $end; |
||
49 | |||
50 | /** |
||
51 | * @var PartStreamRegistry The registry service object. |
||
52 | */ |
||
53 | protected $registry; |
||
54 | |||
55 | /** |
||
56 | * @var int the current read position. |
||
57 | */ |
||
58 | private $position; |
||
59 | |||
60 | /** |
||
61 | * Constructs a PartStream. |
||
62 | */ |
||
63 | public function __construct() |
||
68 | |||
69 | /** |
||
70 | * Extracts the PartStreamRegistry resource id, start, and end positions for |
||
71 | * the passed path and assigns them to the passed-by-reference parameters |
||
72 | * $id, $start and $end respectively. |
||
73 | * |
||
74 | * @param string $path |
||
75 | * @param string $id |
||
76 | * @param int $start |
||
77 | * @param int $end |
||
78 | */ |
||
79 | private function parseOpenPath($path, &$id, &$start, &$end) |
||
90 | |||
91 | /** |
||
92 | * Called in response to fopen, file_get_contents, etc... with a |
||
93 | * PartStream::STREAM_WRAPPER_PROTOCOL, e.g., |
||
94 | * fopen('mmp-mime-message://...'); |
||
95 | * |
||
96 | * The \ZBateson\MailMimeParser\Message object ID must be passed as the |
||
97 | * 'host' part in $path. The start and end boundaries of the part must be |
||
98 | * passed as query string parameters in the path, for example: |
||
99 | * |
||
100 | * fopen('mmp-mime-message://123456?start=0&end=20'); |
||
101 | * |
||
102 | * This would open a file handle to a MIME message with the ID 123456, with |
||
103 | * a start offset of 0, and an end offset of 20. |
||
104 | * |
||
105 | * TODO: $mode is not validated, although only read operations are |
||
106 | * implemented in PartStream. $options are not checked for error reporting |
||
107 | * mode. |
||
108 | * |
||
109 | * @param string $path The requested path |
||
110 | * @param string $mode The requested open mode |
||
111 | * @param int $options Additional streams API flags |
||
112 | * @param string $opened_path The full path of the opened resource |
||
113 | * @return boolean true if the resource was opened successfully |
||
114 | */ |
||
115 | public function stream_open($path, $mode, $options, &$opened_path) |
||
125 | |||
126 | /** |
||
127 | * Reads up to $count characters from the stream and returns them. |
||
128 | * |
||
129 | * @param int $count |
||
130 | * @return string |
||
131 | */ |
||
132 | public function stream_read($count) |
||
146 | |||
147 | /** |
||
148 | * Returns the current read position. |
||
149 | * |
||
150 | * @return int |
||
151 | */ |
||
152 | public function stream_tell() |
||
156 | |||
157 | /** |
||
158 | * Returns true if the end of the stream has been reached. |
||
159 | * |
||
160 | * @return boolean |
||
161 | */ |
||
162 | public function stream_eof() |
||
169 | |||
170 | /** |
||
171 | * Checks if the position is valid and seeks to it by setting |
||
172 | * $this->position |
||
173 | * |
||
174 | * @param int $pos |
||
175 | * @return boolean true if set |
||
176 | */ |
||
177 | private function streamSeekSet($pos) |
||
185 | |||
186 | /** |
||
187 | * Moves the pointer to the given offset, in accordance to $whence. |
||
188 | * |
||
189 | * @param int $offset |
||
190 | * @param int $whence One of SEEK_SET, SEEK_CUR and SEEK_END. |
||
191 | * @return boolean |
||
192 | */ |
||
193 | public function stream_seek($offset, $whence = SEEK_SET) |
||
208 | |||
209 | /** |
||
210 | * Returns information about the opened stream, as would be expected by |
||
211 | * fstat. |
||
212 | * |
||
213 | * @return array |
||
214 | */ |
||
215 | public function stream_stat() |
||
223 | } |
||
224 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.