@@ -24,11 +24,9 @@ discard block |
||
24 | 24 | public function __get ($prop) { |
25 | 25 | if ($prop == 'length') { |
26 | 26 | return $this->length; |
27 | - } |
|
28 | - else if ($prop == 'dom') { |
|
27 | + } else if ($prop == 'dom') { |
|
29 | 28 | return $this->dom; |
30 | - } |
|
31 | - else { |
|
29 | + } else { |
|
32 | 30 | return null; |
33 | 31 | } |
34 | 32 | } |
@@ -56,8 +54,9 @@ discard block |
||
56 | 54 | public function item($index) { |
57 | 55 | if (isset($this->array[$index])) { |
58 | 56 | return $this->array[$index]; |
57 | + } else { |
|
58 | + return FALSE; |
|
59 | 59 | } |
60 | - else return FALSE; |
|
61 | 60 | } |
62 | 61 | |
63 | 62 | public function count() { |
@@ -22,14 +22,14 @@ discard block |
||
22 | 22 | * $xml can either be an XML string, a DOMDocument, or a DOMElement. |
23 | 23 | * You can also pass FALSE or NULL (or omit it) and load XML later using loadXML or loadHTML |
24 | 24 | * |
25 | - * @param mixed $auto_register_namespaces |
|
25 | + * @param boolean $auto_register_namespaces |
|
26 | 26 | * Auto-register namespaces. All namespaces in the root element will be registered for use in xpath queries. |
27 | 27 | * Namespaces that are not declared in the root element will not be auto-registered |
28 | 28 | * Defaults to TRUE (Meaning it will auto register all auxiliary namespaces but not the default namespace). |
29 | 29 | * Pass a prefix string to automatically register the default namespace. |
30 | 30 | * Pass FALSE to disable auto-namespace registeration |
31 | 31 | * |
32 | - * @param bool $error_checking |
|
32 | + * @param string|boolean $error_checking |
|
33 | 33 | * Can be 'strict', 'warning', or 'none. Defaults to 'strict'. |
34 | 34 | * 'none' supresses all errors |
35 | 35 | * 'warning' is the default behavior in DOMDocument |
@@ -487,10 +487,10 @@ discard block |
||
487 | 487 | /** |
488 | 488 | * Given a pair of nodes, replace the first with the second |
489 | 489 | * |
490 | - * @param mixed $node |
|
490 | + * @param \DOMElement $node |
|
491 | 491 | * Node to be replaced. Can either be an xpath string or a DOMDocument (or even a DOMNode). |
492 | 492 | * |
493 | - * @param mixed $replace |
|
493 | + * @param \DOMElement $replace |
|
494 | 494 | * Replace $node with $replace. Replace can be an XML string, or a DOMNode |
495 | 495 | * |
496 | 496 | * @return mixed |
@@ -550,7 +550,7 @@ discard block |
||
550 | 550 | * $context can either be an xpath string, or a DOMElement. Ommiting it |
551 | 551 | * results in transforming the entire document |
552 | 552 | * |
553 | - * @return a new DOMDoc |
|
553 | + * @return DOMDoc new DOMDoc |
|
554 | 554 | */ |
555 | 555 | public function tranform($xsl, $context = NULL) { |
556 | 556 | if (!$context) { |
@@ -632,7 +632,7 @@ discard block |
||
632 | 632 | * it will transform all elements with xlink:type = simple into a <a href> element. |
633 | 633 | * Alternatively you may specify your own xpath for selecting which elements get transformed |
634 | 634 | * into <a href> tags. |
635 | - * @return HTML string |
|
635 | + * @return string string |
|
636 | 636 | */ |
637 | 637 | public function asHTML($context = NULL, $options = array()) { |
638 | 638 | $xslSimple = ' |
@@ -714,7 +714,7 @@ discard block |
||
714 | 714 | * $context can either be an xpath string, or a DOMElement. Ommiting it |
715 | 715 | * results in outputting the entire document |
716 | 716 | * |
717 | - * @return XML string |
|
717 | + * @return string string |
|
718 | 718 | */ |
719 | 719 | public function out($context = NULL) { |
720 | 720 | $this->createContext($context, 'xpath'); |
@@ -749,6 +749,9 @@ discard block |
||
749 | 749 | return $this->out(); |
750 | 750 | } |
751 | 751 | |
752 | + /** |
|
753 | + * @param string|boolean $error_checking |
|
754 | + */ |
|
752 | 755 | public function setErrorChecking($error_checking) { |
753 | 756 | // Check up error-checking |
754 | 757 | if ($error_checking == FALSE) { |
@@ -778,6 +781,10 @@ discard block |
||
778 | 781 | return boolval($success); |
779 | 782 | } |
780 | 783 | |
784 | + /** |
|
785 | + * @param string $source |
|
786 | + * @param integer $options |
|
787 | + */ |
|
781 | 788 | public function loadXML($source, $options = NULL) { |
782 | 789 | $success = parent::loadXML($source, $options); |
783 | 790 | $this->AutoRegisterNamespace(TRUE); |
@@ -55,12 +55,10 @@ discard block |
||
55 | 55 | $this->appendChild($this->importNode($xml->documentElement, true)); |
56 | 56 | } |
57 | 57 | } |
58 | - } |
|
59 | - else if (is_string($xml) && !empty($xml)) { |
|
58 | + } else if (is_string($xml) && !empty($xml)) { |
|
60 | 59 | if ($this->error_checking == 'none') { |
61 | 60 | @$this->loadXML($xml, LIBXML_COMPACT); |
62 | - } |
|
63 | - else if (!$this->loadXML($xml, LIBXML_COMPACT)) { |
|
61 | + } else if (!$this->loadXML($xml, LIBXML_COMPACT)) { |
|
64 | 62 | trigger_error('BetterDOMDocument\DOMDoc: Could not load: ' . htmlspecialchars($xml), E_USER_WARNING); |
65 | 63 | } |
66 | 64 | } |
@@ -115,8 +113,7 @@ discard block |
||
115 | 113 | public function lookupURL($prefix) { |
116 | 114 | if (isset($this->ns[$prefix])) { |
117 | 115 | return $this->ns[$prefix]; |
118 | - } |
|
119 | - else { |
|
116 | + } else { |
|
120 | 117 | return FALSE; |
121 | 118 | } |
122 | 119 | } |
@@ -150,15 +147,13 @@ discard block |
||
150 | 147 | |
151 | 148 | if ($context) { |
152 | 149 | $result = $xob->query($xpath, $context); |
153 | - } |
|
154 | - else { |
|
150 | + } else { |
|
155 | 151 | $result = $xob->query($xpath); |
156 | 152 | } |
157 | 153 | |
158 | 154 | if ($result) { |
159 | 155 | return new DOMList($result, $this); |
160 | - } |
|
161 | - else { |
|
156 | + } else { |
|
162 | 157 | return FALSE; |
163 | 158 | } |
164 | 159 | } |
@@ -182,8 +177,7 @@ discard block |
||
182 | 177 | |
183 | 178 | if (empty($result) || !count($result)) { |
184 | 179 | return FALSE; |
185 | - } |
|
186 | - else { |
|
180 | + } else { |
|
187 | 181 | return $result->item(0); |
188 | 182 | } |
189 | 183 | } |
@@ -262,13 +256,11 @@ discard block |
||
262 | 256 | if ($context->hasChildNodes()) { |
263 | 257 | if ($context->childNodes->length == 1 && $context->firstChild->nodeType == XML_TEXT_NODE) { |
264 | 258 | $array['#text'] = $context->firstChild->nodeValue; |
265 | - } |
|
266 | - else { |
|
259 | + } else { |
|
267 | 260 | foreach ($context->childNodes as $childNode) { |
268 | 261 | if ($childNode->nodeType == XML_ELEMENT_NODE) { |
269 | 262 | $array[$childNode->nodeName][] = $this->getArray($raw, $childNode); |
270 | - } |
|
271 | - elseif ($childNode->nodeType == XML_CDATA_SECTION_NODE) { |
|
263 | + } elseif ($childNode->nodeType == XML_CDATA_SECTION_NODE) { |
|
272 | 264 | $array['#text'] = $childNode->textContent; |
273 | 265 | } |
274 | 266 | } |
@@ -300,8 +292,7 @@ discard block |
||
300 | 292 | $matches = array(); |
301 | 293 | if (preg_match($pattern, $this->saveXML($context), $matches)) { |
302 | 294 | return $matches[1]; |
303 | - } |
|
304 | - else { |
|
295 | + } else { |
|
305 | 296 | return ''; |
306 | 297 | } |
307 | 298 | } |
@@ -371,15 +362,13 @@ discard block |
||
371 | 362 | |
372 | 363 | if ($newnode->ownerDocument === $this) { |
373 | 364 | $appendnode = $newnode; |
374 | - } |
|
375 | - else { |
|
365 | + } else { |
|
376 | 366 | if (is_a($newnode, 'BetterDOMDocument\DOMDoc')) { |
377 | 367 | foreach ($newnode->ns as $prefix => $uri) { |
378 | 368 | $this->registerNamespace($prefix, $uri); |
379 | 369 | } |
380 | 370 | $newnode = $newnode->documentElement; |
381 | - } |
|
382 | - else if (is_a($newnode, 'DOMDocument')) { |
|
371 | + } else if (is_a($newnode, 'DOMDocument')) { |
|
383 | 372 | $newnode = $newnode->documentElement; |
384 | 373 | } |
385 | 374 | $appendnode = $this->importNode($newnode, true); |
@@ -463,20 +452,17 @@ discard block |
||
463 | 452 | if ($context->nextSibling) { |
464 | 453 | // $context has an immediate sibling : insert newnode before this one |
465 | 454 | return $context->parentNode->insertBefore($newnode, $context->nextSibling); |
466 | - } |
|
467 | - else { |
|
455 | + } else { |
|
468 | 456 | // $context has no sibling next to it : insert newnode as last child of it's parent |
469 | 457 | if ($newnode->ownerDocument === $this) { |
470 | 458 | $appendnode = $newnode; |
471 | - } |
|
472 | - else { |
|
459 | + } else { |
|
473 | 460 | if (is_a($newnode, 'BetterDOMDocument\DOMDoc')) { |
474 | 461 | foreach ($newnode->ns as $prefix => $uri) { |
475 | 462 | $this->registerNamespace($prefix, $uri); |
476 | 463 | } |
477 | 464 | $newnode = $newnode->documentElement; |
478 | - } |
|
479 | - else if (is_a($newnode, 'DOMDocument')) { |
|
465 | + } else if (is_a($newnode, 'DOMDocument')) { |
|
480 | 466 | $newnode = $newnode->documentElement; |
481 | 467 | } |
482 | 468 | $appendnode = $this->importNode($newnode, true); |
@@ -546,11 +532,9 @@ discard block |
||
546 | 532 | foreach($node as $item) { |
547 | 533 | $this->remove($item); |
548 | 534 | } |
549 | - } |
|
550 | - else if (get_class($node) == 'DOMNodeList') { |
|
535 | + } else if (get_class($node) == 'DOMNodeList') { |
|
551 | 536 | $this->remove(new DOMList($node, $this)); |
552 | - } |
|
553 | - else { |
|
537 | + } else { |
|
554 | 538 | $parent = $node->parentNode; |
555 | 539 | $parent->removeChild($node); |
556 | 540 | } |
@@ -572,8 +556,7 @@ discard block |
||
572 | 556 | public function tranform($xsl, $context = NULL) { |
573 | 557 | if (!$context) { |
574 | 558 | $doc = $this; |
575 | - } |
|
576 | - else { |
|
559 | + } else { |
|
577 | 560 | if (is_string($context)) { |
578 | 561 | $context = $this->xpathSingle($context); |
579 | 562 | } |
@@ -624,8 +607,7 @@ discard block |
||
624 | 607 | |
625 | 608 | $transformed = $this->tranform($xsl, $node); |
626 | 609 | return $this->replace($node, $transformed->documentElement); |
627 | - } |
|
628 | - else { |
|
610 | + } else { |
|
629 | 611 | // @@TODO: Report the correct calling file and number |
630 | 612 | throw new Exception("Changing the namespace of a " . get_class($node) . " is not supported"); |
631 | 613 | } |
@@ -710,14 +692,12 @@ discard block |
||
710 | 692 | // Add in xlink options |
711 | 693 | if ($options['xlink'] === TRUE) { |
712 | 694 | $options['xlink'] = "@xlink:type = 'simple'"; |
713 | - } |
|
714 | - else if (empty($options['xlink'])) { |
|
695 | + } else if (empty($options['xlink'])) { |
|
715 | 696 | $options['xlink'] = "false()"; |
716 | 697 | } |
717 | 698 | $xslOptions = str_replace("||xlink||", $options['xlink'], $xslOptions); |
718 | 699 | $transformed = $this->tranform($xslOptions, $context); |
719 | - } |
|
720 | - else { |
|
700 | + } else { |
|
721 | 701 | $transformed = $this->tranform($xslSimple, $context); |
722 | 702 | } |
723 | 703 | |
@@ -753,8 +733,7 @@ discard block |
||
753 | 733 | // Find any of these elements that have no child nodes and are therefore candidates for self-closing, replace them with a self-closed version. |
754 | 734 | $pattern = '<(area|base|br|col|command|embed|hr|img|input|keygen|link|meta|param|source|track|wbr)(\b[^<]*)><\/\1>'; |
755 | 735 | return preg_replace('/' . $pattern . '/', '<$1$2/>', $output); |
756 | - } |
|
757 | - else { |
|
736 | + } else { |
|
758 | 737 | return $this->saveXML($context, LIBXML_NOEMPTYTAG); |
759 | 738 | } |
760 | 739 | } |
@@ -770,8 +749,7 @@ discard block |
||
770 | 749 | // Check up error-checking |
771 | 750 | if ($error_checking == FALSE) { |
772 | 751 | $this->error_checking = 'none'; |
773 | - } |
|
774 | - else { |
|
752 | + } else { |
|
775 | 753 | $this->error_checking = $error_checking; |
776 | 754 | } |
777 | 755 | if ($this->error_checking != 'strict') { |
@@ -812,8 +790,7 @@ discard block |
||
812 | 790 | if ($namespace->prefix != 'xml' && $namespace->nodeValue != 'http://www.w3.org/XML/1998/namespace') { |
813 | 791 | $this->registerNamespace($namespace->prefix, $namespace->nodeValue); |
814 | 792 | } |
815 | - } |
|
816 | - else { |
|
793 | + } else { |
|
817 | 794 | $this->default_ns = $namespace->nodeValue; |
818 | 795 | if (is_string($auto_register_namespaces)) { |
819 | 796 | $this->registerNamespace($auto_register_namespaces, $namespace->nodeValue); |
@@ -844,8 +821,7 @@ discard block |
||
844 | 821 | $this->registerNamespace($tagname, $attr->value); |
845 | 822 | } |
846 | 823 | } |
847 | - } |
|
848 | - else if (substr($attr->name,0,6) == 'xmlns:') { |
|
824 | + } else if (substr($attr->name,0,6) == 'xmlns:') { |
|
849 | 825 | $prefix = substr($attr->name,6); |
850 | 826 | $this->registerNamespace($prefix, $attr->value); |
851 | 827 | } |