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

DirectoryResource.php

Zuletzt modifiziert: 02.04.2025, 15:03 - Dateigröße: 3.10 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  /**
015   * DirectoryResource represents a resources stored in a subdirectory tree.
016   *
017   * @author Fabien Potencier <fabien@symfony.com>
018   */
019  class DirectoryResource implements SelfCheckingResourceInterface, \Serializable
020  {
021      private $resource;
022      private $pattern;
023   
024      /**
025       * @param string      $resource The file path to the resource
026       * @param string|null $pattern  A pattern to restrict monitored files
027       *
028       * @throws \InvalidArgumentException
029       */
030      public function __construct($resource, $pattern = null)
031      {
032          $this->resource = realpath($resource) ?: (file_exists($resource) ? $resource : false);
033          $this->pattern = $pattern;
034   
035          if (false === $this->resource || !is_dir($this->resource)) {
036              throw new \InvalidArgumentException(sprintf('The directory "%s" does not exist.', $resource));
037          }
038      }
039   
040      /**
041       * {@inheritdoc}
042       */
043      public function __toString()
044      {
045          return md5(serialize([$this->resource, $this->pattern]));
046      }
047   
048      /**
049       * @return string The file path to the resource
050       */
051      public function getResource()
052      {
053          return $this->resource;
054      }
055   
056      /**
057       * Returns the pattern to restrict monitored files.
058       *
059       * @return string|null
060       */
061      public function getPattern()
062      {
063          return $this->pattern;
064      }
065   
066      /**
067       * {@inheritdoc}
068       */
069      public function isFresh($timestamp)
070      {
071          if (!is_dir($this->resource)) {
072              return false;
073          }
074   
075          if ($timestamp < filemtime($this->resource)) {
076              return false;
077          }
078   
079          foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->resource), \RecursiveIteratorIterator::SELF_FIRST) as $file) {
080              // if regex filtering is enabled only check matching files
081              if ($this->pattern && $file->isFile() && !preg_match($this->pattern, $file->getBasename())) {
082                  continue;
083              }
084   
085              // always monitor directories for changes, except the .. entries
086              // (otherwise deleted files wouldn't get detected)
087              if ($file->isDir() && '/..' === substr($file, -3)) {
088                  continue;
089              }
090   
091              // for broken links
092              try {
093                  $fileMTime = $file->getMTime();
094              } catch (\RuntimeException $e) {
095                  continue;
096              }
097   
098              // early return if a file's mtime exceeds the passed timestamp
099              if ($timestamp < $fileMTime) {
100                  return false;
101              }
102          }
103   
104          return true;
105      }
106   
107      /**
108       * @internal
109       */
110      public function serialize()
111      {
112          return serialize([$this->resource, $this->pattern]);
113      }
114   
115      /**
116       * @internal
117       */
118      public function unserialize($serialized)
119      {
120          list($this->resource, $this->pattern) = unserialize($serialized);
121      }
122  }
123