1 | <?php |
||
15 | class Normalizer extends IRProcessor |
||
16 | { |
||
17 | /** |
||
18 | * @var Optimizer |
||
19 | */ |
||
20 | protected $optimizer; |
||
21 | |||
22 | /** |
||
23 | * @var string Regexp that matches the names of all void elements |
||
24 | * @link http://www.w3.org/TR/html-markup/syntax.html#void-elements |
||
25 | */ |
||
26 | public $voidRegexp = '/^(?:area|base|br|col|command|embed|hr|img|input|keygen|link|meta|param|source|track|wbr)$/Di'; |
||
27 | |||
28 | /** |
||
29 | * @param Optimizer $optimizer |
||
30 | * @return void |
||
31 | */ |
||
32 | public function __construct(Optimizer $optimizer) |
||
36 | |||
37 | /** |
||
38 | * Normalize an IR |
||
39 | * |
||
40 | * @param DOMDocument $ir |
||
41 | * @return void |
||
42 | */ |
||
43 | public function normalize(DOMDocument $ir) |
||
55 | |||
56 | /** |
||
57 | * Add <closeTag/> elements everywhere an open start tag should be closed |
||
58 | * |
||
59 | * @param DOMDocument $ir |
||
60 | * @return void |
||
61 | */ |
||
62 | protected function addCloseTagElements(DOMDocument $ir) |
||
88 | |||
89 | /** |
||
90 | * Add an empty default <case/> to <switch/> nodes that don't have one |
||
91 | * |
||
92 | * @param DOMDocument $ir |
||
93 | * @return void |
||
94 | */ |
||
95 | protected function addDefaultCase(DOMDocument $ir) |
||
102 | |||
103 | /** |
||
104 | * Add an id attribute to <element/> nodes |
||
105 | * |
||
106 | * @param DOMDocument $ir |
||
107 | * @return void |
||
108 | */ |
||
109 | protected function addElementIds(DOMDocument $ir) |
||
117 | |||
118 | /** |
||
119 | * Get the context type for given output element |
||
120 | * |
||
121 | * @param DOMNode $output |
||
122 | * @return string |
||
123 | */ |
||
124 | protected function getOutputContext(DOMNode $output) |
||
141 | |||
142 | /** |
||
143 | * Get the ID of the closest "element" ancestor |
||
144 | * |
||
145 | * @param DOMNode $node Context node |
||
146 | * @return string|null |
||
147 | */ |
||
148 | protected function getParentElementId(DOMNode $node) |
||
160 | |||
161 | /** |
||
162 | * Mark switch elements that are used as branch tables |
||
163 | * |
||
164 | * If a switch is used for a series of equality tests against the same attribute or variable, the |
||
165 | * attribute/variable is stored within the switch as "branch-key" and the values it is compared |
||
166 | * against are stored JSON-encoded in the case as "branch-values". It can be used to create |
||
167 | * optimized branch tables |
||
168 | * |
||
169 | * @param DOMDocument $ir |
||
170 | * @return void |
||
171 | */ |
||
172 | protected function markBranchTables(DOMDocument $ir) |
||
180 | |||
181 | /** |
||
182 | * Mark given switch element if it's used as a branch table |
||
183 | * |
||
184 | * @param DOMElement $switch |
||
185 | * @return void |
||
186 | */ |
||
187 | protected function markSwitchTable(DOMElement $switch) |
||
213 | |||
214 | /** |
||
215 | * Mark conditional <closeTag/> nodes |
||
216 | * |
||
217 | * @param DOMDocument $ir |
||
218 | * @return void |
||
219 | */ |
||
220 | protected function markConditionalCloseTagElements(DOMDocument $ir) |
||
243 | |||
244 | /** |
||
245 | * Mark void elements |
||
246 | * |
||
247 | * @param DOMDocument $ir |
||
248 | * @return void |
||
249 | */ |
||
250 | protected function markVoidElements(DOMDocument $ir) |
||
268 | |||
269 | /** |
||
270 | * Fill in output context |
||
271 | * |
||
272 | * @param DOMDocument $ir |
||
273 | * @return void |
||
274 | */ |
||
275 | protected function setOutputContext(DOMDocument $ir) |
||
282 | } |