1 | <?php |
||
10 | class Source |
||
11 | { |
||
12 | /** @var string $str given string to deserialize */ |
||
13 | private $str; |
||
14 | |||
15 | /** @var int $length given string length */ |
||
16 | private $length; |
||
17 | |||
18 | /** @var int $current current position of parser */ |
||
19 | private $current; |
||
20 | |||
21 | /** |
||
22 | * constructor |
||
23 | * |
||
24 | * @param string $str parser input |
||
25 | * @throws \InvalidArgumentException |
||
26 | */ |
||
27 | 110 | public function __construct($str) |
|
36 | |||
37 | /** |
||
38 | * throw error with currnt position |
||
39 | * |
||
40 | * @return void |
||
41 | * @throws UnserializeFailedException |
||
42 | */ |
||
43 | 67 | public function triggerError() |
|
48 | |||
49 | /** |
||
50 | * consume given string if it is as expected |
||
51 | * |
||
52 | * @param string $expected expected string |
||
53 | * @param integer $length length of $expected |
||
54 | * @return void |
||
55 | * @throws UnserializeFailedException |
||
56 | */ |
||
57 | 26 | public function consume($expected, $length) |
|
64 | |||
65 | /** |
||
66 | * read givin length substring |
||
67 | * |
||
68 | * @param integer $length length to read |
||
69 | * @return string |
||
70 | * @throws UnserializeFailedException |
||
71 | */ |
||
72 | 25 | public function read($length) |
|
84 | |||
85 | /** |
||
86 | * return matching string for given regexp |
||
87 | * |
||
88 | * @param string $regexp Regular Expression for expected substring |
||
89 | * @return array |
||
90 | */ |
||
91 | 109 | public function match($regexp) |
|
101 | } |
||
102 |