[ Index ]

PHP Cross Reference of phpBB-3.3.14-deutsch

title

Body

[close]

/vendor/s9e/text-formatter/src/Configurator/TemplateChecks/ -> DisallowUnsupportedXSL.php (source)

   1  <?php declare(strict_types=1);
   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\TemplateChecks;
   9  
  10  use DOMElement;
  11  use RuntimeException;
  12  
  13  class DisallowUnsupportedXSL extends AbstractXSLSupportCheck
  14  {
  15      protected $supportedElements = ['apply-templates', 'attribute', 'choose', 'comment', 'copy-of', 'element', 'for-each', 'if', 'number', 'otherwise', 'processing-instruction', 'sort', 'text', 'value-of', 'variable', 'when'];
  16  
  17      protected $supportedFunctions = ['boolean', 'ceiling', 'concat', 'contains', 'count', 'current', 'document', 'element-available', 'false', 'floor', 'format-number', 'function-available', 'generate-id', 'id', 'key', 'lang', 'last', 'local-name', 'name', 'namespace-uri', 'normalize-space', 'not', 'number', 'position', 'round', 'starts-with', 'string', 'string-length', 'substring', 'substring-after', 'substring-before', 'sum', 'system-property', 'translate', 'true', 'unparsed-entity-uri'];
  18  
  19  	protected function checkXslApplyTemplatesElement(DOMElement $applyTemplates): void
  20      {
  21          if ($applyTemplates->hasAttribute('mode'))
  22          {
  23              throw new RuntimeException('xsl:apply-templates elements do not support the mode attribute');
  24          }
  25      }
  26  
  27  	protected function checkXslCopyOfElement(DOMElement $copyOf): void
  28      {
  29          $this->requireAttribute($copyOf, 'select');
  30      }
  31  
  32  	protected function checkXslAttributeElement(DOMElement $attribute): void
  33      {
  34          $this->requireAttribute($attribute, 'name');
  35  
  36          $attrName = $attribute->getAttribute('name');
  37          if (!preg_match('(^(?:\\{[^\\}]++\\}|[-.\\pL])++$)Du', $attrName))
  38          {
  39              throw new RuntimeException("Unsupported xsl:attribute name '" . $attrName . "'");
  40          }
  41      }
  42  
  43  	protected function checkXslElementElement(DOMElement $element): void
  44      {
  45          $this->requireAttribute($element, 'name');
  46  
  47          $elName = $element->getAttribute('name');
  48          if (!preg_match('(^(?:\\{[^\\}]++\\}|[-.\\pL])++(?::(?:\\{[^\\}]++\\}|[-.\\pL])++)?$)Du', $elName))
  49          {
  50              throw new RuntimeException("Unsupported xsl:element name '" . $elName . "'");
  51          }
  52      }
  53  
  54  	protected function checkXslIfElement(DOMElement $if): void
  55      {
  56          $this->requireAttribute($if, 'test');
  57      }
  58  
  59  	protected function checkXslValueOfElement(DOMElement $valueOf): void
  60      {
  61          $this->requireAttribute($valueOf, 'select');
  62      }
  63  
  64  	protected function checkXslVariableElement(DOMElement $variable): void
  65      {
  66          $this->requireAttribute($variable, 'name');
  67      }
  68  
  69  	protected function checkXslWhenElement(DOMElement $when): void
  70      {
  71          $this->requireAttribute($when, 'test');
  72      }
  73  
  74  	protected function requireAttribute(DOMElement $element, string $attrName)
  75      {
  76          if (!$element->hasAttribute($attrName))
  77          {
  78              throw new RuntimeException('xsl:' . $element->localName . ' elements require a ' . $attrName . ' attribute');
  79          }
  80      }
  81  }


Generated: Mon Nov 25 19:05:08 2024 Cross-referenced by PHPXref 0.7.1