Changeset 58363
- Timestamp:
- 06/08/2024 10:55:55 AM (8 months ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/html-api/class-wp-html-processor.php
r58304 r58363 277 277 * 278 278 * @since 6.4.0 279 * @since 6.6.0 Returns `static` instead of `self` so it can create subclass instances. 279 280 * 280 281 * @param string $html Input HTML fragment to process. 281 282 * @param string $context Context element for the fragment, must be default of `<body>`. 282 283 * @param string $encoding Text encoding of the document; must be default of 'UTF-8'. 283 * @return WP_HTML_Processor|null The created processor if successful, otherwise null.284 * @return static|null The created processor if successful, otherwise null. 284 285 */ 285 286 public static function create_fragment( $html, $context = '<body>', $encoding = 'UTF-8' ) { … … 288 289 } 289 290 290 $processor = new s elf( $html, self::CONSTRUCTOR_UNLOCK_CODE );291 $processor = new static( $html, self::CONSTRUCTOR_UNLOCK_CODE ); 291 292 $processor->state->context_node = array( 'BODY', array() ); 292 293 $processor->state->insertion_mode = WP_HTML_Processor_State::INSERTION_MODE_IN_BODY; -
trunk/tests/phpunit/tests/html-api/wpHtmlProcessor.php
r58192 r58363 518 518 ); 519 519 } 520 521 /** 522 * Ensures that subclasses can be created from ::create_fragment method. 523 * 524 * @ticket 61374 525 */ 526 public function test_subclass_create_fragment_creates_subclass() { 527 $processor = WP_HTML_Processor::create_fragment( '' ); 528 $this->assertInstanceOf( WP_HTML_Processor::class, $processor, '::create_fragment did not return class instance.' ); 529 530 $subclass_instance = new class('') extends WP_HTML_Processor { 531 public function __construct( $html ) { 532 parent::__construct( $html, parent::CONSTRUCTOR_UNLOCK_CODE ); 533 } 534 }; 535 536 $subclass_processor = call_user_func( array( get_class( $subclass_instance ), 'create_fragment' ), '' ); 537 $this->assertInstanceOf( get_class( $subclass_instance ), $subclass_processor, '::create_fragment did not return subclass instance.' ); 538 } 520 539 }
Note: See TracChangeset
for help on using the changeset viewer.