Verzeichnisstruktur phpBB-3.3.15


Veröffentlicht
28.08.2024

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

AbstractXSLSupportCheck.php

Zuletzt modifiziert: 02.04.2025, 15:04 - Dateigröße: 3.12 KiB


001  <?php declare(strict_types=1);
002   
003  /**
004  * @package   s9e\TextFormatter
005  * @copyright Copyright (c) 2010-2022 The s9e authors
006  * @license   http://www.opensource.org/licenses/mit-license.php The MIT License
007  */
008  namespace s9e\TextFormatter\Configurator\TemplateChecks;
009   
010  use DOMElement;
011  use DOMXPath;
012  use RuntimeException;
013  use s9e\TextFormatter\Configurator\Helpers\AVTHelper;
014  use s9e\TextFormatter\Configurator\Items\Tag;
015  use s9e\TextFormatter\Configurator\TemplateCheck;
016   
017  abstract class AbstractXSLSupportCheck extends TemplateCheck
018  {
019      /**
020      * @var string[] List of supported XSL elements (local name only)
021      */
022      protected $supportedElements = [];
023   
024      /**
025      * @var string[] List of supported XPath functions
026      */
027      protected $supportedFunctions = [];
028   
029      /**
030      * @var string[] List of supported XPath operators
031      */
032      protected $supportedOperators = ['and', 'div', 'mod', 'or'];
033   
034      /**
035      * Check for elements not supported by the PHP renderer
036      *
037      * @param DOMElement $template <xsl:template/> node
038      * @param Tag        $tag      Tag this template belongs to
039      */
040      public function check(DOMElement $template, Tag $tag): void
041      {
042          $this->checkXslElements($template);
043          $this->checkXPathExpressions($template);
044      }
045   
046      /**
047      * Check given XPath expression
048      */
049      protected function checkXPathExpression(string $expr): void
050      {
051          preg_match_all('("[^"]*+"|\'[^\']*+\'|((?:[a-z]++-)*+[a-z]++)(?=\\s*\\())', $expr, $m);
052          foreach (array_filter($m[1]) as $funcName)
053          {
054              if (!in_array($funcName, $this->supportedFunctions, true)
055               && !in_array($funcName, $this->supportedOperators, true))
056              {
057                  throw new RuntimeException('XPath function ' . $funcName . '() is not supported');
058              }
059          }
060      }
061   
062      /**
063      * Check all XPath expressions in given template
064      */
065      protected function checkXPathExpressions(DOMElement $template): void
066      {
067          foreach ($this->getXPathExpressions($template) as $expr)
068          {
069              $this->checkXPathExpression($expr);
070          }
071      }
072   
073      /**
074      * Check all XSL elements in given template
075      */
076      protected function checkXslElements(DOMElement $template): void
077      {
078          $xpath = new DOMXPath($template->ownerDocument);
079          $nodes = $xpath->query('/xsl:template//xsl:*');
080          foreach ($nodes as $node)
081          {
082              if (!in_array($node->localName, $this->supportedElements, true))
083              {
084                  throw new RuntimeException('xsl:' . $node->localName . ' elements are not supported');
085              }
086   
087              $methodName = 'checkXsl' . str_replace(' ', '', ucwords(str_replace('-', ' ', $node->localName))) . 'Element';
088              if (method_exists($this, $methodName))
089              {
090                  $this->$methodName($node);
091              }
092          }
093      }
094   
095      /**
096      * Return all XPath expressions in given template
097      */
098      protected function getXPathExpressions(DOMElement $template): array
099      {
100          $exprs = [];
101          $xpath = new DOMXPath($template->ownerDocument);
102   
103          $query = '//xsl:*/@name | //*[namespace-uri() != "' . self::XMLNS_XSL . '"]/@*[contains(., "{")]';
104          foreach ($xpath->query($query) as $attribute)
105          {
106              foreach (AVTHelper::parse($attribute->value) as [$type, $content])
107              {
108                  if ($type === 'expression')
109                  {
110                      $exprs[] = $content;
111                  }
112              }
113          }
114   
115          $query = '//xsl:*/@select | //xsl:*/@test';
116          foreach ($xpath->query($query) as $attribute)
117          {
118              $exprs[] = $attribute->value;
119          }
120   
121          return $exprs;
122      }
123  }