Complex classes like TemplateInspector often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use TemplateInspector, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
32 | class TemplateInspector |
||
33 | { |
||
34 | /** |
||
35 | * XSL namespace |
||
36 | */ |
||
37 | const XMLNS_XSL = 'http://www.w3.org/1999/XSL/Transform'; |
||
38 | |||
39 | /** |
||
40 | * @var string[] allowChild bitfield for each branch |
||
41 | */ |
||
42 | protected $allowChildBitfields = []; |
||
43 | |||
44 | /** |
||
45 | * @var bool Whether elements are allowed as children |
||
46 | */ |
||
47 | protected $allowsChildElements; |
||
48 | |||
49 | /** |
||
50 | * @var bool Whether text nodes are allowed as children |
||
51 | */ |
||
52 | protected $allowsText; |
||
53 | |||
54 | /** |
||
55 | * @var array[] Array of array of DOMElement instances |
||
56 | */ |
||
57 | protected $branches; |
||
58 | |||
59 | /** |
||
60 | * @var string OR-ed bitfield representing all of the categories used by this template |
||
61 | */ |
||
62 | protected $contentBitfield = "\0"; |
||
63 | |||
64 | /** |
||
65 | * @var string denyDescendant bitfield |
||
66 | */ |
||
67 | protected $denyDescendantBitfield = "\0"; |
||
68 | |||
69 | /** |
||
70 | * @var DOMDocument Document containing the template |
||
71 | */ |
||
72 | protected $dom; |
||
73 | |||
74 | /** |
||
75 | * @var bool Whether this template contains any HTML elements |
||
76 | */ |
||
77 | protected $hasElements = false; |
||
78 | |||
79 | /** |
||
80 | * @var bool Whether this template renders non-whitespace text nodes at its root |
||
81 | */ |
||
82 | protected $hasRootText; |
||
83 | |||
84 | /** |
||
85 | * @var bool Whether this template should be considered a block-level element |
||
86 | */ |
||
87 | protected $isBlock = false; |
||
88 | |||
89 | /** |
||
90 | * @var bool Whether the template uses the "empty" content model |
||
91 | */ |
||
92 | protected $isEmpty; |
||
93 | |||
94 | /** |
||
95 | * @var bool Whether this template adds to the list of active formatting elements |
||
96 | */ |
||
97 | protected $isFormattingElement; |
||
98 | |||
99 | /** |
||
100 | * @var bool Whether this template lets content through via an xsl:apply-templates element |
||
101 | */ |
||
102 | protected $isPassthrough = false; |
||
103 | |||
104 | /** |
||
105 | * @var bool Whether all branches use the transparent content model |
||
106 | */ |
||
107 | protected $isTransparent = false; |
||
108 | |||
109 | /** |
||
110 | * @var bool Whether all branches have an ancestor that is a void element |
||
111 | */ |
||
112 | protected $isVoid; |
||
113 | |||
114 | /** |
||
115 | * @var array Names of every last HTML element that precedes an <xsl:apply-templates/> node |
||
116 | */ |
||
117 | protected $leafNodes = []; |
||
118 | |||
119 | /** |
||
120 | * @var bool Whether any branch has an element that preserves new lines by default (e.g. <pre>) |
||
121 | */ |
||
122 | protected $preservesNewLines = false; |
||
123 | |||
124 | /** |
||
125 | * @var array Bitfield of the first HTML element of every branch |
||
126 | */ |
||
127 | protected $rootBitfields = []; |
||
128 | |||
129 | /** |
||
130 | * @var array Names of every HTML element that have no HTML parent |
||
131 | */ |
||
132 | protected $rootNodes = []; |
||
133 | |||
134 | /** |
||
135 | * @var DOMXPath XPath engine associated with $this->dom |
||
136 | */ |
||
137 | protected $xpath; |
||
138 | |||
139 | /** |
||
140 | * Constructor |
||
141 | * |
||
142 | * @param string $template Template content |
||
143 | */ |
||
144 | public function __construct($template) |
||
145 | { |
||
146 | $this->dom = TemplateHelper::loadTemplate($template); |
||
147 | $this->xpath = new DOMXPath($this->dom); |
||
148 | |||
149 | $this->analyseRootNodes(); |
||
150 | $this->analyseBranches(); |
||
151 | $this->analyseContent(); |
||
152 | } |
||
153 | |||
154 | /** |
||
155 | * Return whether this template allows a given child |
||
156 | * |
||
157 | * @param TemplateInspector $child |
||
158 | * @return bool |
||
159 | */ |
||
160 | public function allowsChild(TemplateInspector $child) |
||
161 | { |
||
162 | // Sometimes, a template can technically be allowed as a child but denied as a descendant |
||
163 | if (!$this->allowsDescendant($child)) |
||
164 | { |
||
165 | return false; |
||
166 | } |
||
167 | |||
168 | foreach ($child->rootBitfields as $rootBitfield) |
||
169 | { |
||
170 | foreach ($this->allowChildBitfields as $allowChildBitfield) |
||
171 | { |
||
172 | if (!self::match($rootBitfield, $allowChildBitfield)) |
||
173 | { |
||
174 | return false; |
||
175 | } |
||
176 | } |
||
177 | } |
||
178 | |||
179 | return ($this->allowsText || !$child->hasRootText); |
||
180 | } |
||
181 | |||
182 | /** |
||
183 | * Return whether this template allows a given descendant |
||
184 | * |
||
185 | * @param TemplateInspector $descendant |
||
186 | * @return bool |
||
187 | */ |
||
188 | public function allowsDescendant(TemplateInspector $descendant) |
||
189 | { |
||
190 | // Test whether the descendant is explicitly disallowed |
||
191 | if (self::match($descendant->contentBitfield, $this->denyDescendantBitfield)) |
||
192 | { |
||
193 | return false; |
||
194 | } |
||
195 | |||
196 | // Test whether the descendant contains any elements and we disallow elements |
||
197 | return ($this->allowsChildElements || !$descendant->hasElements); |
||
198 | } |
||
199 | |||
200 | /** |
||
201 | * Return whether this template allows elements as children |
||
202 | * |
||
203 | * @return bool |
||
204 | */ |
||
205 | public function allowsChildElements() |
||
209 | |||
210 | /** |
||
211 | * Return whether this template allows text nodes as children |
||
212 | * |
||
213 | * @return bool |
||
214 | */ |
||
215 | public function allowsText() |
||
219 | |||
220 | /** |
||
221 | * Return whether this template automatically closes given parent template |
||
222 | * |
||
223 | * @param TemplateInspector $parent |
||
224 | * @return bool |
||
225 | */ |
||
226 | public function closesParent(TemplateInspector $parent) |
||
248 | |||
249 | /** |
||
250 | * Evaluate an XPath expression |
||
251 | * |
||
252 | * @param string $expr XPath expression |
||
253 | * @param DOMElement $node Context node |
||
254 | * @return mixed |
||
255 | */ |
||
256 | public function evaluate($expr, DOMElement $node = null) |
||
257 | { |
||
258 | return $this->xpath->evaluate($expr, $node); |
||
259 | } |
||
260 | |||
261 | /** |
||
262 | * Return whether this template should be considered a block-level element |
||
263 | * |
||
264 | * @return bool |
||
265 | */ |
||
266 | public function isBlock() |
||
270 | |||
271 | /** |
||
272 | * Return whether this template adds to the list of active formatting elements |
||
273 | * |
||
274 | * @return bool |
||
275 | */ |
||
276 | public function isFormattingElement() |
||
280 | |||
281 | /** |
||
282 | * Return whether this template uses the "empty" content model |
||
283 | * |
||
284 | * @return bool |
||
285 | */ |
||
286 | public function isEmpty() |
||
290 | |||
291 | /** |
||
292 | * Return whether this template lets content through via an xsl:apply-templates element |
||
293 | * |
||
294 | * @return bool |
||
295 | */ |
||
296 | public function isPassthrough() |
||
300 | |||
301 | /** |
||
302 | * Return whether this template uses the "transparent" content model |
||
303 | * |
||
304 | * @return bool |
||
305 | */ |
||
306 | public function isTransparent() |
||
310 | |||
311 | /** |
||
312 | * Return whether all branches have an ancestor that is a void element |
||
313 | * |
||
314 | * @return bool |
||
315 | */ |
||
316 | public function isVoid() |
||
320 | |||
321 | /** |
||
322 | * Return whether this template preserves the whitespace in its descendants |
||
323 | * |
||
324 | * @return bool |
||
325 | */ |
||
326 | public function preservesNewLines() |
||
330 | |||
331 | /** |
||
332 | * Analyses the content of the whole template and set $this->contentBitfield accordingly |
||
333 | */ |
||
334 | protected function analyseContent() |
||
347 | |||
348 | /** |
||
349 | * Records the HTML elements (and their bitfield) rendered at the root of the template |
||
350 | */ |
||
351 | protected function analyseRootNodes() |
||
386 | |||
387 | /** |
||
388 | * Analyses each branch that leads to an <xsl:apply-templates/> tag |
||
389 | */ |
||
390 | protected function analyseBranches() |
||
409 | |||
410 | /** |
||
411 | * Test whether any branch of this template has an element that has given property |
||
412 | * |
||
413 | * @param string $propName |
||
414 | * @return bool |
||
415 | */ |
||
416 | protected function anyBranchHasProperty($propName) |
||
431 | |||
432 | /** |
||
433 | * Compute the allowChildBitfields and denyDescendantBitfield properties |
||
434 | * |
||
435 | * @return void |
||
436 | */ |
||
437 | protected function computeBitfields() |
||
474 | |||
475 | /** |
||
476 | * Compute the allowsChildElements property |
||
477 | * |
||
478 | * A template allows child Elements if it has at least one xsl:apply-templates and none of its |
||
479 | * ancestors have the text-only ("to") property |
||
480 | * |
||
481 | * @return void |
||
482 | */ |
||
483 | protected function computeAllowsChildElements() |
||
487 | |||
488 | /** |
||
489 | * Compute the allowsText property |
||
490 | * |
||
491 | * A template is said to allow text if none of the leaf elements disallow text |
||
492 | * |
||
493 | * @return void |
||
494 | */ |
||
495 | protected function computeAllowsText() |
||
509 | |||
510 | /** |
||
511 | * Compute the isFormattingElement property |
||
512 | * |
||
513 | * A template is said to be a formatting element if all (non-zero) of its branches are entirely |
||
514 | * composed of formatting elements |
||
515 | * |
||
516 | * @return void |
||
517 | */ |
||
518 | protected function computeFormattingElement() |
||
534 | |||
535 | /** |
||
536 | * Compute the isEmpty property |
||
537 | * |
||
538 | * A template is said to be empty if it has no xsl:apply-templates elements or any there is a empty |
||
539 | * element ancestor to an xsl:apply-templates element |
||
540 | * |
||
541 | * @return void |
||
542 | */ |
||
543 | protected function computeIsEmpty() |
||
547 | |||
548 | /** |
||
549 | * Compute the isTransparent property |
||
550 | * |
||
551 | * A template is said to be transparent if it has at least one branch and no non-transparent |
||
552 | * elements in its path |
||
553 | * |
||
554 | * @return void |
||
555 | */ |
||
556 | protected function computeIsTransparent() |
||
572 | |||
573 | /** |
||
574 | * Compute the isVoid property |
||
575 | * |
||
576 | * A template is said to be void if it has no xsl:apply-templates elements or any there is a void |
||
577 | * element ancestor to an xsl:apply-templates element |
||
578 | * |
||
579 | * @return void |
||
580 | */ |
||
581 | protected function computeIsVoid() |
||
585 | |||
586 | /** |
||
587 | * Compute the preservesNewLines property |
||
588 | * |
||
589 | * @return void |
||
590 | */ |
||
591 | protected function computePreservesNewLines() |
||
610 | |||
611 | /** |
||
612 | * Test whether given element is a block-level element |
||
613 | * |
||
614 | * @param DOMElement $element |
||
615 | * @return bool |
||
616 | */ |
||
617 | protected function elementIsBlock(DOMElement $element) |
||
631 | |||
632 | /** |
||
633 | * Retrieve and return the inline style assigned to given element |
||
634 | * |
||
635 | * @param DOMElement $node Context node |
||
636 | * @param bool $deep Whether to retrieve the content of all xsl:attribute descendants |
||
637 | * @return string |
||
638 | */ |
||
639 | protected function getStyle(DOMElement $node, $deep = false) |
||
657 | |||
658 | /** |
||
659 | * Test whether given node is a span element used for formatting |
||
660 | * |
||
661 | * Will return TRUE if the node is a span element with a class attribute and/or a style attribute |
||
662 | * and no other attributes |
||
663 | * |
||
664 | * @param DOMElement $node |
||
665 | * @return boolean |
||
666 | */ |
||
667 | protected function isFormattingSpan(DOMElement $node) |
||
689 | |||
690 | /** |
||
691 | * Store the names of every leaf node |
||
692 | * |
||
693 | * A leaf node is defined as the closest non-XSL ancestor to an xsl:apply-templates element |
||
694 | * |
||
695 | * @return void |
||
696 | */ |
||
697 | protected function storeLeafNodes() |
||
704 | |||
705 | /** |
||
706 | * "What is this?" you might ask. This is basically a compressed version of the HTML5 content |
||
707 | * models and rules, with some liberties taken. |
||
708 | * |
||
709 | * For each element, up to three bitfields are defined: "c", "ac" and "dd". Bitfields are stored |
||
710 | * as raw bytes, formatted using the octal notation to keep the sources ASCII. |
||
711 | * |
||
712 | * "c" represents the categories the element belongs to. The categories are comprised of HTML5 |
||
713 | * content models (such as "phrasing content" or "interactive content") plus a few special |
||
714 | * categories created to cover the parts of the specs that refer to "a group of X and Y |
||
715 | * elements" rather than a specific content model. |
||
716 | * |
||
717 | * "ac" represents the categories that are allowed as children of given element. |
||
718 | * |
||
719 | * "dd" represents the categories that must not appear as a descendant of given element. |
||
720 | * |
||
721 | * Sometimes, HTML5 specifies some restrictions on when an element can accept certain children, |
||
722 | * or what categories the element belongs to. For example, an <img> element is only part of the |
||
723 | * "interactive content" category if it has a "usemap" attribute. Those restrictions are |
||
724 | * expressed as an XPath expression and stored using the concatenation of the key of the bitfield |
||
725 | * plus the bit number of the category. For instance, if "interactive content" got assigned to |
||
726 | * bit 2, the definition of the <img> element will contain a key "c2" with value "@usemap". |
||
727 | * |
||
728 | * Additionally, other flags are set: |
||
729 | * |
||
730 | * "t" indicates that the element uses the "transparent" content model. |
||
731 | * "e" indicates that the element uses the "empty" content model. |
||
732 | * "v" indicates that the element is a void element. |
||
733 | * "nt" indicates that the element does not accept text nodes. (no text) |
||
734 | * "to" indicates that the element should only contain text. (text-only) |
||
735 | * "fe" indicates that the element is a formatting element. It will automatically be reopened |
||
736 | * when closed by an end tag of a different name. |
||
737 | * "b" indicates that the element is not phrasing content, which makes it likely to act like |
||
738 | * a block element. |
||
739 | * |
||
740 | * Finally, HTML5 defines "optional end tag" rules, where one element automatically closes its |
||
741 | * predecessor. Those are used to generate closeParent rules and are stored in the "cp" key. |
||
742 | * |
||
743 | * @var array |
||
744 | * @see /scripts/patchTemplateInspector.php |
||
745 | */ |
||
746 | protected static $htmlElements = [ |
||
747 | 'a'=>['c'=>"\17\0\0\0\0\1",'c3'=>'@href','ac'=>"\0",'dd'=>"\10\0\0\0\0\1",'t'=>1,'fe'=>1], |
||
748 | 'abbr'=>['c'=>"\7",'ac'=>"\4",'dd'=>"\0"], |
||
749 | 'address'=>['c'=>"\3\40",'ac'=>"\1",'dd'=>"\0\45",'b'=>1,'cp'=>['p']], |
||
750 | 'article'=>['c'=>"\3\4",'ac'=>"\1",'dd'=>"\0",'b'=>1,'cp'=>['p']], |
||
751 | 'aside'=>['c'=>"\3\4",'ac'=>"\1",'dd'=>"\0\0\0\0\10",'b'=>1,'cp'=>['p']], |
||
752 | 'audio'=>['c'=>"\57",'c3'=>'@controls','c1'=>'@controls','ac'=>"\0\0\0\104",'ac26'=>'not(@src)','dd'=>"\0\0\0\0\0\2",'dd41'=>'@src','t'=>1], |
||
753 | 'b'=>['c'=>"\7",'ac'=>"\4",'dd'=>"\0",'fe'=>1], |
||
754 | 'base'=>['c'=>"\20",'ac'=>"\0",'dd'=>"\0",'nt'=>1,'e'=>1,'v'=>1,'b'=>1], |
||
755 | 'bdi'=>['c'=>"\7",'ac'=>"\4",'dd'=>"\0"], |
||
756 | 'bdo'=>['c'=>"\7",'ac'=>"\4",'dd'=>"\0"], |
||
757 | 'blockquote'=>['c'=>"\203",'ac'=>"\1",'dd'=>"\0",'b'=>1,'cp'=>['p']], |
||
758 | 'body'=>['c'=>"\200\0\4",'ac'=>"\1",'dd'=>"\0",'b'=>1], |
||
759 | 'br'=>['c'=>"\5",'ac'=>"\0",'dd'=>"\0",'nt'=>1,'e'=>1,'v'=>1], |
||
760 | 'button'=>['c'=>"\117",'ac'=>"\4",'dd'=>"\10"], |
||
761 | 'canvas'=>['c'=>"\47",'ac'=>"\0",'dd'=>"\0",'t'=>1], |
||
762 | 'caption'=>['c'=>"\0\2",'ac'=>"\1",'dd'=>"\0\0\0\200",'b'=>1], |
||
763 | 'cite'=>['c'=>"\7",'ac'=>"\4",'dd'=>"\0"], |
||
764 | 'code'=>['c'=>"\7",'ac'=>"\4",'dd'=>"\0",'fe'=>1], |
||
765 | 'col'=>['c'=>"\0\0\20",'ac'=>"\0",'dd'=>"\0",'nt'=>1,'e'=>1,'v'=>1,'b'=>1], |
||
766 | 'colgroup'=>['c'=>"\0\2",'ac'=>"\0\0\20",'ac20'=>'not(@span)','dd'=>"\0",'nt'=>1,'e'=>1,'e0'=>'@span','b'=>1], |
||
767 | 'data'=>['c'=>"\7",'ac'=>"\4",'dd'=>"\0"], |
||
768 | 'datalist'=>['c'=>"\5",'ac'=>"\4\200\0\10",'dd'=>"\0"], |
||
769 | 'dd'=>['c'=>"\0\0\200",'ac'=>"\1",'dd'=>"\0",'b'=>1,'cp'=>['dd','dt']], |
||
770 | 'del'=>['c'=>"\5",'ac'=>"\0",'dd'=>"\0",'t'=>1], |
||
771 | 'details'=>['c'=>"\213",'ac'=>"\1\0\0\2",'dd'=>"\0",'b'=>1,'cp'=>['p']], |
||
772 | 'dfn'=>['c'=>"\7\0\0\0\40",'ac'=>"\4",'dd'=>"\0\0\0\0\40"], |
||
773 | 'div'=>['c'=>"\3",'ac'=>"\1",'dd'=>"\0",'b'=>1,'cp'=>['p']], |
||
774 | 'dl'=>['c'=>"\3",'c1'=>'dt and dd','ac'=>"\0\200\200",'dd'=>"\0",'nt'=>1,'b'=>1,'cp'=>['p']], |
||
775 | 'dt'=>['c'=>"\0\0\200",'ac'=>"\1",'dd'=>"\0\5\0\40",'b'=>1,'cp'=>['dd','dt']], |
||
776 | 'em'=>['c'=>"\7",'ac'=>"\4",'dd'=>"\0",'fe'=>1], |
||
777 | 'embed'=>['c'=>"\57",'ac'=>"\0",'dd'=>"\0",'nt'=>1,'e'=>1,'v'=>1], |
||
778 | 'fieldset'=>['c'=>"\303",'ac'=>"\1\0\0\20",'dd'=>"\0",'b'=>1,'cp'=>['p']], |
||
779 | 'figcaption'=>['c'=>"\0\0\0\0\0\4",'ac'=>"\1",'dd'=>"\0",'b'=>1,'cp'=>['p']], |
||
780 | 'figure'=>['c'=>"\203",'ac'=>"\1\0\0\0\0\4",'dd'=>"\0",'b'=>1,'cp'=>['p']], |
||
781 | 'footer'=>['c'=>"\3\40",'ac'=>"\1",'dd'=>"\0\0\0\0\10",'b'=>1,'cp'=>['p']], |
||
782 | 'form'=>['c'=>"\3\0\0\0\20",'ac'=>"\1",'dd'=>"\0\0\0\0\20",'b'=>1,'cp'=>['p']], |
||
783 | 'h1'=>['c'=>"\3\1",'ac'=>"\4",'dd'=>"\0",'b'=>1,'cp'=>['p']], |
||
784 | 'h2'=>['c'=>"\3\1",'ac'=>"\4",'dd'=>"\0",'b'=>1,'cp'=>['p']], |
||
785 | 'h3'=>['c'=>"\3\1",'ac'=>"\4",'dd'=>"\0",'b'=>1,'cp'=>['p']], |
||
786 | 'h4'=>['c'=>"\3\1",'ac'=>"\4",'dd'=>"\0",'b'=>1,'cp'=>['p']], |
||
787 | 'h5'=>['c'=>"\3\1",'ac'=>"\4",'dd'=>"\0",'b'=>1,'cp'=>['p']], |
||
788 | 'h6'=>['c'=>"\3\1",'ac'=>"\4",'dd'=>"\0",'b'=>1,'cp'=>['p']], |
||
789 | 'head'=>['c'=>"\0\0\4",'ac'=>"\20",'dd'=>"\0",'nt'=>1,'b'=>1], |
||
790 | 'header'=>['c'=>"\3\40\0\40",'ac'=>"\1",'dd'=>"\0\0\0\0\10",'b'=>1,'cp'=>['p']], |
||
791 | 'hr'=>['c'=>"\1\100",'ac'=>"\0",'dd'=>"\0",'nt'=>1,'e'=>1,'v'=>1,'b'=>1,'cp'=>['p']], |
||
792 | 'html'=>['c'=>"\0",'ac'=>"\0\0\4",'dd'=>"\0",'nt'=>1,'b'=>1], |
||
793 | 'i'=>['c'=>"\7",'ac'=>"\4",'dd'=>"\0",'fe'=>1], |
||
794 | 'iframe'=>['c'=>"\57",'ac'=>"\4",'dd'=>"\0"], |
||
795 | 'img'=>['c'=>"\57\20\10",'c3'=>'@usemap','ac'=>"\0",'dd'=>"\0",'nt'=>1,'e'=>1,'v'=>1], |
||
796 | 'input'=>['c'=>"\17\20",'c3'=>'@type!="hidden"','c12'=>'@type!="hidden" or @type="hidden"','c1'=>'@type!="hidden"','ac'=>"\0",'dd'=>"\0",'nt'=>1,'e'=>1,'v'=>1], |
||
797 | 'ins'=>['c'=>"\7",'ac'=>"\0",'dd'=>"\0",'t'=>1], |
||
798 | 'kbd'=>['c'=>"\7",'ac'=>"\4",'dd'=>"\0"], |
||
799 | 'keygen'=>['c'=>"\117",'ac'=>"\0",'dd'=>"\0",'nt'=>1,'e'=>1,'v'=>1], |
||
800 | 'label'=>['c'=>"\17\20\0\0\4",'ac'=>"\4",'dd'=>"\0\0\1\0\4"], |
||
801 | 'legend'=>['c'=>"\0\0\0\20",'ac'=>"\4",'dd'=>"\0",'b'=>1], |
||
802 | 'li'=>['c'=>"\0\0\0\0\200",'ac'=>"\1",'dd'=>"\0",'b'=>1,'cp'=>['li']], |
||
803 | 'link'=>['c'=>"\20",'ac'=>"\0",'dd'=>"\0",'nt'=>1,'e'=>1,'v'=>1,'b'=>1], |
||
804 | 'main'=>['c'=>"\3\0\0\0\10",'ac'=>"\1",'dd'=>"\0",'b'=>1,'cp'=>['p']], |
||
805 | 'mark'=>['c'=>"\7",'ac'=>"\4",'dd'=>"\0"], |
||
806 | 'media element'=>['c'=>"\0\0\0\0\0\2",'ac'=>"\0",'dd'=>"\0",'nt'=>1,'b'=>1], |
||
807 | 'menu'=>['c'=>"\1\100",'ac'=>"\0\300",'dd'=>"\0",'nt'=>1,'b'=>1,'cp'=>['p']], |
||
808 | 'menuitem'=>['c'=>"\0\100",'ac'=>"\0",'dd'=>"\0",'nt'=>1,'e'=>1,'v'=>1,'b'=>1], |
||
809 | 'meta'=>['c'=>"\20",'ac'=>"\0",'dd'=>"\0",'nt'=>1,'e'=>1,'v'=>1,'b'=>1], |
||
810 | 'meter'=>['c'=>"\7\0\1\0\2",'ac'=>"\4",'dd'=>"\0\0\0\0\2"], |
||
811 | 'nav'=>['c'=>"\3\4",'ac'=>"\1",'dd'=>"\0\0\0\0\10",'b'=>1,'cp'=>['p']], |
||
812 | 'noscript'=>['c'=>"\25",'ac'=>"\0",'dd'=>"\0",'nt'=>1], |
||
813 | 'object'=>['c'=>"\147",'ac'=>"\0\0\0\0\1",'dd'=>"\0",'t'=>1], |
||
814 | 'ol'=>['c'=>"\3",'c1'=>'li','ac'=>"\0\200\0\0\200",'dd'=>"\0",'nt'=>1,'b'=>1,'cp'=>['p']], |
||
815 | 'optgroup'=>['c'=>"\0\0\2",'ac'=>"\0\200\0\10",'dd'=>"\0",'nt'=>1,'b'=>1,'cp'=>['optgroup','option']], |
||
816 | 'option'=>['c'=>"\0\0\2\10",'ac'=>"\0",'dd'=>"\0",'b'=>1,'cp'=>['option']], |
||
817 | 'output'=>['c'=>"\107",'ac'=>"\4",'dd'=>"\0"], |
||
818 | 'p'=>['c'=>"\3",'ac'=>"\4",'dd'=>"\0",'b'=>1,'cp'=>['p']], |
||
819 | 'param'=>['c'=>"\0\0\0\0\1",'ac'=>"\0",'dd'=>"\0",'nt'=>1,'e'=>1,'v'=>1,'b'=>1], |
||
820 | 'picture'=>['c'=>"\45",'ac'=>"\0\200\10",'dd'=>"\0",'nt'=>1], |
||
821 | 'pre'=>['c'=>"\3",'ac'=>"\4",'dd'=>"\0",'pre'=>1,'b'=>1,'cp'=>['p']], |
||
822 | 'progress'=>['c'=>"\7\0\1\1",'ac'=>"\4",'dd'=>"\0\0\0\1"], |
||
823 | 'q'=>['c'=>"\7",'ac'=>"\4",'dd'=>"\0"], |
||
824 | 'rb'=>['c'=>"\0\10",'ac'=>"\4",'dd'=>"\0",'b'=>1], |
||
825 | 'rp'=>['c'=>"\0\10\100",'ac'=>"\4",'dd'=>"\0",'b'=>1,'cp'=>['rp','rt']], |
||
826 | 'rt'=>['c'=>"\0\10\100",'ac'=>"\4",'dd'=>"\0",'b'=>1,'cp'=>['rp','rt']], |
||
827 | 'rtc'=>['c'=>"\0\10",'ac'=>"\4\0\100",'dd'=>"\0",'b'=>1], |
||
828 | 'ruby'=>['c'=>"\7",'ac'=>"\4\10",'dd'=>"\0"], |
||
829 | 's'=>['c'=>"\7",'ac'=>"\4",'dd'=>"\0",'fe'=>1], |
||
830 | 'samp'=>['c'=>"\7",'ac'=>"\4",'dd'=>"\0"], |
||
831 | 'script'=>['c'=>"\25\200",'ac'=>"\0",'dd'=>"\0",'to'=>1], |
||
832 | 'section'=>['c'=>"\3\4",'ac'=>"\1",'dd'=>"\0",'b'=>1,'cp'=>['p']], |
||
833 | 'select'=>['c'=>"\117",'ac'=>"\0\200\2",'dd'=>"\0",'nt'=>1], |
||
834 | 'small'=>['c'=>"\7",'ac'=>"\4",'dd'=>"\0",'fe'=>1], |
||
835 | 'source'=>['c'=>"\0\0\10\4",'ac'=>"\0",'dd'=>"\0",'nt'=>1,'e'=>1,'v'=>1,'b'=>1], |
||
836 | 'span'=>['c'=>"\7",'ac'=>"\4",'dd'=>"\0"], |
||
837 | 'strong'=>['c'=>"\7",'ac'=>"\4",'dd'=>"\0",'fe'=>1], |
||
838 | 'style'=>['c'=>"\20",'ac'=>"\0",'dd'=>"\0",'to'=>1,'b'=>1], |
||
839 | 'sub'=>['c'=>"\7",'ac'=>"\4",'dd'=>"\0"], |
||
840 | 'summary'=>['c'=>"\0\0\0\2",'ac'=>"\4\1",'dd'=>"\0",'b'=>1], |
||
841 | 'sup'=>['c'=>"\7",'ac'=>"\4",'dd'=>"\0"], |
||
842 | 'table'=>['c'=>"\3\0\0\200",'ac'=>"\0\202",'dd'=>"\0",'nt'=>1,'b'=>1,'cp'=>['p']], |
||
843 | 'tbody'=>['c'=>"\0\2",'ac'=>"\0\200\0\0\100",'dd'=>"\0",'nt'=>1,'b'=>1,'cp'=>['tbody','td','tfoot','th','thead','tr']], |
||
844 | 'td'=>['c'=>"\200\0\40",'ac'=>"\1",'dd'=>"\0",'b'=>1,'cp'=>['td','th']], |
||
845 | 'template'=>['c'=>"\25\200\20",'ac'=>"\0",'dd'=>"\0",'nt'=>1], |
||
846 | 'textarea'=>['c'=>"\117",'ac'=>"\0",'dd'=>"\0",'pre'=>1,'to'=>1], |
||
847 | 'tfoot'=>['c'=>"\0\2",'ac'=>"\0\200\0\0\100",'dd'=>"\0",'nt'=>1,'b'=>1,'cp'=>['tbody','td','th','thead','tr']], |
||
848 | 'th'=>['c'=>"\0\0\40",'ac'=>"\1",'dd'=>"\0\5\0\40",'b'=>1,'cp'=>['td','th']], |
||
849 | 'thead'=>['c'=>"\0\2",'ac'=>"\0\200\0\0\100",'dd'=>"\0",'nt'=>1,'b'=>1], |
||
850 | 'time'=>['c'=>"\7",'ac'=>"\4",'ac2'=>'@datetime','dd'=>"\0"], |
||
851 | 'title'=>['c'=>"\20",'ac'=>"\0",'dd'=>"\0",'to'=>1,'b'=>1], |
||
852 | 'tr'=>['c'=>"\0\2\0\0\100",'ac'=>"\0\200\40",'dd'=>"\0",'nt'=>1,'b'=>1,'cp'=>['td','th','tr']], |
||
853 | 'track'=>['c'=>"\0\0\0\100",'ac'=>"\0",'dd'=>"\0",'nt'=>1,'e'=>1,'v'=>1,'b'=>1], |
||
854 | 'u'=>['c'=>"\7",'ac'=>"\4",'dd'=>"\0",'fe'=>1], |
||
855 | 'ul'=>['c'=>"\3",'c1'=>'li','ac'=>"\0\200\0\0\200",'dd'=>"\0",'nt'=>1,'b'=>1,'cp'=>['p']], |
||
856 | 'var'=>['c'=>"\7",'ac'=>"\4",'dd'=>"\0"], |
||
857 | 'video'=>['c'=>"\57",'c3'=>'@controls','ac'=>"\0\0\0\104",'ac26'=>'not(@src)','dd'=>"\0\0\0\0\0\2",'dd41'=>'@src','t'=>1], |
||
858 | 'wbr'=>['c'=>"\5",'ac'=>"\0",'dd'=>"\0",'nt'=>1,'e'=>1,'v'=>1] |
||
859 | ]; |
||
860 | |||
861 | /** |
||
862 | * Get the bitfield value for a given element in a given context |
||
863 | * |
||
864 | * @param DOMElement $element Context node |
||
865 | * @param string $k Bitfield name: either 'c', 'ac' or 'dd' |
||
866 | * @return string |
||
867 | */ |
||
868 | protected function getBitfield(DOMElement $element, $k) |
||
911 | |||
912 | /** |
||
913 | * Test whether given element has given property in context |
||
914 | * |
||
915 | * @param string $elName Element name |
||
916 | * @param string $propName Property name, see self::$htmlElements |
||
917 | * @param DOMElement $node Context node |
||
918 | * @return bool |
||
919 | */ |
||
920 | protected function hasProperty($elName, $propName, DOMElement $node) |
||
934 | |||
935 | /** |
||
936 | * Test whether two bitfields have any bits in common |
||
937 | * |
||
938 | * @param string $bitfield1 |
||
939 | * @param string $bitfield2 |
||
940 | * @return bool |
||
941 | */ |
||
942 | protected static function match($bitfield1, $bitfield2) |
||
946 | } |