Verzeichnisstruktur phpBB-3.2.0


Veröffentlicht
06.01.2017

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: 09.10.2024, 12:56 - Dateigröße: 3.18 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 = array();
022      protected $noMatchRegexps = array();
023   
024      /**
025       * Constructor.
026       *
027       * @param \Iterator $iterator        The Iterator to filter
028       * @param array     $matchPatterns   An array of patterns that need to match
029       * @param array     $noMatchPatterns An array of patterns that need to not match
030       */
031      public function __construct(\Iterator $iterator, array $matchPatterns, array $noMatchPatterns)
032      {
033          foreach ($matchPatterns as $pattern) {
034              $this->matchRegexps[] = $this->toRegex($pattern);
035          }
036   
037          foreach ($noMatchPatterns as $pattern) {
038              $this->noMatchRegexps[] = $this->toRegex($pattern);
039          }
040   
041          parent::__construct($iterator);
042      }
043   
044      /**
045       * Checks whether the string is accepted by the regex filters.
046       *
047       * If there is no regexps defined in the class, this method will accept the string.
048       * Such case can be handled by child classes before calling the method if they want to
049       * apply a different behavior.
050       *
051       * @param string $string The string to be matched against filters
052       *
053       * @return bool
054       */
055      protected function isAccepted($string)
056      {
057          // should at least not match one rule to exclude
058          foreach ($this->noMatchRegexps as $regex) {
059              if (preg_match($regex, $string)) {
060                  return false;
061              }
062          }
063   
064          // should at least match one rule
065          if ($this->matchRegexps) {
066              foreach ($this->matchRegexps as $regex) {
067                  if (preg_match($regex, $string)) {
068                      return true;
069                  }
070              }
071   
072              return false;
073          }
074   
075          // If there is no match rules, the file is accepted
076          return true;
077      }
078   
079      /**
080       * Checks whether the string is a regex.
081       *
082       * @param string $str
083       *
084       * @return bool Whether the given string is a regex
085       */
086      protected function isRegex($str)
087      {
088          if (preg_match('/^(.{3,}?)[imsxuADU]*$/', $str, $m)) {
089              $start = substr($m[1], 0, 1);
090              $end = substr($m[1], -1);
091   
092              if ($start === $end) {
093                  return !preg_match('/[*?[:alnum:] \\\\]/', $start);
094              }
095   
096              foreach (array(array('{', '}'), array('(', ')'), array('[', ']'), array('<', '>')) as $delimiters) {
097                  if ($start === $delimiters[0] && $end === $delimiters[1]) {
098                      return true;
099                  }
100              }
101          }
102   
103          return false;
104      }
105   
106      /**
107       * Converts string into regexp.
108       *
109       * @param string $str Pattern
110       *
111       * @return string regexp corresponding to a given string
112       */
113      abstract protected function toRegex($str);
114  }
115