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. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
Glob.php
001 <?php
002 /**
003 * Zend Framework (http://framework.zend.com/)
004 *
005 * @link http://github.com/zendframework/zf2 for the canonical source repository
006 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
007 * @license http://framework.zend.com/license/new-bsd New BSD License
008 */
009
010 namespace Zend\Stdlib;
011
012 /**
013 * Wrapper for glob with fallback if GLOB_BRACE is not available.
014 */
015 abstract class Glob
016 {
017 /**#@+
018 * Glob constants.
019 */
020 const GLOB_MARK = 0x01;
021 const GLOB_NOSORT = 0x02;
022 const GLOB_NOCHECK = 0x04;
023 const GLOB_NOESCAPE = 0x08;
024 const GLOB_BRACE = 0x10;
025 const GLOB_ONLYDIR = 0x20;
026 const GLOB_ERR = 0x40;
027 /**#@-*/
028
029 /**
030 * Find pathnames matching a pattern.
031 *
032 * @see http://docs.php.net/glob
033 * @param string $pattern
034 * @param int $flags
035 * @param bool $forceFallback
036 * @return array
037 * @throws Exception\RuntimeException
038 */
039 public static function glob($pattern, $flags = 0, $forceFallback = false)
040 {
041 if (!defined('GLOB_BRACE') || $forceFallback) {
042 return static::fallbackGlob($pattern, $flags);
043 }
044
045 return static::systemGlob($pattern, $flags);
046 }
047
048 /**
049 * Use the glob function provided by the system.
050 *
051 * @param string $pattern
052 * @param int $flags
053 * @return array
054 * @throws Exception\RuntimeException
055 */
056 protected static function systemGlob($pattern, $flags)
057 {
058 if ($flags) {
059 $flagMap = array(
060 self::GLOB_MARK => GLOB_MARK,
061 self::GLOB_NOSORT => GLOB_NOSORT,
062 self::GLOB_NOCHECK => GLOB_NOCHECK,
063 self::GLOB_NOESCAPE => GLOB_NOESCAPE,
064 self::GLOB_BRACE => GLOB_BRACE,
065 self::GLOB_ONLYDIR => GLOB_ONLYDIR,
066 self::GLOB_ERR => GLOB_ERR,
067 );
068
069 $globFlags = 0;
070
071 foreach ($flagMap as $internalFlag => $globFlag) {
072 if ($flags & $internalFlag) {
073 $globFlags |= $globFlag;
074 }
075 }
076 } else {
077 $globFlags = 0;
078 }
079
080 ErrorHandler::start();
081 $res = glob($pattern, $globFlags);
082 $err = ErrorHandler::stop();
083 if ($res === false) {
084 throw new Exception\RuntimeException("glob('{$pattern}', {$globFlags}) failed", 0, $err);
085 }
086 return $res;
087 }
088
089 /**
090 * Expand braces manually, then use the system glob.
091 *
092 * @param string $pattern
093 * @param int $flags
094 * @return array
095 * @throws Exception\RuntimeException
096 */
097 protected static function fallbackGlob($pattern, $flags)
098 {
099 if (!$flags & self::GLOB_BRACE) {
100 return static::systemGlob($pattern, $flags);
101 }
102
103 $flags &= ~self::GLOB_BRACE;
104 $length = strlen($pattern);
105 $paths = array();
106
107 if ($flags & self::GLOB_NOESCAPE) {
108 $begin = strpos($pattern, '{');
109 } else {
110 $begin = 0;
111
112 while (true) {
113 if ($begin === $length) {
114 $begin = false;
115 break;
116 } elseif ($pattern[$begin] === '\\' && ($begin + 1) < $length) {
117 $begin++;
118 } elseif ($pattern[$begin] === '{') {
119 break;
120 }
121
122 $begin++;
123 }
124 }
125
126 if ($begin === false) {
127 return static::systemGlob($pattern, $flags);
128 }
129
130 $next = static::nextBraceSub($pattern, $begin + 1, $flags);
131
132 if ($next === null) {
133 return static::systemGlob($pattern, $flags);
134 }
135
136 $rest = $next;
137
138 while ($pattern[$rest] !== '}') {
139 $rest = static::nextBraceSub($pattern, $rest + 1, $flags);
140
141 if ($rest === null) {
142 return static::systemGlob($pattern, $flags);
143 }
144 }
145
146 $p = $begin + 1;
147
148 while (true) {
149 $subPattern = substr($pattern, 0, $begin)
150 . substr($pattern, $p, $next - $p)
151 . substr($pattern, $rest + 1);
152
153 $result = static::fallbackGlob($subPattern, $flags | self::GLOB_BRACE);
154
155 if ($result) {
156 $paths = array_merge($paths, $result);
157 }
158
159 if ($pattern[$next] === '}') {
160 break;
161 }
162
163 $p = $next + 1;
164 $next = static::nextBraceSub($pattern, $p, $flags);
165 }
166
167 return array_unique($paths);
168 }
169
170 /**
171 * Find the end of the sub-pattern in a brace expression.
172 *
173 * @param string $pattern
174 * @param int $begin
175 * @param int $flags
176 * @return int|null
177 */
178 protected static function nextBraceSub($pattern, $begin, $flags)
179 {
180 $length = strlen($pattern);
181 $depth = 0;
182 $current = $begin;
183
184 while ($current < $length) {
185 if (!$flags & self::GLOB_NOESCAPE && $pattern[$current] === '\\') {
186 if (++$current === $length) {
187 break;
188 }
189
190 $current++;
191 } else {
192 if (($pattern[$current] === '}' && $depth-- === 0) || ($pattern[$current] === ',' && $depth === 0)) {
193 break;
194 } elseif ($pattern[$current++] === '{') {
195 $depth++;
196 }
197 }
198 }
199
200 return ($current < $length ? $current : null);
201 }
202 }
203