PluginProbe
ManageWP Worker / 4.9.25
ManageWP Worker v4.9.25
4.9.38 4.9.37 4.9.36 4.9.35 4.9.34 3.8.7 3.8.8 3.9.0 3.9.1 3.9.10 3.9.11 3.9.12 3.9.13 3.9.14 3.9.15 3.9.16 3.9.17 3.9.18 3.9.19 3.9.2 3.9.20 3.9.21 3.9.22 3.9.23 3.9.24 All 73 releases
worker / src / Symfony / Filesystem / FilesystemIterator.php

FilesystemIterator.php in ManageWP Worker 4.9.25, at src/Symfony/Filesystem/FilesystemIterator.php

126 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Poor man's PHP 5.2 port of FilesystemIterator from PHP 5.3.
5 *
6 * WARNING: Do not use this one in PHP >=5.3, use native FilesystemIterator instead.
7 *
8 * @see http://php.net/manual/en/class.filesystemiterator.php
9 * @see https://github.com/php/php-src/blob/master/ext/spl/spl_directory.c
10 */
11 class Symfony_Filesystem_FilesystemIterator extends DirectoryIterator implements SeekableIterator
12 {
13 const CURRENT_AS_PATHNAME = 32;
14 const CURRENT_AS_FILEINFO = 0;
15 const CURRENT_AS_SELF = 16;
16 const CURRENT_MODE_MASK = 240;
17 const KEY_AS_PATHNAME = 0;
18 const KEY_AS_FILENAME = 256;
19 const FOLLOW_SYMLINKS = 512;
20 const KEY_MODE_MASK = 3840;
21 const NEW_CURRENT_AND_KEY = 256;
22 const SKIP_DOTS = 4096;
23 const UNIX_PATHS = 8192;
24
25 private $flags;
26
27 /**
28 * @param string $path
29 * @param int $flags
30 */
31 public function __construct($path, $flags = null)
32 {
33 if ($flags === null) {
34 $flags = self::KEY_AS_PATHNAME | self::CURRENT_AS_FILEINFO | self::SKIP_DOTS;
35 }
36 $this->flags = $flags;
37 parent::__construct($path);
38 }
39
40 /**
41 * @return mixed
42 */
43 public function current()
44 {
45 if ($this->flags & self::CURRENT_AS_PATHNAME) {
46 return $this->getPathname();
47 } elseif ($this->flags & self::CURRENT_AS_SELF) {
48 return $this;
49 } else {
50 return $this->getFileInfo();
51 }
52 }
53
54 /**
55 * @return string
56 */
57 public function key()
58 {
59 if ($this->flags & self::KEY_AS_FILENAME) {
60 return $this->getFilename();
61 }
62
63 return $this->getPathname();
64 }
65
66 /**
67 */
68 public function next()
69 {
70 do {
71 parent::next();
72 } while ($this->isDot());
73 }
74
75 /**
76 */
77 public function rewind()
78 {
79 parent::rewind();
80 while ($this->isDot()) {
81 $this->next();
82 }
83 }
84
85 /**
86 * @param int $flags
87 */
88 public function setFlags($flags)
89 {
90 $this->flags = $flags;
91 }
92
93 /**
94 * @return int
95 */
96 public function getFlags()
97 {
98 return $this->flags;
99 }
100
101 /**
102 * Overridden to not crash PHP 5.2, because DirectoryIterator::seek was added in 5.3.
103 *
104 * @link http://lxr.php.net/xref/PHP_5_3/ext/spl/spl_directory.c#807
105 */
106 public function seek($position)
107 {
108 if (is_callable(array('parent', 'seek'))) {
109 parent::seek($position);
110
111 return;
112 }
113
114 if ($this->key() > $position) {
115 $this->rewind();
116 }
117
118 while ($this->key() < $position) {
119 if (!$this->valid()) {
120 return;
121 }
122 $this->next();
123 }
124 }
125 }
126