[ Index ] |
PHP Cross Reference of phpBB-3.3.12-deutsch |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * @package s9e\TextFormatter 5 * @copyright Copyright (c) 2010-2022 The s9e authors 6 * @license http://www.opensource.org/licenses/mit-license.php The MIT License 7 */ 8 namespace s9e\TextFormatter\Configurator\TemplateNormalizations; 9 10 use DOMElement; 11 use DOMNode; 12 13 abstract class AbstractChooseOptimization extends AbstractNormalization 14 { 15 /** 16 * @var DOMElement Current xsl:choose element 17 */ 18 protected $choose; 19 20 /** 21 * {@inheritdoc} 22 */ 23 protected $queries = ['//xsl:choose']; 24 25 /** 26 * Retrieve a list of attributes from given element 27 * 28 * @return array NamespaceURI#nodeName as keys, attribute values as values 29 */ 30 protected function getAttributes(DOMElement $element) 31 { 32 $attributes = array(); 33 foreach ($element->attributes as $attribute) 34 { 35 $key = $attribute->namespaceURI . '#' . $attribute->nodeName; 36 $attributes[$key] = $attribute->nodeValue; 37 } 38 39 return $attributes; 40 } 41 42 /** 43 * Return a list the xsl:when and xsl:otherwise children of current xsl:choose element 44 * 45 * @return DOMElement[] 46 */ 47 protected function getBranches() 48 { 49 $query = 'xsl:when|xsl:otherwise'; 50 51 return $this->xpath($query, $this->choose); 52 } 53 54 /** 55 * Test whether current xsl:choose element has an xsl:otherwise child 56 * 57 * @return bool 58 */ 59 protected function hasOtherwise() 60 { 61 return (bool) $this->xpath->evaluate('count(xsl:otherwise)', $this->choose); 62 } 63 64 /** 65 * Test whether current xsl:choose element has no content besides xsl:when and xsl:otherwise 66 * 67 * @return bool 68 */ 69 protected function isEmpty() 70 { 71 $query = 'count(xsl:when/node() | xsl:otherwise/node())'; 72 73 return !$this->xpath->evaluate($query, $this->choose); 74 } 75 76 /** 77 * Test whether two nodes are identical 78 * 79 * ext/dom does not support isEqualNode() from DOM Level 3 so this is a makeshift replacement. 80 * Unlike the DOM 3 function, attributes order matters 81 * 82 * @param DOMNode $node1 83 * @param DOMNode $node2 84 * @return bool 85 */ 86 protected function isEqualNode(DOMNode $node1, DOMNode $node2) 87 { 88 return ($node1->ownerDocument->saveXML($node1) === $node2->ownerDocument->saveXML($node2)); 89 } 90 91 /** 92 * Test whether two elements have the same start tag 93 * 94 * @param DOMElement $el1 95 * @param DOMElement $el2 96 * @return bool 97 */ 98 protected function isEqualTag(DOMElement $el1, DOMElement $el2) 99 { 100 return ($el1->namespaceURI === $el2->namespaceURI && $el1->nodeName === $el2->nodeName && $this->getAttributes($el1) === $this->getAttributes($el2)); 101 } 102 103 /** 104 * {@inheritdoc} 105 */ 106 protected function normalizeElement(DOMElement $element) 107 { 108 $this->choose = $element; 109 $this->optimizeChoose(); 110 } 111 112 /** 113 * Optimize the current xsl:choose element 114 * 115 * @return void 116 */ 117 abstract protected function optimizeChoose(); 118 119 /** 120 * {@inheritdoc} 121 */ 122 protected function reset() 123 { 124 $this->choose = null; 125 parent::reset(); 126 } 127 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Jun 23 12:25:44 2024 | Cross-referenced by PHPXref 0.7.1 |