Verzeichnisstruktur phpBB-3.1.0


Veröffentlicht
27.10.2014

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: 09.10.2024, 12:58 - Dateigröße: 2.70 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 ResourceInterface, \Serializable
020  {
021      private $resource;
022      private $pattern;
023   
024      /**
025       * Constructor.
026       *
027       * @param string $resource The file path to the resource
028       * @param string $pattern  A pattern to restrict monitored files
029       */
030      public function __construct($resource, $pattern = null)
031      {
032          $this->resource = $resource;
033          $this->pattern = $pattern;
034      }
035   
036      /**
037       * Returns a string representation of the Resource.
038       *
039       * @return string A string representation of the Resource
040       */
041      public function __toString()
042      {
043          return (string) $this->resource;
044      }
045   
046      /**
047       * Returns the resource tied to this Resource.
048       *
049       * @return mixed The resource
050       */
051      public function getResource()
052      {
053          return $this->resource;
054      }
055   
056      public function getPattern()
057      {
058          return $this->pattern;
059      }
060   
061      /**
062       * Returns true if the resource has not been updated since the given timestamp.
063       *
064       * @param int     $timestamp The last time the resource was loaded
065       *
066       * @return bool    true if the resource has not been updated, false otherwise
067       */
068      public function isFresh($timestamp)
069      {
070          if (!is_dir($this->resource)) {
071              return false;
072          }
073   
074          $newestMTime = filemtime($this->resource);
075          foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->resource), \RecursiveIteratorIterator::SELF_FIRST) as $file) {
076              // if regex filtering is enabled only check matching files
077              if ($this->pattern && $file->isFile() && !preg_match($this->pattern, $file->getBasename())) {
078                  continue;
079              }
080   
081              // always monitor directories for changes, except the .. entries
082              // (otherwise deleted files wouldn't get detected)
083              if ($file->isDir() && '/..' === substr($file, -3)) {
084                  continue;
085              }
086   
087              $newestMTime = max($file->getMTime(), $newestMTime);
088          }
089   
090          return $newestMTime < $timestamp;
091      }
092   
093      public function serialize()
094      {
095          return serialize(array($this->resource, $this->pattern));
096      }
097   
098      public function unserialize($serialized)
099      {
100          list($this->resource, $this->pattern) = unserialize($serialized);
101      }
102  }
103