@@ -35,8 +35,9 @@ discard block |
||
35 | 35 | $htmlDoc = new \DomDocument; |
36 | 36 | $htmlDoc->loadHtml($doc); |
37 | 37 | |
38 | - if (strpos($doc, '<!') === 0) $doc = $htmlDoc; |
|
39 | - else { |
|
38 | + if (strpos($doc, '<!') === 0) { |
|
39 | + $doc = $htmlDoc; |
|
40 | + } else { |
|
40 | 41 | $templateNode = $htmlDoc->getElementsByTagName('template')[0]; |
41 | 42 | $this->document->appendChild($this->document->importNode($templateNode, true)); |
42 | 43 | } |
@@ -57,7 +58,9 @@ discard block |
||
57 | 58 | /** Loops through all assigned hooks, runs the Xpath query and calls the hook */ |
58 | 59 | private function processHooks() { |
59 | 60 | foreach ($this->hooks as list($query, $hook)) { |
60 | - foreach ($this->xpath->query($query) as $element) $hook->run($element); |
|
61 | + foreach ($this->xpath->query($query) as $element) { |
|
62 | + $hook->run($element); |
|
63 | + } |
|
61 | 64 | } |
62 | 65 | $this->hooks = []; |
63 | 66 | } |
@@ -65,7 +68,9 @@ discard block |
||
65 | 68 | /** Prints out the current DomDocument as HTML */ |
66 | 69 | private function printDocument(\DomDocument $doc) { |
67 | 70 | $output = ''; |
68 | - foreach ($doc->documentElement->childNodes as $node) $output .= $doc->saveXML($node, LIBXML_NOEMPTYTAG); |
|
71 | + foreach ($doc->documentElement->childNodes as $node) { |
|
72 | + $output .= $doc->saveXML($node, LIBXML_NOEMPTYTAG); |
|
73 | + } |
|
69 | 74 | return $output; |
70 | 75 | } |
71 | 76 | |
@@ -77,13 +82,18 @@ discard block |
||
77 | 82 | //Generate the document by taking only the childnodes of the template, ignoring the <template> and </template> tags |
78 | 83 | //TODO: Is there a faster way of doing this without string manipulation on the output or this loop through childnodes? |
79 | 84 | //Either return a whole DomDocument or return the output HTML |
80 | - if ($document) return $this->document; |
|
85 | + if ($document) { |
|
86 | + return $this->document; |
|
87 | + } |
|
81 | 88 | |
82 | 89 | |
83 | 90 | $output = ($this->document->doctype) ? $this->document->saveXml($this->document->doctype) . "\n" : ''; |
84 | 91 | |
85 | - if ($this->document->documentElement->tagName !== 'template') $output .= $this->document->saveXml($this->document->documentElement, LIBXML_NOEMPTYTAG); |
|
86 | - else $output = $this->printDocument($this->document); |
|
92 | + if ($this->document->documentElement->tagName !== 'template') { |
|
93 | + $output .= $this->document->saveXml($this->document->documentElement, LIBXML_NOEMPTYTAG); |
|
94 | + } else { |
|
95 | + $output = $this->printDocument($this->document); |
|
96 | + } |
|
87 | 97 | |
88 | 98 | //repair empty tags. Browsers break on <script /> and <div /> so can't avoid LIBXML_NOEMPTYTAG but they also break on <base></base> so repair them |
89 | 99 | $output = str_replace(['></img>', '></br>', '></meta>', '></base>', '></link>', '></hr>', '></input>'], ' />', $output); |