Skip to content

Commit 92ced0a

Browse files
committed
Lightly document WP_Entity_Reader
1 parent a46edf9 commit 92ced0a

File tree

1 file changed

+35
-10
lines changed

1 file changed

+35
-10
lines changed

packages/playground/data-liberation/src/entity-readers/WP_Entity_Reader.php

+35-10
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,64 @@
11
<?php
22

3+
/**
4+
* The Entity Reader ingests content from a source and breaks it down into
5+
* individual "entities" that WordPress understands - posts, comments, metadata, etc.
6+
*
7+
* The reader implements Iterator so you can easily loop through entities:
8+
* foreach ($reader as $entity) { ... }
9+
*/
310
abstract class WP_Entity_Reader implements \Iterator {
411

12+
/**
13+
* Gets the current entity being processed.
14+
*
15+
* @return WP_Imported_Entity|false The current entity, or false if none available
16+
*/
517
abstract public function get_entity();
6-
abstract public function next_entity();
718

819
/**
9-
* Checks if processing is finished.
20+
* Advances to the next entity in the source content.
1021
*
11-
* @since WP_VERSION
22+
* This is where each data source implements its own logic for parsing the bytes
23+
* and extracting the next meaningful piece of content.
1224
*
13-
* @return bool Whether processing is finished.
25+
* @return bool Whether we successfully moved to the next entity
26+
*/
27+
abstract public function next_entity();
28+
29+
/**
30+
* Checks if we've processed everything from the source.
31+
*
32+
* @return bool Whether we've processed everything from the source
1433
*/
1534
abstract public function is_finished(): bool;
1635

1736
/**
18-
* Gets the last error that occurred.
37+
* Gets any error that occurred during processing.
1938
*
20-
* @since WP_VERSION
39+
* Readers should use this to report issues like invalid source content
40+
* or parsing failures.
2141
*
22-
* @return string|null The error message, or null if no error occurred.
42+
* @since WP_VERSION
43+
* @return string|null Error message if something went wrong, null otherwise
2344
*/
2445
abstract public function get_last_error(): ?string;
2546

2647
/**
27-
* Returns a cursor that can be used to restore the reader's state.
48+
* Returns a cursor position that can be used to resume processing later.
2849
*
29-
* @TODO: Define a general interface for entity readers.
50+
* This allows for processing large imports in chunks without losing your place.
51+
* Not all readers support this yet.
3052
*
31-
* @return string
53+
* @TODO: Define a general interface for entity readers.
54+
* @return string Position marker for resuming later
3255
*/
3356
public function get_reentrancy_cursor() {
3457
return '';
3558
}
3659

60+
// The iterator interface:
61+
3762
public function current(): object {
3863
if ( null === $this->get_entity() && ! $this->is_finished() && ! $this->get_last_error() ) {
3964
$this->next();

0 commit comments

Comments
 (0)