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

ExcludeDirectoryFilterIterator.php

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


01  <?php
02   
03  /*
04   * This file is part of the Symfony package.
05   *
06   * (c) Fabien Potencier <fabien@symfony.com>
07   *
08   * For the full copyright and license information, please view the LICENSE
09   * file that was distributed with this source code.
10   */
11   
12  namespace Symfony\Component\Finder\Iterator;
13   
14  /**
15   * ExcludeDirectoryFilterIterator filters out directories.
16   *
17   * @author Fabien Potencier <fabien@symfony.com>
18   */
19  class ExcludeDirectoryFilterIterator extends FilterIterator implements \RecursiveIterator
20  {
21      private $iterator;
22      private $isRecursive;
23      private $excludedDirs = [];
24      private $excludedPattern;
25   
26      /**
27       * @param \Iterator $iterator    The Iterator to filter
28       * @param string[]  $directories An array of directories to exclude
29       */
30      public function __construct(\Iterator $iterator, array $directories)
31      {
32          $this->iterator = $iterator;
33          $this->isRecursive = $iterator instanceof \RecursiveIterator;
34          $patterns = [];
35          foreach ($directories as $directory) {
36              $directory = rtrim($directory, '/');
37              if (!$this->isRecursive || false !== strpos($directory, '/')) {
38                  $patterns[] = preg_quote($directory, '#');
39              } else {
40                  $this->excludedDirs[$directory] = true;
41              }
42          }
43          if ($patterns) {
44              $this->excludedPattern = '#(?:^|/)(?:'.implode('|', $patterns).')(?:/|$)#';
45          }
46   
47          parent::__construct($iterator);
48      }
49   
50      /**
51       * Filters the iterator values.
52       *
53       * @return bool True if the value should be kept, false otherwise
54       */
55      public function accept()
56      {
57          if ($this->isRecursive && isset($this->excludedDirs[$this->getFilename()]) && $this->isDir()) {
58              return false;
59          }
60   
61          if ($this->excludedPattern) {
62              $path = $this->isDir() ? $this->current()->getRelativePathname() : $this->current()->getRelativePath();
63              $path = str_replace('\\', '/', $path);
64   
65              return !preg_match($this->excludedPattern, $path);
66          }
67   
68          return true;
69      }
70   
71      public function hasChildren()
72      {
73          return $this->isRecursive && $this->iterator->hasChildren();
74      }
75   
76      public function getChildren()
77      {
78          $children = new self($this->iterator->getChildren(), []);
79          $children->excludedDirs = $this->excludedDirs;
80          $children->excludedPattern = $this->excludedPattern;
81   
82          return $children;
83      }
84  }
85