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

GlobResource.php

Zuletzt modifiziert: 02.04.2025, 15:03 - Dateigröße: 4.77 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\Config\Resource;
013   
014  use Symfony\Component\Finder\Finder;
015  use Symfony\Component\Finder\Glob;
016   
017  /**
018   * GlobResource represents a set of resources stored on the filesystem.
019   *
020   * Only existence/removal is tracked (not mtimes.)
021   *
022   * @author Nicolas Grekas <p@tchwork.com>
023   */
024  class GlobResource implements \IteratorAggregate, SelfCheckingResourceInterface, \Serializable
025  {
026      private $prefix;
027      private $pattern;
028      private $recursive;
029      private $hash;
030   
031      /**
032       * @param string $prefix    A directory prefix
033       * @param string $pattern   A glob pattern
034       * @param bool   $recursive Whether directories should be scanned recursively or not
035       *
036       * @throws \InvalidArgumentException
037       */
038      public function __construct($prefix, $pattern, $recursive)
039      {
040          $this->prefix = realpath($prefix) ?: (file_exists($prefix) ? $prefix : false);
041          $this->pattern = $pattern;
042          $this->recursive = $recursive;
043   
044          if (false === $this->prefix) {
045              throw new \InvalidArgumentException(sprintf('The path "%s" does not exist.', $prefix));
046          }
047      }
048   
049      public function getPrefix()
050      {
051          return $this->prefix;
052      }
053   
054      /**
055       * {@inheritdoc}
056       */
057      public function __toString()
058      {
059          return 'glob.'.$this->prefix.$this->pattern.(int) $this->recursive;
060      }
061   
062      /**
063       * {@inheritdoc}
064       */
065      public function isFresh($timestamp)
066      {
067          $hash = $this->computeHash();
068   
069          if (null === $this->hash) {
070              $this->hash = $hash;
071          }
072   
073          return $this->hash === $hash;
074      }
075   
076      /**
077       * @internal
078       */
079      public function serialize()
080      {
081          if (null === $this->hash) {
082              $this->hash = $this->computeHash();
083          }
084   
085          return serialize([$this->prefix, $this->pattern, $this->recursive, $this->hash]);
086      }
087   
088      /**
089       * @internal
090       */
091      public function unserialize($serialized)
092      {
093          list($this->prefix, $this->pattern, $this->recursive, $this->hash) = unserialize($serialized);
094      }
095   
096      public function getIterator()
097      {
098          if (!file_exists($this->prefix) || (!$this->recursive && '' === $this->pattern)) {
099              return;
100          }
101   
102          if (0 !== strpos($this->prefix, 'phar://') && false === strpos($this->pattern, '/**/') && (\defined('GLOB_BRACE') || false === strpos($this->pattern, '{'))) {
103              $paths = glob($this->prefix.$this->pattern, \GLOB_NOSORT | (\defined('GLOB_BRACE') ? \GLOB_BRACE : 0));
104              sort($paths);
105              foreach ($paths as $path) {
106                  if ($this->recursive && is_dir($path)) {
107                      $files = iterator_to_array(new \RecursiveIteratorIterator(
108                          new \RecursiveCallbackFilterIterator(
109                              new \RecursiveDirectoryIterator($path, \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::FOLLOW_SYMLINKS),
110                              function (\SplFileInfo $file) { return '.' !== $file->getBasename()[0]; }
111                          ),
112                          \RecursiveIteratorIterator::LEAVES_ONLY
113                      ));
114                      uasort($files, function (\SplFileInfo $a, \SplFileInfo $b) {
115                          return (string) $a > (string) $b ? 1 : -1;
116                      });
117   
118                      foreach ($files as $path => $info) {
119                          if ($info->isFile()) {
120                              yield $path => $info;
121                          }
122                      }
123                  } elseif (is_file($path)) {
124                      yield $path => new \SplFileInfo($path);
125                  }
126              }
127   
128              return;
129          }
130   
131          if (!class_exists(Finder::class)) {
132              throw new \LogicException(sprintf('Extended glob pattern "%s" cannot be used as the Finder component is not installed.', $this->pattern));
133          }
134   
135          $finder = new Finder();
136          $regex = Glob::toRegex($this->pattern);
137          if ($this->recursive) {
138              $regex = substr_replace($regex, '(/|$)', -2, 1);
139          }
140   
141          $prefixLen = \strlen($this->prefix);
142          foreach ($finder->followLinks()->sortByName()->in($this->prefix) as $path => $info) {
143              if (preg_match($regex, substr('\\' === \DIRECTORY_SEPARATOR ? str_replace('\\', '/', $path) : $path, $prefixLen)) && $info->isFile()) {
144                  yield $path => $info;
145              }
146          }
147      }
148   
149      private function computeHash()
150      {
151          $hash = hash_init('md5');
152   
153          foreach ($this->getIterator() as $path => $info) {
154              hash_update($hash, $path."\n");
155          }
156   
157          return hash_final($hash);
158      }
159  }
160