[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/html-api/ -> class-wp-html-token.php (source)

   1  <?php
   2  /**
   3   * HTML API: WP_HTML_Token class
   4   *
   5   * @package WordPress
   6   * @subpackage HTML-API
   7   * @since 6.4.0
   8   */
   9  
  10  /**
  11   * Core class used by the HTML processor during HTML parsing
  12   * for referring to tokens in the input HTML string.
  13   *
  14   * This class is designed for internal use by the HTML processor.
  15   *
  16   * @since 6.4.0
  17   *
  18   * @access private
  19   *
  20   * @see WP_HTML_Processor
  21   */
  22  class WP_HTML_Token {
  23      /**
  24       * Name of bookmark corresponding to source of token in input HTML string.
  25       *
  26       * Having a bookmark name does not imply that the token still exists. It
  27       * may be that the source token and underlying bookmark was wiped out by
  28       * some modification to the source HTML.
  29       *
  30       * @since 6.4.0
  31       *
  32       * @var string|null
  33       */
  34      public $bookmark_name = null;
  35  
  36      /**
  37       * Name of node; lowercase names such as "marker" are not HTML elements.
  38       *
  39       * For HTML elements/tags this value should come from WP_HTML_Processor::get_tag().
  40       *
  41       * @since 6.4.0
  42       *
  43       * @see WP_HTML_Processor::get_tag()
  44       *
  45       * @var string
  46       * @phpstan-var non-falsy-string
  47       */
  48      public $node_name = null;
  49  
  50      /**
  51       * Whether node contains the self-closing flag.
  52       *
  53       * A node may have a self-closing flag when it shouldn't. This value
  54       * only reports if the flag is present in the original HTML.
  55       *
  56       * @since 6.4.0
  57       *
  58       * @link https://html.spec.whatwg.org/#self-closing-flag
  59       *
  60       * @var bool
  61       */
  62      public $has_self_closing_flag = false;
  63  
  64      /**
  65       * Indicates if the element is an HTML element or if it's inside foreign content.
  66       *
  67       * @since 6.7.0
  68       *
  69       * @var string 'html', 'svg', or 'math'.
  70       */
  71      public $namespace = 'html';
  72  
  73      /**
  74       * Indicates which kind of integration point the element is, if any.
  75       *
  76       * @since 6.7.0
  77       *
  78       * @var string|null 'math', 'html', or null if not an integration point.
  79       */
  80      public $integration_node_type = null;
  81  
  82      /**
  83       * Called when token is garbage-collected or otherwise destroyed.
  84       *
  85       * @since 6.4.0
  86       * @var callable|null
  87       */
  88      public $on_destroy = null;
  89  
  90      /**
  91       * Constructor - creates a reference to a token in some external HTML string.
  92       *
  93       * @since 6.4.0
  94       *
  95       * @param string|null   $bookmark_name         Name of bookmark corresponding to location in HTML where token is found,
  96       *                                             or `null` for markers and nodes without a bookmark.
  97       * @param string        $node_name             Name of node token represents; if uppercase, an HTML element; if lowercase, a special value like "marker".
  98       * @param bool          $has_self_closing_flag Whether the source token contains the self-closing flag, regardless of whether it's valid.
  99       * @param callable|null $on_destroy            Optional. Function to call when destroying token, useful for releasing the bookmark.
 100       *
 101       * @phpstan-param non-falsy-string $node_name
 102       */
 103  	public function __construct( ?string $bookmark_name, string $node_name, bool $has_self_closing_flag, ?callable $on_destroy = null ) {
 104          $this->bookmark_name         = $bookmark_name;
 105          $this->namespace             = 'html';
 106          $this->node_name             = $node_name;
 107          $this->has_self_closing_flag = $has_self_closing_flag;
 108          $this->on_destroy            = $on_destroy;
 109      }
 110  
 111      /**
 112       * Destructor.
 113       *
 114       * @since 6.4.0
 115       */
 116  	public function __destruct() {
 117          if ( is_callable( $this->on_destroy ) ) {
 118              call_user_func( $this->on_destroy, $this->bookmark_name );
 119          }
 120      }
 121  
 122      /**
 123       * Wakeup magic method.
 124       *
 125       * @since 6.4.2
 126       */
 127  	public function __wakeup() {
 128          throw new \LogicException( __CLASS__ . ' should never be unserialized' );
 129      }
 130  }


Generated : Sun Nov 22 08:20:01 2026 Cross-referenced by PHPXref