1 | <?php |
||
16 | class EntityDumpIterator implements Iterator { |
||
17 | |||
18 | /** |
||
19 | * @var Deserializer |
||
20 | */ |
||
21 | private $deserializer; |
||
22 | |||
23 | /** |
||
24 | * @var Iterator |
||
25 | */ |
||
26 | private $dumpIterator; |
||
27 | |||
28 | /** |
||
29 | * @var callable|null |
||
30 | */ |
||
31 | private $errorReporter = null; |
||
32 | |||
33 | /** |
||
34 | * @var EntityDocument|null |
||
35 | */ |
||
36 | private $current = null; |
||
37 | |||
38 | 9 | public function __construct( Iterator $objectIterator, Deserializer $entityDeserializer ) { |
|
42 | |||
43 | /** |
||
44 | * @param callable|null $errorReporter |
||
45 | */ |
||
46 | 8 | public function onError( callable $errorReporter = null ) { |
|
49 | |||
50 | /** |
||
51 | * @return EntityDocument|null |
||
52 | */ |
||
53 | 5 | public function current() { |
|
56 | |||
57 | /** |
||
58 | * @return EntityDocument|null |
||
59 | */ |
||
60 | 6 | public function next() { |
|
67 | |||
68 | 9 | private function getCurrentFromObject() { |
|
69 | 9 | while ( true ) { |
|
70 | try { |
||
71 | 9 | $jsonData = $this->dumpIterator->current(); |
|
72 | |||
73 | 9 | if ( $jsonData === null ) { |
|
74 | 9 | $this->current = null; |
|
75 | 9 | return; |
|
76 | } |
||
77 | |||
78 | 7 | $this->current = $this->deserializer->deserialize( $jsonData ); |
|
79 | 6 | return; |
|
80 | } |
||
81 | 3 | catch ( DeserializationException $ex ) { |
|
82 | 3 | $this->reportError( $ex->getMessage() ); |
|
83 | 3 | $this->dumpIterator->next(); |
|
84 | } |
||
85 | } |
||
86 | } |
||
87 | |||
88 | 3 | private function reportError( $errorMessage ) { |
|
89 | 3 | if ( $this->errorReporter !== null ) { |
|
90 | 1 | call_user_func( $this->errorReporter, $errorMessage ); |
|
91 | } |
||
92 | 3 | } |
|
93 | |||
94 | public function key() { |
||
97 | |||
98 | 9 | public function valid() { |
|
101 | |||
102 | 9 | public function rewind() { |
|
107 | |||
108 | } |
||
109 |