@@ -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 |
@@ -489,10 +489,10 @@ discard block |
||
| 489 | 489 | /** |
| 490 | 490 | * Given a pair of nodes, replace the first with the second |
| 491 | 491 | * |
| 492 | - * @param mixed $node |
|
| 492 | + * @param \DOMElement $node |
|
| 493 | 493 | * Node to be replaced. Can either be an xpath string or a DOMDocument (or even a DOMNode). |
| 494 | 494 | * |
| 495 | - * @param mixed $replace |
|
| 495 | + * @param \DOMElement $replace |
|
| 496 | 496 | * Replace $node with $replace. Replace can be an XML string, or a DOMNode |
| 497 | 497 | * |
| 498 | 498 | * @return replaced node |
@@ -552,7 +552,7 @@ discard block |
||
| 552 | 552 | * $context can either be an xpath string, or a DOMElement. Ommiting it |
| 553 | 553 | * results in transforming the entire document |
| 554 | 554 | * |
| 555 | - * @return a new DOMDoc |
|
| 555 | + * @return DOMDoc new DOMDoc |
|
| 556 | 556 | */ |
| 557 | 557 | function tranform($xsl, $context = NULL) { |
| 558 | 558 | if (!$context) { |
@@ -578,8 +578,6 @@ discard block |
||
| 578 | 578 | * @param mixed $node |
| 579 | 579 | * Node to be changed. Can either be an xpath string or a DOMElement. |
| 580 | 580 | * |
| 581 | - * @param mixed $replace |
|
| 582 | - * Replace $node with $replace. Replace can be an XML string, or a DOMNode |
|
| 583 | 581 | * |
| 584 | 582 | * @return the changed node |
| 585 | 583 | * The node with the new namespace. The node will also be changed in-situ in the document as well. |
@@ -635,7 +633,7 @@ discard block |
||
| 635 | 633 | * it will transform all elements with xlink:type = simple into a <a href> element. |
| 636 | 634 | * Alternatively you may specify your own xpath for selecting which elements get transformed |
| 637 | 635 | * into <a href> tags. |
| 638 | - * @return HTML string |
|
| 636 | + * @return string string |
|
| 639 | 637 | */ |
| 640 | 638 | function asHTML($context = NULL, $options = array()) { |
| 641 | 639 | $xslSimple = ' |
@@ -717,7 +715,7 @@ discard block |
||
| 717 | 715 | * $context can either be an xpath string, or a DOMElement. Ommiting it |
| 718 | 716 | * results in outputting the entire document |
| 719 | 717 | * |
| 720 | - * @return XML string |
|
| 718 | + * @return string string |
|
| 721 | 719 | */ |
| 722 | 720 | function out($context = NULL) { |
| 723 | 721 | $this->createContext($context, 'xpath'); |
@@ -752,6 +750,9 @@ discard block |
||
| 752 | 750 | return $this->out(); |
| 753 | 751 | } |
| 754 | 752 | |
| 753 | + /** |
|
| 754 | + * @param string|boolean $error_checking |
|
| 755 | + */ |
|
| 755 | 756 | public function setErrorChecking($error_checking) { |
| 756 | 757 | // Check up error-checking |
| 757 | 758 | if ($error_checking == FALSE) { |
@@ -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 | $class = get_class($xml); |
| 45 | 45 | if ($class == 'DOMElement') { |
| 46 | 46 | $this->appendChild($this->importNode($xml, true)); |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | } |
| 65 | 65 | else { |
| 66 | 66 | if (!$this->loadXML($xml, LIBXML_COMPACT)) { |
| 67 | - trigger_error('BetterDOMDocument\DOMDoc: Could not load: ' . htmlspecialchars($xml), E_USER_WARNING); |
|
| 67 | + trigger_error('BetterDOMDocument\DOMDoc: Could not load: '.htmlspecialchars($xml), E_USER_WARNING); |
|
| 68 | 68 | } |
| 69 | 69 | } |
| 70 | 70 | } |
@@ -329,7 +329,7 @@ discard block |
||
| 329 | 329 | $prefix = $parts[0]; |
| 330 | 330 | if (isset($namespaces[$prefix])) { |
| 331 | 331 | if (!strpos($root_match[0], "xmlns:$prefix")) { |
| 332 | - $new_root .= " xmlns:$prefix='" . $namespaces[$prefix] . "'"; |
|
| 332 | + $new_root .= " xmlns:$prefix='".$namespaces[$prefix]."'"; |
|
| 333 | 333 | } |
| 334 | 334 | } |
| 335 | 335 | } |
@@ -338,7 +338,7 @@ discard block |
||
| 338 | 338 | |
| 339 | 339 | $dom = new DOMDoc($xml, $this->auto_ns); |
| 340 | 340 | if (!$dom->documentElement) { |
| 341 | - trigger_error('BetterDomDocument\DOMDoc Error: Invalid XML: ' . $xml); |
|
| 341 | + trigger_error('BetterDomDocument\DOMDoc Error: Invalid XML: '.$xml); |
|
| 342 | 342 | } |
| 343 | 343 | $element = $dom->documentElement; |
| 344 | 344 | |
@@ -450,7 +450,7 @@ discard block |
||
| 450 | 450 | $this->createContext($newnode, 'xml'); |
| 451 | 451 | $this->createContext($context, 'xpath'); |
| 452 | 452 | |
| 453 | - if (!$context){ |
|
| 453 | + if (!$context) { |
|
| 454 | 454 | return FALSE; |
| 455 | 455 | } |
| 456 | 456 | |
@@ -528,7 +528,7 @@ discard block |
||
| 528 | 528 | |
| 529 | 529 | if ($node) { |
| 530 | 530 | if (is_array($node) || get_class($node) == 'BetterDOMDocument\DOMList') { |
| 531 | - foreach($node as $item) { |
|
| 531 | + foreach ($node as $item) { |
|
| 532 | 532 | $this->remove($item); |
| 533 | 533 | } |
| 534 | 534 | } |
@@ -596,12 +596,12 @@ discard block |
||
| 596 | 596 | if (get_class($node) == 'DOMElement') { |
| 597 | 597 | $elemname = array_pop(explode(':', $node->tagName)); |
| 598 | 598 | |
| 599 | - $replace = DOMDocument::createElementNS($url, $prefix . ':' . $elemname); |
|
| 599 | + $replace = DOMDocument::createElementNS($url, $prefix.':'.$elemname); |
|
| 600 | 600 | |
| 601 | 601 | $xsl = ' |
| 602 | 602 | <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> |
| 603 | 603 | <xsl:template match="*"> |
| 604 | - <xsl:element name="' . $prefix . ':{local-name()}" namespace="' . $url . '"> |
|
| 604 | + <xsl:element name="' . $prefix.':{local-name()}" namespace="'.$url.'"> |
|
| 605 | 605 | <xsl:copy-of select="@*"/> |
| 606 | 606 | <xsl:apply-templates/> |
| 607 | 607 | </xsl:element> |
@@ -613,7 +613,7 @@ discard block |
||
| 613 | 613 | } |
| 614 | 614 | else { |
| 615 | 615 | // @@TODO: Report the correct calling file and number |
| 616 | - throw new Exception("Changing the namespace of a " . get_class($node) . " is not supported"); |
|
| 616 | + throw new Exception("Changing the namespace of a ".get_class($node)." is not supported"); |
|
| 617 | 617 | } |
| 618 | 618 | } |
| 619 | 619 | |
@@ -688,7 +688,7 @@ discard block |
||
| 688 | 688 | foreach ($this->getNamespaces() as $prefix => $url) { |
| 689 | 689 | $namespaces = ''; |
| 690 | 690 | if ($prefix != 'xsl' && $prefix != 'xlink') { |
| 691 | - $namespaces .= 'xmlns:' . $prefix . '="' . $url. '" '; |
|
| 691 | + $namespaces .= 'xmlns:'.$prefix.'="'.$url.'" '; |
|
| 692 | 692 | } |
| 693 | 693 | $xslOptions = str_replace("||namespaces||", $namespaces, $xslOptions); |
| 694 | 694 | } |
@@ -727,8 +727,8 @@ discard block |
||
| 727 | 727 | |
| 728 | 728 | // Copy namespace prefixes |
| 729 | 729 | foreach ($this->ns as $prefix => $namespace) { |
| 730 | - if (!$context->hasAttribute('xmlns:' . $prefix)) { |
|
| 731 | - $context->setAttribute('xmlns:' . $prefix, $namespace); |
|
| 730 | + if (!$context->hasAttribute('xmlns:'.$prefix)) { |
|
| 731 | + $context->setAttribute('xmlns:'.$prefix, $namespace); |
|
| 732 | 732 | } |
| 733 | 733 | } |
| 734 | 734 | |
@@ -738,7 +738,7 @@ discard block |
||
| 738 | 738 | // The types listed are html "void" elements. |
| 739 | 739 | // Find any of these elements that have no child nodes and are therefore candidates for self-closing, replace them with a self-closed version. |
| 740 | 740 | $pattern = '<(area|base|br|col|command|embed|hr|img|input|keygen|link|meta|param|source|track|wbr)(\b[^<]*)><\/\1>'; |
| 741 | - return preg_replace('/' . $pattern . '/', '<$1$2/>', $output); |
|
| 741 | + return preg_replace('/'.$pattern.'/', '<$1$2/>', $output); |
|
| 742 | 742 | } |
| 743 | 743 | else { |
| 744 | 744 | return $this->saveXML($context, LIBXML_NOEMPTYTAG); |
@@ -779,7 +779,7 @@ discard block |
||
| 779 | 779 | |
| 780 | 780 | // If it's an "XML" document, then get namespaces via xpath |
| 781 | 781 | $xpath = new \DOMXPath($this); |
| 782 | - foreach($xpath->query('namespace::*') as $namespace) { |
|
| 782 | + foreach ($xpath->query('namespace::*') as $namespace) { |
|
| 783 | 783 | if (!empty($namespace->prefix)) { |
| 784 | 784 | if ($namespace->prefix != 'xml' && $namespace->nodeValue != 'http://www.w3.org/XML/1998/namespace') { |
| 785 | 785 | $this->registerNamespace($namespace->prefix, $namespace->nodeValue); |
@@ -817,8 +817,8 @@ discard block |
||
| 817 | 817 | } |
| 818 | 818 | } |
| 819 | 819 | } |
| 820 | - else if (substr($attr->name,0,6) == 'xmlns:') { |
|
| 821 | - $prefix = substr($attr->name,6); |
|
| 820 | + else if (substr($attr->name, 0, 6) == 'xmlns:') { |
|
| 821 | + $prefix = substr($attr->name, 6); |
|
| 822 | 822 | $this->registerNamespace($prefix, $attr->value); |
| 823 | 823 | } |
| 824 | 824 | } |
@@ -61,8 +61,7 @@ discard block |
||
| 61 | 61 | if ($xml && is_string($xml)) { |
| 62 | 62 | if ($this->error_checking == 'none') { |
| 63 | 63 | @$this->loadXML($xml, LIBXML_COMPACT); |
| 64 | - } |
|
| 65 | - else { |
|
| 64 | + } else { |
|
| 66 | 65 | if (!$this->loadXML($xml, LIBXML_COMPACT)) { |
| 67 | 66 | trigger_error('BetterDOMDocument\DOMDoc: Could not load: ' . htmlspecialchars($xml), E_USER_WARNING); |
| 68 | 67 | } |
@@ -118,8 +117,7 @@ discard block |
||
| 118 | 117 | function lookupURL($prefix) { |
| 119 | 118 | if (isset($this->ns[$prefix])) { |
| 120 | 119 | return $this->ns[$prefix]; |
| 121 | - } |
|
| 122 | - else { |
|
| 120 | + } else { |
|
| 123 | 121 | return FALSE; |
| 124 | 122 | } |
| 125 | 123 | } |
@@ -153,15 +151,13 @@ discard block |
||
| 153 | 151 | |
| 154 | 152 | if ($context) { |
| 155 | 153 | $result = $xob->query($xpath, $context); |
| 156 | - } |
|
| 157 | - else { |
|
| 154 | + } else { |
|
| 158 | 155 | $result = $xob->query($xpath); |
| 159 | 156 | } |
| 160 | 157 | |
| 161 | 158 | if ($result) { |
| 162 | 159 | return new DOMList($result, $this); |
| 163 | - } |
|
| 164 | - else { |
|
| 160 | + } else { |
|
| 165 | 161 | return FALSE; |
| 166 | 162 | } |
| 167 | 163 | } |
@@ -185,8 +181,7 @@ discard block |
||
| 185 | 181 | |
| 186 | 182 | if (empty($result) || !count($result)) { |
| 187 | 183 | return FALSE; |
| 188 | - } |
|
| 189 | - else { |
|
| 184 | + } else { |
|
| 190 | 185 | return $result->item(0); |
| 191 | 186 | } |
| 192 | 187 | } |
@@ -265,13 +260,11 @@ discard block |
||
| 265 | 260 | if ($context->hasChildNodes()) { |
| 266 | 261 | if ($context->childNodes->length == 1 && $context->firstChild->nodeType == XML_TEXT_NODE) { |
| 267 | 262 | $array['#text'] = $context->firstChild->nodeValue; |
| 268 | - } |
|
| 269 | - else { |
|
| 263 | + } else { |
|
| 270 | 264 | foreach ($context->childNodes as $childNode) { |
| 271 | 265 | if ($childNode->nodeType == XML_ELEMENT_NODE) { |
| 272 | 266 | $array[$childNode->nodeName][] = $this->getArray($raw, $childNode); |
| 273 | - } |
|
| 274 | - elseif ($childNode->nodeType == XML_CDATA_SECTION_NODE) { |
|
| 267 | + } elseif ($childNode->nodeType == XML_CDATA_SECTION_NODE) { |
|
| 275 | 268 | $array['#text'] = $childNode->textContent; |
| 276 | 269 | } |
| 277 | 270 | } |
@@ -303,8 +296,7 @@ discard block |
||
| 303 | 296 | $matches = array(); |
| 304 | 297 | if (preg_match($pattern, $this->saveXML($context), $matches)) { |
| 305 | 298 | return $matches[1]; |
| 306 | - } |
|
| 307 | - else { |
|
| 299 | + } else { |
|
| 308 | 300 | return ''; |
| 309 | 301 | } |
| 310 | 302 | } |
@@ -374,8 +366,7 @@ discard block |
||
| 374 | 366 | |
| 375 | 367 | if ($newnode->ownerDocument === $this) { |
| 376 | 368 | $appendnode = $newnode; |
| 377 | - } |
|
| 378 | - else { |
|
| 369 | + } else { |
|
| 379 | 370 | $appendnode = $this->importNode($newnode, true); |
| 380 | 371 | } |
| 381 | 372 | |
@@ -457,13 +448,11 @@ discard block |
||
| 457 | 448 | if ($context->nextSibling) { |
| 458 | 449 | // $context has an immediate sibling : insert newnode before this one |
| 459 | 450 | return $context->parentNode->insertBefore($newnode, $context->nextSibling); |
| 460 | - } |
|
| 461 | - else { |
|
| 451 | + } else { |
|
| 462 | 452 | // $context has no sibling next to it : insert newnode as last child of it's parent |
| 463 | 453 | if ($newnode->ownerDocument === $this) { |
| 464 | 454 | $appendnode = $newnode; |
| 465 | - } |
|
| 466 | - else { |
|
| 455 | + } else { |
|
| 467 | 456 | $appendnode = $this->importNode($newnode, true); |
| 468 | 457 | } |
| 469 | 458 | return $context->parentNode->appendChild($appendnode); |
@@ -531,11 +520,9 @@ discard block |
||
| 531 | 520 | foreach($node as $item) { |
| 532 | 521 | $this->remove($item); |
| 533 | 522 | } |
| 534 | - } |
|
| 535 | - else if (get_class($node) == 'DOMNodeList') { |
|
| 523 | + } else if (get_class($node) == 'DOMNodeList') { |
|
| 536 | 524 | $this->remove(new DOMList($node, $this)); |
| 537 | - } |
|
| 538 | - else { |
|
| 525 | + } else { |
|
| 539 | 526 | $parent = $node->parentNode; |
| 540 | 527 | $parent->removeChild($node); |
| 541 | 528 | } |
@@ -557,8 +544,7 @@ discard block |
||
| 557 | 544 | function tranform($xsl, $context = NULL) { |
| 558 | 545 | if (!$context) { |
| 559 | 546 | $doc = $this; |
| 560 | - } |
|
| 561 | - else { |
|
| 547 | + } else { |
|
| 562 | 548 | if (is_string($context)) { |
| 563 | 549 | $context = $this->xpathSingle($context); |
| 564 | 550 | } |
@@ -610,8 +596,7 @@ discard block |
||
| 610 | 596 | |
| 611 | 597 | $transformed = $this->tranform($xsl, $node); |
| 612 | 598 | return $this->replace($node, $transformed->documentElement); |
| 613 | - } |
|
| 614 | - else { |
|
| 599 | + } else { |
|
| 615 | 600 | // @@TODO: Report the correct calling file and number |
| 616 | 601 | throw new Exception("Changing the namespace of a " . get_class($node) . " is not supported"); |
| 617 | 602 | } |
@@ -696,14 +681,12 @@ discard block |
||
| 696 | 681 | // Add in xlink options |
| 697 | 682 | if ($options['xlink'] === TRUE) { |
| 698 | 683 | $options['xlink'] = "@xlink:type = 'simple'"; |
| 699 | - } |
|
| 700 | - else if (empty($options['xlink'])) { |
|
| 684 | + } else if (empty($options['xlink'])) { |
|
| 701 | 685 | $options['xlink'] = "false()"; |
| 702 | 686 | } |
| 703 | 687 | $xslOptions = str_replace("||xlink||", $options['xlink'], $xslOptions); |
| 704 | 688 | $transformed = $this->tranform($xslOptions, $context); |
| 705 | - } |
|
| 706 | - else { |
|
| 689 | + } else { |
|
| 707 | 690 | $transformed = $this->tranform($xslSimple, $context); |
| 708 | 691 | } |
| 709 | 692 | |
@@ -739,8 +722,7 @@ discard block |
||
| 739 | 722 | // Find any of these elements that have no child nodes and are therefore candidates for self-closing, replace them with a self-closed version. |
| 740 | 723 | $pattern = '<(area|base|br|col|command|embed|hr|img|input|keygen|link|meta|param|source|track|wbr)(\b[^<]*)><\/\1>'; |
| 741 | 724 | return preg_replace('/' . $pattern . '/', '<$1$2/>', $output); |
| 742 | - } |
|
| 743 | - else { |
|
| 725 | + } else { |
|
| 744 | 726 | return $this->saveXML($context, LIBXML_NOEMPTYTAG); |
| 745 | 727 | } |
| 746 | 728 | } |
@@ -756,8 +738,7 @@ discard block |
||
| 756 | 738 | // Check up error-checking |
| 757 | 739 | if ($error_checking == FALSE) { |
| 758 | 740 | $this->error_checking = 'none'; |
| 759 | - } |
|
| 760 | - else { |
|
| 741 | + } else { |
|
| 761 | 742 | $this->error_checking = $error_checking; |
| 762 | 743 | } |
| 763 | 744 | if ($this->error_checking != 'strict') { |
@@ -784,8 +765,7 @@ discard block |
||
| 784 | 765 | if ($namespace->prefix != 'xml' && $namespace->nodeValue != 'http://www.w3.org/XML/1998/namespace') { |
| 785 | 766 | $this->registerNamespace($namespace->prefix, $namespace->nodeValue); |
| 786 | 767 | } |
| 787 | - } |
|
| 788 | - else { |
|
| 768 | + } else { |
|
| 789 | 769 | $this->default_ns = $namespace->nodeValue; |
| 790 | 770 | if (is_string($auto_register_namespaces)) { |
| 791 | 771 | $this->registerNamespace($auto_register_namespaces, $namespace->nodeValue); |
@@ -816,8 +796,7 @@ discard block |
||
| 816 | 796 | $this->registerNamespace($tagname, $attr->value); |
| 817 | 797 | } |
| 818 | 798 | } |
| 819 | - } |
|
| 820 | - else if (substr($attr->name,0,6) == 'xmlns:') { |
|
| 799 | + } else if (substr($attr->name,0,6) == 'xmlns:') { |
|
| 821 | 800 | $prefix = substr($attr->name,6); |
| 822 | 801 | $this->registerNamespace($prefix, $attr->value); |
| 823 | 802 | } |
@@ -53,6 +53,9 @@ |
||
| 53 | 53 | return isset($this->array[$this->position]); |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | + /** |
|
| 57 | + * @param integer $index |
|
| 58 | + */ |
|
| 56 | 59 | function item($index) { |
| 57 | 60 | if (isset($this->array[$index])) { |
| 58 | 61 | return $this->array[$index]; |
@@ -21,7 +21,7 @@ |
||
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | // Provides read-only access to $length and $dom |
| 24 | - function __get ($prop) { |
|
| 24 | + function __get($prop) { |
|
| 25 | 25 | if ($prop == 'length') { |
| 26 | 26 | return $this->length; |
| 27 | 27 | } |
@@ -24,11 +24,9 @@ discard block |
||
| 24 | 24 | 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 | 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 | function count() { |