@@ -21,7 +21,7 @@ |
||
21 | 21 | } |
22 | 22 | |
23 | 23 | // Provides read-only access to $length and $dom |
24 | - public function __get ($prop) { |
|
24 | + public function __get($prop) { |
|
25 | 25 | if ($prop == 'length') { |
26 | 26 | return $this->length; |
27 | 27 | } |
@@ -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() { |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | |
41 | 41 | $this->setErrorChecking($error_checking); |
42 | 42 | |
43 | - if(is_object($xml)){ |
|
43 | + if (is_object($xml)) { |
|
44 | 44 | if (is_a($xml, 'DOMElement')) { |
45 | 45 | $this->appendChild($this->importNode($xml, true)); |
46 | 46 | } |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | @$this->loadXML($xml, LIBXML_COMPACT); |
62 | 62 | } |
63 | 63 | else if (!$this->loadXML($xml, LIBXML_COMPACT)) { |
64 | - trigger_error('BetterDOMDocument\DOMDoc: Could not load: ' . htmlspecialchars($xml), E_USER_WARNING); |
|
64 | + trigger_error('BetterDOMDocument\DOMDoc: Could not load: '.htmlspecialchars($xml), E_USER_WARNING); |
|
65 | 65 | } |
66 | 66 | } |
67 | 67 | |
@@ -326,7 +326,7 @@ discard block |
||
326 | 326 | $prefix = $parts[0]; |
327 | 327 | if (isset($namespaces[$prefix])) { |
328 | 328 | if (!strpos($root_match[0], "xmlns:$prefix")) { |
329 | - $new_root .= " xmlns:$prefix='" . $namespaces[$prefix] . "'"; |
|
329 | + $new_root .= " xmlns:$prefix='".$namespaces[$prefix]."'"; |
|
330 | 330 | } |
331 | 331 | } |
332 | 332 | } |
@@ -335,7 +335,7 @@ discard block |
||
335 | 335 | |
336 | 336 | $dom = new DOMDoc($xml, $this->auto_ns); |
337 | 337 | if (!$dom->documentElement) { |
338 | - trigger_error('BetterDomDocument\DOMDoc Error: Invalid XML: ' . $xml); |
|
338 | + trigger_error('BetterDomDocument\DOMDoc Error: Invalid XML: '.$xml); |
|
339 | 339 | } |
340 | 340 | $element = $dom->documentElement; |
341 | 341 | |
@@ -456,7 +456,7 @@ discard block |
||
456 | 456 | $this->createContext($newnode, 'xml'); |
457 | 457 | $this->createContext($context, 'xpath'); |
458 | 458 | |
459 | - if (!$context){ |
|
459 | + if (!$context) { |
|
460 | 460 | return FALSE; |
461 | 461 | } |
462 | 462 | |
@@ -543,7 +543,7 @@ discard block |
||
543 | 543 | |
544 | 544 | if ($node) { |
545 | 545 | if (is_array($node) || get_class($node) == 'BetterDOMDocument\DOMList') { |
546 | - foreach($node as $item) { |
|
546 | + foreach ($node as $item) { |
|
547 | 547 | $this->remove($item); |
548 | 548 | } |
549 | 549 | } |
@@ -615,7 +615,7 @@ discard block |
||
615 | 615 | $xsl = ' |
616 | 616 | <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> |
617 | 617 | <xsl:template match="*"> |
618 | - <xsl:element name="' . $prefix . ':{local-name()}" namespace="' . $url . '"> |
|
618 | + <xsl:element name="' . $prefix.':{local-name()}" namespace="'.$url.'"> |
|
619 | 619 | <xsl:copy-of select="@*"/> |
620 | 620 | <xsl:apply-templates/> |
621 | 621 | </xsl:element> |
@@ -627,7 +627,7 @@ discard block |
||
627 | 627 | } |
628 | 628 | else { |
629 | 629 | // @@TODO: Report the correct calling file and number |
630 | - throw new Exception("Changing the namespace of a " . get_class($node) . " is not supported"); |
|
630 | + throw new Exception("Changing the namespace of a ".get_class($node)." is not supported"); |
|
631 | 631 | } |
632 | 632 | } |
633 | 633 | |
@@ -702,7 +702,7 @@ discard block |
||
702 | 702 | foreach ($this->getNamespaces() as $prefix => $url) { |
703 | 703 | $namespaces = ''; |
704 | 704 | if ($prefix != 'xsl' && $prefix != 'xlink') { |
705 | - $namespaces .= 'xmlns:' . $prefix . '="' . $url. '" '; |
|
705 | + $namespaces .= 'xmlns:'.$prefix.'="'.$url.'" '; |
|
706 | 706 | } |
707 | 707 | $xslOptions = str_replace("||namespaces||", $namespaces, $xslOptions); |
708 | 708 | } |
@@ -741,8 +741,8 @@ discard block |
||
741 | 741 | |
742 | 742 | // Copy namespace prefixes |
743 | 743 | foreach ($this->ns as $prefix => $namespace) { |
744 | - if (!$context->hasAttribute('xmlns:' . $prefix)) { |
|
745 | - $context->setAttribute('xmlns:' . $prefix, $namespace); |
|
744 | + if (!$context->hasAttribute('xmlns:'.$prefix)) { |
|
745 | + $context->setAttribute('xmlns:'.$prefix, $namespace); |
|
746 | 746 | } |
747 | 747 | } |
748 | 748 | |
@@ -752,7 +752,7 @@ discard block |
||
752 | 752 | // The types listed are html "void" elements. |
753 | 753 | // 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 | 754 | $pattern = '<(area|base|br|col|command|embed|hr|img|input|keygen|link|meta|param|source|track|wbr)(\b[^<]*)><\/\1>'; |
755 | - return preg_replace('/' . $pattern . '/', '<$1$2/>', $output); |
|
755 | + return preg_replace('/'.$pattern.'/', '<$1$2/>', $output); |
|
756 | 756 | } |
757 | 757 | else { |
758 | 758 | return $this->saveXML($context, LIBXML_NOEMPTYTAG); |
@@ -807,7 +807,7 @@ discard block |
||
807 | 807 | |
808 | 808 | // If it's an "XML" document, then get namespaces via xpath |
809 | 809 | $xpath = new \DOMXPath($this); |
810 | - foreach($xpath->query('namespace::*') as $namespace) { |
|
810 | + foreach ($xpath->query('namespace::*') as $namespace) { |
|
811 | 811 | if (!empty($namespace->prefix)) { |
812 | 812 | if ($namespace->prefix != 'xml' && $namespace->nodeValue != 'http://www.w3.org/XML/1998/namespace') { |
813 | 813 | $this->registerNamespace($namespace->prefix, $namespace->nodeValue); |
@@ -845,8 +845,8 @@ discard block |
||
845 | 845 | } |
846 | 846 | } |
847 | 847 | } |
848 | - else if (substr($attr->name,0,6) == 'xmlns:') { |
|
849 | - $prefix = substr($attr->name,6); |
|
848 | + else if (substr($attr->name, 0, 6) == 'xmlns:') { |
|
849 | + $prefix = substr($attr->name, 6); |
|
850 | 850 | $this->registerNamespace($prefix, $attr->value); |
851 | 851 | } |
852 | 852 | } |
@@ -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 | } |
@@ -447,8 +438,7 @@ discard block |
||
447 | 438 | if ($context->nextSibling) { |
448 | 439 | // $context has an immediate sibling : insert newnode before this one |
449 | 440 | return $context->parentNode->insertBefore($newnode, $context->nextSibling); |
450 | - } |
|
451 | - else { |
|
441 | + } else { |
|
452 | 442 | return $context->parentNode->appendChild($newnode); |
453 | 443 | } |
454 | 444 | } |
@@ -514,11 +504,9 @@ discard block |
||
514 | 504 | foreach($node as $item) { |
515 | 505 | $this->remove($item); |
516 | 506 | } |
517 | - } |
|
518 | - else if (get_class($node) == 'DOMNodeList') { |
|
507 | + } else if (get_class($node) == 'DOMNodeList') { |
|
519 | 508 | $this->remove(new DOMList($node, $this)); |
520 | - } |
|
521 | - else { |
|
509 | + } else { |
|
522 | 510 | $parent = $node->parentNode; |
523 | 511 | $parent->removeChild($node); |
524 | 512 | } |
@@ -540,8 +528,7 @@ discard block |
||
540 | 528 | public function tranform($xsl, $context = NULL) { |
541 | 529 | if (!$context) { |
542 | 530 | $doc = $this; |
543 | - } |
|
544 | - else { |
|
531 | + } else { |
|
545 | 532 | if (is_string($context)) { |
546 | 533 | $context = $this->xpathSingle($context); |
547 | 534 | } |
@@ -592,8 +579,7 @@ discard block |
||
592 | 579 | |
593 | 580 | $transformed = $this->tranform($xsl, $node); |
594 | 581 | return $this->replace($node, $transformed->documentElement); |
595 | - } |
|
596 | - else { |
|
582 | + } else { |
|
597 | 583 | // @@TODO: Report the correct calling file and number |
598 | 584 | throw new Exception("Changing the namespace of a " . get_class($node) . " is not supported"); |
599 | 585 | } |
@@ -678,14 +664,12 @@ discard block |
||
678 | 664 | // Add in xlink options |
679 | 665 | if ($options['xlink'] === TRUE) { |
680 | 666 | $options['xlink'] = "@xlink:type = 'simple'"; |
681 | - } |
|
682 | - else if (empty($options['xlink'])) { |
|
667 | + } else if (empty($options['xlink'])) { |
|
683 | 668 | $options['xlink'] = "false()"; |
684 | 669 | } |
685 | 670 | $xslOptions = str_replace("||xlink||", $options['xlink'], $xslOptions); |
686 | 671 | $transformed = $this->tranform($xslOptions, $context); |
687 | - } |
|
688 | - else { |
|
672 | + } else { |
|
689 | 673 | $transformed = $this->tranform($xslSimple, $context); |
690 | 674 | } |
691 | 675 | |
@@ -721,8 +705,7 @@ discard block |
||
721 | 705 | // Find any of these elements that have no child nodes and are therefore candidates for self-closing, replace them with a self-closed version. |
722 | 706 | $pattern = '<(area|base|br|col|command|embed|hr|img|input|keygen|link|meta|param|source|track|wbr)(\b[^<]*)><\/\1>'; |
723 | 707 | return preg_replace('/' . $pattern . '/', '<$1$2/>', $output); |
724 | - } |
|
725 | - else { |
|
708 | + } else { |
|
726 | 709 | return $this->saveXML($context, LIBXML_NOEMPTYTAG); |
727 | 710 | } |
728 | 711 | } |
@@ -738,8 +721,7 @@ discard block |
||
738 | 721 | // Check up error-checking |
739 | 722 | if ($error_checking == FALSE) { |
740 | 723 | $this->error_checking = 'none'; |
741 | - } |
|
742 | - else { |
|
724 | + } else { |
|
743 | 725 | $this->error_checking = $error_checking; |
744 | 726 | } |
745 | 727 | if ($this->error_checking != 'strict') { |
@@ -780,8 +762,7 @@ discard block |
||
780 | 762 | if ($namespace->prefix != 'xml' && $namespace->nodeValue != 'http://www.w3.org/XML/1998/namespace') { |
781 | 763 | $this->registerNamespace($namespace->prefix, $namespace->nodeValue); |
782 | 764 | } |
783 | - } |
|
784 | - else { |
|
765 | + } else { |
|
785 | 766 | $this->default_ns = $namespace->nodeValue; |
786 | 767 | if (is_string($auto_register_namespaces)) { |
787 | 768 | $this->registerNamespace($auto_register_namespaces, $namespace->nodeValue); |
@@ -812,8 +793,7 @@ discard block |
||
812 | 793 | $this->registerNamespace($tagname, $attr->value); |
813 | 794 | } |
814 | 795 | } |
815 | - } |
|
816 | - else if (substr($attr->name,0,6) == 'xmlns:') { |
|
796 | + } else if (substr($attr->name,0,6) == 'xmlns:') { |
|
817 | 797 | $prefix = substr($attr->name,6); |
818 | 798 | $this->registerNamespace($prefix, $attr->value); |
819 | 799 | } |
@@ -852,12 +832,10 @@ discard block |
||
852 | 832 | } |
853 | 833 | $context = $this->importNode($context->documentElement, TRUE); |
854 | 834 | return; |
855 | - } |
|
856 | - else if (is_a($context, 'DOMDocument')) { |
|
835 | + } else if (is_a($context, 'DOMDocument')) { |
|
857 | 836 | $context = $this->importNode($context->documentElement, TRUE); |
858 | 837 | return; |
859 | - } |
|
860 | - else { |
|
838 | + } else { |
|
861 | 839 | $context = $this->importNode($context, TRUE); |
862 | 840 | return; |
863 | 841 | } |
@@ -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 |
@@ -472,10 +472,10 @@ discard block |
||
472 | 472 | /** |
473 | 473 | * Given a pair of nodes, replace the first with the second |
474 | 474 | * |
475 | - * @param mixed $node |
|
475 | + * @param \DOMElement $node |
|
476 | 476 | * Node to be replaced. Can either be an xpath string or a DOMDocument (or even a DOMNode). |
477 | 477 | * |
478 | - * @param mixed $replace |
|
478 | + * @param \DOMElement $replace |
|
479 | 479 | * Replace $node with $replace. Replace can be an XML string, or a DOMNode |
480 | 480 | * |
481 | 481 | * @return mixed |
@@ -535,7 +535,7 @@ discard block |
||
535 | 535 | * $context can either be an xpath string, or a DOMElement. Ommiting it |
536 | 536 | * results in transforming the entire document |
537 | 537 | * |
538 | - * @return a new DOMDoc |
|
538 | + * @return DOMDoc new DOMDoc |
|
539 | 539 | */ |
540 | 540 | public function tranform($xsl, $context = NULL) { |
541 | 541 | if (!$context) { |
@@ -617,7 +617,7 @@ discard block |
||
617 | 617 | * it will transform all elements with xlink:type = simple into a <a href> element. |
618 | 618 | * Alternatively you may specify your own xpath for selecting which elements get transformed |
619 | 619 | * into <a href> tags. |
620 | - * @return HTML string |
|
620 | + * @return string string |
|
621 | 621 | */ |
622 | 622 | public function asHTML($context = NULL, $options = array()) { |
623 | 623 | $xslSimple = ' |
@@ -699,7 +699,7 @@ discard block |
||
699 | 699 | * $context can either be an xpath string, or a DOMElement. Ommiting it |
700 | 700 | * results in outputting the entire document |
701 | 701 | * |
702 | - * @return XML string |
|
702 | + * @return string string |
|
703 | 703 | */ |
704 | 704 | public function out($context = NULL) { |
705 | 705 | $this->createContext($context, 'xpath'); |
@@ -747,6 +747,9 @@ discard block |
||
747 | 747 | ); |
748 | 748 | } |
749 | 749 | |
750 | + /** |
|
751 | + * @param string|boolean $error_checking |
|
752 | + */ |
|
750 | 753 | public function setErrorChecking($error_checking) { |
751 | 754 | // Check up error-checking |
752 | 755 | if ($error_checking == FALSE) { |
@@ -776,6 +779,10 @@ discard block |
||
776 | 779 | return boolval($success); |
777 | 780 | } |
778 | 781 | |
782 | + /** |
|
783 | + * @param string $source |
|
784 | + * @param integer $options |
|
785 | + */ |
|
779 | 786 | public function loadXML($source, $options = NULL) { |
780 | 787 | $success = parent::loadXML($source, $options); |
781 | 788 | $this->AutoRegisterNamespace(TRUE); |