1 | <?php |
||
27 | class Reader |
||
28 | { |
||
29 | /** |
||
30 | * Start token of XMP data. |
||
31 | * |
||
32 | * @var string |
||
33 | */ |
||
34 | private $tokenStart = '<x:xmpmeta'; |
||
35 | |||
36 | /** |
||
37 | * End token of XMP data. |
||
38 | * |
||
39 | * @var string |
||
40 | */ |
||
41 | private $tokenEnd = '</x:xmpmeta>'; |
||
42 | |||
43 | /** |
||
44 | * Size (in bytes) of data chunks read from the stream. |
||
45 | * |
||
46 | * @var int |
||
47 | */ |
||
48 | private $chunkSize = 1024; |
||
49 | |||
50 | /** |
||
51 | * Buffer to construct XMP data in. |
||
52 | * |
||
53 | * @var string |
||
54 | */ |
||
55 | private $buffer; |
||
56 | |||
57 | /** |
||
58 | * True if $tokenStart has been found. |
||
59 | * |
||
60 | * @var bool |
||
61 | */ |
||
62 | private $started; |
||
63 | |||
64 | /** |
||
65 | * True if $started and $tokenEnd has been found. |
||
66 | * |
||
67 | * @var bool |
||
68 | */ |
||
69 | private $ended; |
||
70 | |||
71 | /** |
||
72 | * Counts how many characters of the token that is currently searched for |
||
73 | * have been found. |
||
74 | * |
||
75 | * This is reset whenever a character that doesn't equal the next one from |
||
76 | * the token is found. If $delimPos reaches token length, the token has been |
||
77 | * found. |
||
78 | * |
||
79 | * This variable is needed because a token might be split over two chunks of |
||
80 | * input data so that functions such as strpos aren't sufficient. |
||
81 | * |
||
82 | * @var int |
||
83 | */ |
||
84 | private $delimPos; |
||
85 | |||
86 | /** |
||
87 | * Length (in byte) of $tokenStart. |
||
88 | * |
||
89 | * @var int |
||
90 | */ |
||
91 | private $tokenStartLen; |
||
92 | |||
93 | /** |
||
94 | * Length (in byte) of $tokenEnd. |
||
95 | * |
||
96 | * @var int |
||
97 | */ |
||
98 | private $tokenEndLen; |
||
99 | |||
100 | /** |
||
101 | * Initializes the instance. |
||
102 | */ |
||
103 | 4 | public function __construct() |
|
107 | |||
108 | /** |
||
109 | * Resets instance data to clean starting state. |
||
110 | */ |
||
111 | 4 | private function reset() |
|
120 | |||
121 | /** |
||
122 | * Searches incoming data for $tokenStart adapting internal state if found. |
||
123 | * |
||
124 | * @param string $char A single byte |
||
125 | */ |
||
126 | 3 | private function searchForTokenStart($char) |
|
140 | |||
141 | /** |
||
142 | * Searches incoming data for $tokenEnd adapting internal state if found. |
||
143 | * |
||
144 | * @param string $char A single byte |
||
145 | */ |
||
146 | 3 | private function searchForTokenEnd($char) |
|
160 | |||
161 | /** |
||
162 | * Extracts the first found XMP document from the stream. |
||
163 | * |
||
164 | * The stream is read in chunks and processed byte by byte in an |
||
165 | * automaton-like fashion. |
||
166 | * |
||
167 | * After the execution of this method, instance variables $buffer, $started, |
||
168 | * and $ended will contain meaningful values. |
||
169 | * |
||
170 | * @param resource $stream A stream resource |
||
171 | */ |
||
172 | 3 | private function getXmpData($stream) |
|
196 | |||
197 | /** |
||
198 | * Returns a Kaloa\Xmp\Document of the first occurrence of XMP data in the |
||
199 | * stream. |
||
200 | * |
||
201 | * @todo The method of error handling (set_error_handler) is just insane. |
||
202 | * |
||
203 | * @param resource $stream A stream resource |
||
204 | * @return XmpDocument |
||
205 | * @throws ReaderException |
||
206 | */ |
||
207 | 4 | public function getXmpDocument($stream) |
|
250 | } |
||
251 |