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

RecursiveDirectoryIterator.php

Zuletzt modifiziert: 09.10.2024, 12:56 - Dateigröße: 4.50 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  use Symfony\Component\Finder\Exception\AccessDeniedException;
 015  use Symfony\Component\Finder\SplFileInfo;
 016   
 017  /**
 018   * Extends the \RecursiveDirectoryIterator to support relative paths.
 019   *
 020   * @author Victor Berchet <victor@suumit.com>
 021   */
 022  class RecursiveDirectoryIterator extends \RecursiveDirectoryIterator
 023  {
 024      /**
 025       * @var bool
 026       */
 027      private $ignoreUnreadableDirs;
 028   
 029      /**
 030       * @var bool
 031       */
 032      private $rewindable;
 033   
 034      // these 3 properties take part of the performance optimization to avoid redoing the same work in all iterations
 035      private $rootPath;
 036      private $subPath;
 037      private $directorySeparator = '/';
 038   
 039      /**
 040       * Constructor.
 041       *
 042       * @param string $path
 043       * @param int    $flags
 044       * @param bool   $ignoreUnreadableDirs
 045       *
 046       * @throws \RuntimeException
 047       */
 048      public function __construct($path, $flags, $ignoreUnreadableDirs = false)
 049      {
 050          if ($flags & (self::CURRENT_AS_PATHNAME | self::CURRENT_AS_SELF)) {
 051              throw new \RuntimeException('This iterator only support returning current as fileinfo.');
 052          }
 053   
 054          parent::__construct($path, $flags);
 055          $this->ignoreUnreadableDirs = $ignoreUnreadableDirs;
 056          $this->rootPath = (string) $path;
 057          if ('/' !== DIRECTORY_SEPARATOR && !($flags & self::UNIX_PATHS)) {
 058              $this->directorySeparator = DIRECTORY_SEPARATOR;
 059          }
 060      }
 061   
 062      /**
 063       * Return an instance of SplFileInfo with support for relative paths.
 064       *
 065       * @return SplFileInfo File information
 066       */
 067      public function current()
 068      {
 069          // the logic here avoids redoing the same work in all iterations
 070   
 071          if (null === $subPathname = $this->subPath) {
 072              $subPathname = $this->subPath = (string) $this->getSubPath();
 073          }
 074          if ('' !== $subPathname) {
 075              $subPathname .= $this->directorySeparator;
 076          }
 077          $subPathname .= $this->getFilename();
 078   
 079          return new SplFileInfo($this->rootPath.$this->directorySeparator.$subPathname, $this->subPath, $subPathname);
 080      }
 081   
 082      /**
 083       * @return \RecursiveIterator
 084       *
 085       * @throws AccessDeniedException
 086       */
 087      public function getChildren()
 088      {
 089          try {
 090              $children = parent::getChildren();
 091   
 092              if ($children instanceof self) {
 093                  // parent method will call the constructor with default arguments, so unreadable dirs won't be ignored anymore
 094                  $children->ignoreUnreadableDirs = $this->ignoreUnreadableDirs;
 095   
 096                  // performance optimization to avoid redoing the same work in all children
 097                  $children->rewindable = &$this->rewindable;
 098                  $children->rootPath = $this->rootPath;
 099              }
 100   
 101              return $children;
 102          } catch (\UnexpectedValueException $e) {
 103              if ($this->ignoreUnreadableDirs) {
 104                  // If directory is unreadable and finder is set to ignore it, a fake empty content is returned.
 105                  return new \RecursiveArrayIterator(array());
 106              } else {
 107                  throw new AccessDeniedException($e->getMessage(), $e->getCode(), $e);
 108              }
 109          }
 110      }
 111   
 112      /**
 113       * Do nothing for non rewindable stream.
 114       */
 115      public function rewind()
 116      {
 117          if (false === $this->isRewindable()) {
 118              return;
 119          }
 120   
 121          // @see https://bugs.php.net/68557
 122          if (PHP_VERSION_ID < 50523 || PHP_VERSION_ID >= 50600 && PHP_VERSION_ID < 50607) {
 123              parent::next();
 124          }
 125   
 126          parent::rewind();
 127      }
 128   
 129      /**
 130       * Checks if the stream is rewindable.
 131       *
 132       * @return bool true when the stream is rewindable, false otherwise
 133       */
 134      public function isRewindable()
 135      {
 136          if (null !== $this->rewindable) {
 137              return $this->rewindable;
 138          }
 139   
 140          // workaround for an HHVM bug, should be removed when https://github.com/facebook/hhvm/issues/7281 is fixed
 141          if ('' === $this->getPath()) {
 142              return $this->rewindable = false;
 143          }
 144   
 145          if (false !== $stream = @opendir($this->getPath())) {
 146              $infos = stream_get_meta_data($stream);
 147              closedir($stream);
 148   
 149              if ($infos['seekable']) {
 150                  return $this->rewindable = true;
 151              }
 152          }
 153   
 154          return $this->rewindable = false;
 155      }
 156  }
 157