class-attachmentdownloader.php
1 week ago
class-attachmentdownloaderevent.php
1 week ago
class-entityimporter.php
1 week ago
class-entityiteratorchain.php
1 week ago
class-filevisitorevent.php
1 week ago
class-importsession.php
1 week ago
class-importutils.php
1 week ago
class-retryfrontloadingiterator.php
1 week ago
class-streamimporter.php
1 week ago
class-entityiteratorchain.php
79 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WordPress\DataLiberation\Importer; |
| 4 | |
| 5 | use Iterator; |
| 6 | use ReturnTypeWillChange; |
| 7 | |
| 8 | class EntityIteratorChain implements Iterator { |
| 9 | private $assets_attempts_iterator = null; |
| 10 | private $entities_iterator = null; |
| 11 | |
| 12 | public function set_assets_attempts_iterator( Iterator $iterator ) { |
| 13 | $this->assets_attempts_iterator = $iterator; |
| 14 | } |
| 15 | |
| 16 | public function set_entities_iterator( Iterator $iterator ) { |
| 17 | $this->entities_iterator = $iterator; |
| 18 | } |
| 19 | |
| 20 | #[ReturnTypeWillChange] |
| 21 | public function current() { |
| 22 | $iterator = $this->get_iterator(); |
| 23 | |
| 24 | return $iterator ? $iterator->current() : null; |
| 25 | } |
| 26 | |
| 27 | #[ReturnTypeWillChange] |
| 28 | public function key() { |
| 29 | $iterator = $this->get_iterator(); |
| 30 | |
| 31 | return $iterator ? $iterator->key() : null; |
| 32 | } |
| 33 | |
| 34 | public function next(): void { |
| 35 | $iterator = $this->get_iterator(); |
| 36 | if ( ! $iterator ) { |
| 37 | return; |
| 38 | } |
| 39 | |
| 40 | $iterator->next(); |
| 41 | } |
| 42 | |
| 43 | public function rewind(): void { |
| 44 | $iterator = $this->get_iterator(); |
| 45 | if ( ! $iterator ) { |
| 46 | return; |
| 47 | } |
| 48 | $iterator->rewind(); |
| 49 | } |
| 50 | |
| 51 | public function valid(): bool { |
| 52 | $iterator = $this->get_iterator(); |
| 53 | |
| 54 | return $iterator && $iterator->valid(); |
| 55 | } |
| 56 | |
| 57 | private function get_iterator(): ?Iterator { |
| 58 | if ( $this->assets_attempts_iterator && $this->assets_attempts_iterator->valid() ) { |
| 59 | return $this->assets_attempts_iterator; |
| 60 | } elseif ( $this->entities_iterator && $this->entities_iterator->valid() ) { |
| 61 | return $this->entities_iterator; |
| 62 | } |
| 63 | |
| 64 | return null; |
| 65 | } |
| 66 | |
| 67 | #[ReturnTypeWillChange] |
| 68 | public function get_reentrancy_cursor() { |
| 69 | if ( ! $this->entities_iterator ) { |
| 70 | return null; |
| 71 | } |
| 72 | if ( ! method_exists( $this->entities_iterator, 'get_reentrancy_cursor' ) ) { |
| 73 | return null; |
| 74 | } |
| 75 | |
| 76 | return $this->entities_iterator->get_reentrancy_cursor(); |
| 77 | } |
| 78 | } |
| 79 |