Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Data Liberation] Merge both XML processors into a single WP_XML_Processor #1960

Merged
merged 6 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions packages/playground/data-liberation/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,14 @@
require_once __DIR__ . '/src/WP_URL.php';

require_once __DIR__ . '/src/xml-api/WP_XML_Decoder.php';
require_once __DIR__ . '/src/xml-api/WP_XML_Tag_Processor.php';
require_once __DIR__ . '/src/xml-api/WP_XML_Processor.php';
require_once __DIR__ . '/src/WP_WXR_URL_Rewrite_Processor.php';

require_once __DIR__ . '/vendor/autoload.php';


// Polyfill WordPress core functions
function _doing_it_wrong() {

function _doing_it_wrong($method, $message, $version) {
}

function __($input) {
Expand Down
1 change: 0 additions & 1 deletion packages/playground/data-liberation/phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
<file>tests/WPBlockMarkupUrlProcessorTests.php</file>
<file>tests/URLParserWHATWGComplianceTests.php</file>
<file>tests/WPXMLProcessorTests.php</file>
<file>tests/WPXMLTagProcessorTests.php</file>
<file>tests/UrldecodeNTests.php</file>
</testsuite>
</testsuites>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
class WP_WXR_URL_Rewrite_Processor {


public static function stream( $current_site_url, $new_site_url ) {
return WP_XML_Processor::stream(
public static function create_stream_processor( $current_site_url, $new_site_url ) {
return WP_XML_Processor::create_stream_processor(
function ( $processor ) use ( $current_site_url, $new_site_url ) {
if ( static::is_wxr_content_node( $processor ) ) {
$text = $processor->get_modifiable_text();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public function __construct( $file_path, $chunk_size = 8096 ) {
$this->file_path = $file_path;
$this->chunk_size = $chunk_size;
parent::__construct();
$this->append_eof();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand anything about this processor yet and am asking questions.

Why did this need to be added?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The processors have two states:

  • Expecting more data. Some syntax errors are then treated as "oh we're actually pausing and waiting for more data".
  • No more data is coming. All errors are treated as "the input is invalid".

EOF marks a transition point between the two states.

Still, I'm questioning the need for these stream classes. They add yet another concept to learn.

}

public function pause() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
* Consult it for reasoning and usage examples:
*
* https://github.com/adamziel/wxr-normalize/pull/1
*
* @TODO: Allow each stream to indicate its output reached EOF
* and propagate that information downstream. Otherwise,
* WP_XML_Processor will always end in an "incomplete input"
* state.
*/
class WP_Stream_Chain extends WP_Byte_Stream implements ArrayAccess, Iterator {
private $first_stream;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

interface WP_Stream_Processor {
public function append_bytes( string $bytes );
public function input_finished(): void;
public function is_finished(): bool;
public function is_paused_at_incomplete_input(): bool;
public function get_last_error(): ?string;
Expand Down
Loading