|
1 <?php |
|
2 /** |
|
3 * HTML API: WP_HTML_Attribute_Token class |
|
4 * |
|
5 * @package WordPress |
|
6 * @subpackage HTML-API |
|
7 * @since 6.2.0 |
|
8 */ |
|
9 |
|
10 /** |
|
11 * Core class used by the HTML tag processor as a data structure for the attribute token, |
|
12 * allowing to drastically improve performance. |
|
13 * |
|
14 * This class is for internal usage of the WP_HTML_Tag_Processor class. |
|
15 * |
|
16 * @access private |
|
17 * @since 6.2.0 |
|
18 * @since 6.5.0 Replaced `end` with `length` to more closely match `substr()`. |
|
19 * |
|
20 * @see WP_HTML_Tag_Processor |
|
21 */ |
|
22 class WP_HTML_Attribute_Token { |
|
23 /** |
|
24 * Attribute name. |
|
25 * |
|
26 * @since 6.2.0 |
|
27 * |
|
28 * @var string |
|
29 */ |
|
30 public $name; |
|
31 |
|
32 /** |
|
33 * Attribute value. |
|
34 * |
|
35 * @since 6.2.0 |
|
36 * |
|
37 * @var int |
|
38 */ |
|
39 public $value_starts_at; |
|
40 |
|
41 /** |
|
42 * How many bytes the value occupies in the input HTML. |
|
43 * |
|
44 * @since 6.2.0 |
|
45 * |
|
46 * @var int |
|
47 */ |
|
48 public $value_length; |
|
49 |
|
50 /** |
|
51 * The string offset where the attribute name starts. |
|
52 * |
|
53 * @since 6.2.0 |
|
54 * |
|
55 * @var int |
|
56 */ |
|
57 public $start; |
|
58 |
|
59 /** |
|
60 * Byte length of text spanning the attribute inside a tag. |
|
61 * |
|
62 * This span starts at the first character of the attribute name |
|
63 * and it ends after one of three cases: |
|
64 * |
|
65 * - at the end of the attribute name for boolean attributes. |
|
66 * - at the end of the value for unquoted attributes. |
|
67 * - at the final single or double quote for quoted attributes. |
|
68 * |
|
69 * Example: |
|
70 * |
|
71 * <div class="post"> |
|
72 * ------------ length is 12, including quotes |
|
73 * |
|
74 * <input type="checked" checked id="selector"> |
|
75 * ------- length is 6 |
|
76 * |
|
77 * <a rel=noopener> |
|
78 * ------------ length is 11 |
|
79 * |
|
80 * @since 6.5.0 Replaced `end` with `length` to more closely match `substr()`. |
|
81 * |
|
82 * @var int |
|
83 */ |
|
84 public $length; |
|
85 |
|
86 /** |
|
87 * Whether the attribute is a boolean attribute with value `true`. |
|
88 * |
|
89 * @since 6.2.0 |
|
90 * |
|
91 * @var bool |
|
92 */ |
|
93 public $is_true; |
|
94 |
|
95 /** |
|
96 * Constructor. |
|
97 * |
|
98 * @since 6.2.0 |
|
99 * @since 6.5.0 Replaced `end` with `length` to more closely match `substr()`. |
|
100 * |
|
101 * @param string $name Attribute name. |
|
102 * @param int $value_start Attribute value. |
|
103 * @param int $value_length Number of bytes attribute value spans. |
|
104 * @param int $start The string offset where the attribute name starts. |
|
105 * @param int $length Byte length of the entire attribute name or name and value pair expression. |
|
106 * @param bool $is_true Whether the attribute is a boolean attribute with true value. |
|
107 */ |
|
108 public function __construct( $name, $value_start, $value_length, $start, $length, $is_true ) { |
|
109 $this->name = $name; |
|
110 $this->value_starts_at = $value_start; |
|
111 $this->value_length = $value_length; |
|
112 $this->start = $start; |
|
113 $this->length = $length; |
|
114 $this->is_true = $is_true; |
|
115 } |
|
116 } |