[ Index ]

PHP Cross Reference of phpBB-3.3.5-deutsch

title

Body

[close]

/vendor/s9e/text-formatter/src/Configurator/TemplateNormalizations/ -> AbstractChooseOptimization.php (source)

   1  <?php
   2  
   3  /**
   4  * @package   s9e\TextFormatter
   5  * @copyright Copyright (c) 2010-2021 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  }


Generated: Mon Oct 4 17:42:11 2021 Cross-referenced by PHPXref 0.7.1