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

Math.php

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


001  <?php
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\RendererGenerators\PHP\XPathConvertor\Convertors;
009   
010  class Math extends AbstractConvertor
011  {
012      /**
013      * {@inheritdoc}
014      */
015      public function getMatchers(): array
016      {
017          $number = '((?&Attribute)|(?&BooleanFunction)|(?&BooleanSubExpr)|(?&MathSubExpr)|(?&Number)|(?&Parameter))';
018          $math   = '((?&Math)|' . substr($number, 1);
019   
020          return [
021              'Math:Addition'       => $number . ' \\+ ' . $math,
022              'Math:Division'       => $number . ' div ' . $math,
023              'Math:MathSubExpr'    => '\\( ((?&Math)) \\)',
024              'Math:Multiplication' => $number . ' \\* ' . $math,
025              'Math:Substraction'   => $number . ' - ' . $math
026          ];
027      }
028   
029      /**
030      * Convert an addition
031      *
032      * @param  string $expr1
033      * @param  string $expr2
034      * @return string
035      */
036      public function parseAddition($expr1, $expr2)
037      {
038          return $this->convertOperation($expr1, '+', $expr2);
039      }
040   
041      /**
042      * Convert a division
043      *
044      * @param  string $expr1
045      * @param  string $expr2
046      * @return string
047      */
048      public function parseDivision($expr1, $expr2)
049      {
050          return $this->convertOperation($expr1, '/', $expr2);
051      }
052   
053      /**
054      * Convert a math subexpression
055      *
056      * @param  string $expr
057      * @return string
058      */
059      public function parseMathSubExpr($expr)
060      {
061          return '(' . $this->recurse($expr) . ')';
062      }
063   
064      /**
065      * Convert a multiplication
066      *
067      * @param  string $expr1
068      * @param  string $expr2
069      * @return string
070      */
071      public function parseMultiplication($expr1, $expr2)
072      {
073          return $this->convertOperation($expr1, '*', $expr2);
074      }
075   
076      /**
077      * Convert a substraction
078      *
079      * @param  string $expr1
080      * @param  string $expr2
081      * @return string
082      */
083      public function parseSubstraction($expr1, $expr2)
084      {
085          return $this->convertOperation($expr1, '-', $expr2);
086      }
087   
088      /**
089      * Convert an operation
090      *
091      * @param  string $expr1
092      * @param  string $operator
093      * @param  string $expr2
094      * @return string
095      */
096      protected function convertOperation($expr1, $operator, $expr2)
097      {
098          $expr1 = $this->recurse($expr1);
099          $expr2 = $this->recurse($expr2);
100   
101          // Prevent two consecutive minus signs to be interpreted as a post-decrement operator
102          if ($operator === '-' && $expr2[0] === '-')
103          {
104              $operator .= ' ';
105          }
106   
107          return $expr1 . $operator . $expr2;
108      }
109  }