1 | <?php |
||
13 | class ObjectDumpIterator implements Iterator { |
||
14 | |||
15 | /** |
||
16 | * @var callable|null |
||
17 | */ |
||
18 | private $errorReporter = null; |
||
19 | |||
20 | /** |
||
21 | * @var string|null |
||
22 | */ |
||
23 | private $current = null; |
||
24 | |||
25 | /** |
||
26 | * @var Iterator |
||
27 | */ |
||
28 | private $stringIterator; |
||
29 | |||
30 | 4 | public function __construct( Iterator $stringIterator ) { |
|
33 | |||
34 | /** |
||
35 | * @param callable|null $errorReporter |
||
36 | */ |
||
37 | 4 | public function onError( callable $errorReporter = null ) { |
|
40 | |||
41 | /** |
||
42 | * @return string|null |
||
43 | */ |
||
44 | 3 | public function current() { |
|
47 | |||
48 | /** |
||
49 | * @return string|null |
||
50 | */ |
||
51 | 4 | public function next() { |
|
57 | |||
58 | 4 | private function getCurrentFromString() { |
|
59 | 4 | while ( true ) { |
|
60 | 4 | $jsonString = $this->stringIterator->current(); |
|
61 | |||
62 | 4 | if ( $jsonString === null ) { |
|
63 | 1 | $this->current = null; |
|
64 | 1 | return; |
|
65 | } |
||
66 | |||
67 | 4 | $data = json_decode( $jsonString, true ); |
|
68 | 4 | if ( $data === null ) { |
|
69 | 1 | $this->reportError( json_last_error_msg() ); |
|
70 | 1 | $this->stringIterator->next(); |
|
71 | } |
||
72 | else { |
||
73 | 4 | $this->current = $data; |
|
74 | 4 | return; |
|
75 | } |
||
76 | } |
||
77 | } |
||
78 | |||
79 | 1 | private function reportError( $errorMessage ) { |
|
80 | 1 | if ( $this->errorReporter !== null ) { |
|
81 | 1 | call_user_func( $this->errorReporter, $errorMessage ); |
|
82 | } |
||
83 | 1 | } |
|
84 | |||
85 | 2 | public function key() { |
|
88 | |||
89 | 1 | public function valid() { |
|
92 | |||
93 | 4 | public function rewind() { |
|
98 | |||
99 | } |
||
100 |