Skip to content

Commit 33e7d55

Browse files
authored
[Data Liberation] Merge both XML processors into a single WP_XML_Processor (#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.
1 parent 6f86c75 commit 33e7d55

12 files changed

+4201
-4475
lines changed

packages/playground/data-liberation/bootstrap.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,14 @@
3030
require_once __DIR__ . '/src/WP_URL.php';
3131

3232
require_once __DIR__ . '/src/xml-api/WP_XML_Decoder.php';
33-
require_once __DIR__ . '/src/xml-api/WP_XML_Tag_Processor.php';
3433
require_once __DIR__ . '/src/xml-api/WP_XML_Processor.php';
3534
require_once __DIR__ . '/src/WP_WXR_URL_Rewrite_Processor.php';
3635

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

3938

4039
// Polyfill WordPress core functions
41-
function _doing_it_wrong() {
42-
40+
function _doing_it_wrong($method, $message, $version) {
4341
}
4442

4543
function __($input) {

packages/playground/data-liberation/phpunit.xml

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
<file>tests/WPBlockMarkupUrlProcessorTests.php</file>
1010
<file>tests/URLParserWHATWGComplianceTests.php</file>
1111
<file>tests/WPXMLProcessorTests.php</file>
12-
<file>tests/WPXMLTagProcessorTests.php</file>
1312
<file>tests/UrldecodeNTests.php</file>
1413
</testsuite>
1514
</testsuites>

packages/playground/data-liberation/src/WP_WXR_URL_Rewrite_Processor.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
class WP_WXR_URL_Rewrite_Processor {
44

55

6-
public static function stream( $current_site_url, $new_site_url ) {
7-
return WP_XML_Processor::stream(
6+
public static function create_stream_processor( $current_site_url, $new_site_url ) {
7+
return WP_XML_Processor::create_stream_processor(
88
function ( $processor ) use ( $current_site_url, $new_site_url ) {
99
if ( static::is_wxr_content_node( $processor ) ) {
1010
$text = $processor->get_modifiable_text();

packages/playground/data-liberation/src/stream-api/WP_File_Byte_Stream.php

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public function __construct( $file_path, $chunk_size = 8096 ) {
1111
$this->file_path = $file_path;
1212
$this->chunk_size = $chunk_size;
1313
parent::__construct();
14+
$this->append_eof();
1415
}
1516

1617
public function pause() {

packages/playground/data-liberation/src/stream-api/WP_Stream_Chain.php

+5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
* Consult it for reasoning and usage examples:
1717
*
1818
* https://github.com/adamziel/wxr-normalize/pull/1
19+
*
20+
* @TODO: Allow each stream to indicate its output reached EOF
21+
* and propagate that information downstream. Otherwise,
22+
* WP_XML_Processor will always end in an "incomplete input"
23+
* state.
1924
*/
2025
class WP_Stream_Chain extends WP_Byte_Stream implements ArrayAccess, Iterator {
2126
private $first_stream;

packages/playground/data-liberation/src/stream-api/WP_Stream_Processor.php

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
interface WP_Stream_Processor {
44
public function append_bytes( string $bytes );
5+
public function input_finished(): void;
56
public function is_finished(): bool;
67
public function is_paused_at_incomplete_input(): bool;
78
public function get_last_error(): ?string;

0 commit comments

Comments
 (0)