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