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

MultiplePcreFilterIterator.php

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


001  <?php
002   
003  /*
004   * This file is part of the Symfony package.
005   *
006   * (c) Fabien Potencier <fabien@symfony.com>
007   *
008   * For the full copyright and license information, please view the LICENSE
009   * file that was distributed with this source code.
010   */
011   
012  namespace Symfony\Component\Finder\Iterator;
013   
014  /**
015   * MultiplePcreFilterIterator filters files using patterns (regexps, globs or strings).
016   *
017   * @author Fabien Potencier <fabien@symfony.com>
018   */
019  abstract class MultiplePcreFilterIterator extends FilterIterator
020  {
021      protected $matchRegexps = [];
022      protected $noMatchRegexps = [];
023   
024      /**
025       * @param \Iterator $iterator        The Iterator to filter
026       * @param array     $matchPatterns   An array of patterns that need to match
027       * @param array     $noMatchPatterns An array of patterns that need to not match
028       */
029      public function __construct(\Iterator $iterator, array $matchPatterns, array $noMatchPatterns)
030      {
031          foreach ($matchPatterns as $pattern) {
032              $this->matchRegexps[] = $this->toRegex($pattern);
033          }
034   
035          foreach ($noMatchPatterns as $pattern) {
036              $this->noMatchRegexps[] = $this->toRegex($pattern);
037          }
038   
039          parent::__construct($iterator);
040      }
041   
042      /**
043       * Checks whether the string is accepted by the regex filters.
044       *
045       * If there is no regexps defined in the class, this method will accept the string.
046       * Such case can be handled by child classes before calling the method if they want to
047       * apply a different behavior.
048       *
049       * @param string $string The string to be matched against filters
050       *
051       * @return bool
052       */
053      protected function isAccepted($string)
054      {
055          // should at least not match one rule to exclude
056          foreach ($this->noMatchRegexps as $regex) {
057              if (preg_match($regex, $string)) {
058                  return false;
059              }
060          }
061   
062          // should at least match one rule
063          if ($this->matchRegexps) {
064              foreach ($this->matchRegexps as $regex) {
065                  if (preg_match($regex, $string)) {
066                      return true;
067                  }
068              }
069   
070              return false;
071          }
072   
073          // If there is no match rules, the file is accepted
074          return true;
075      }
076   
077      /**
078       * Checks whether the string is a regex.
079       *
080       * @param string $str
081       *
082       * @return bool Whether the given string is a regex
083       */
084      protected function isRegex($str)
085      {
086          if (preg_match('/^(.{3,}?)[imsxuADU]*$/', $str, $m)) {
087              $start = substr($m[1], 0, 1);
088              $end = substr($m[1], -1);
089   
090              if ($start === $end) {
091                  return !preg_match('/[*?[:alnum:] \\\\]/', $start);
092              }
093   
094              foreach ([['{', '}'], ['(', ')'], ['[', ']'], ['<', '>']] as $delimiters) {
095                  if ($start === $delimiters[0] && $end === $delimiters[1]) {
096                      return true;
097                  }
098              }
099          }
100   
101          return false;
102      }
103   
104      /**
105       * Converts string into regexp.
106       *
107       * @param string $str Pattern
108       *
109       * @return string regexp corresponding to a given string
110       */
111      abstract protected function toRegex($str);
112  }
113