Skip to content

Commit

Permalink
[Data Liberation] Merge both XML processors into a single WP_XML_Proc…
Browse files Browse the repository at this point in the history
…essor (#1960)

Merge `WP_XML_Tag_Processor` and `WP_XML_Processor` into a single
`WP_XML_Processor` class. This reduces abstractions, enables keeping
more properties as private, and simplifies the code.

Related to #1894
and WordPress/wordpress-develop#6713

 ## Testing instructions

Confirm the CI tests pass.
  • Loading branch information
adamziel authored Oct 31, 2024
1 parent 6f86c75 commit 33e7d55
Show file tree
Hide file tree
Showing 12 changed files with 4,201 additions and 4,475 deletions.
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();
}

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

0 comments on commit 33e7d55

Please sign in to comment.