[ Index ]

PHP Cross Reference of phpBB-3.3.3-deutsch

title

Body

[close]

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

   1  <?php
   2  
   3  /**
   4  * @package   s9e\TextFormatter
   5  * @copyright Copyright (c) 2010-2020 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  
  12  /**
  13  * Remove unnecessary <xsl:if> tests around <xsl:value-of>
  14  *
  15  * NOTE: should be performed before attributes are inlined for maximum effect
  16  */
  17  class OptimizeConditionalValueOf extends AbstractNormalization
  18  {
  19      /**
  20      * {@inheritdoc}
  21      */
  22      protected $queries = ['//xsl:if[count(descendant::node()) = 1]/xsl:value-of'];
  23  
  24      /**
  25      * {@inheritdoc}
  26      */
  27  	protected function normalizeElement(DOMElement $element)
  28      {
  29          $if     = $element->parentNode;
  30          $test   = $if->getAttribute('test');
  31          $select = $element->getAttribute('select');
  32  
  33          // Ensure that the expressions match, and that they select one single attribute
  34          if ($select !== $test || !preg_match('#^@[-\\w]+$#D', $select))
  35          {
  36              return;
  37          }
  38  
  39          // Replace the xsl:if element with the xsl:value-of element
  40          $if->parentNode->replaceChild($if->removeChild($element), $if);
  41      }
  42  }


Generated: Sun Feb 14 20:08:31 2021 Cross-referenced by PHPXref 0.7.1