@@ -29,7 +29,7 @@ class RecursiveDirectoryIterator extends \RecursiveDirectoryIterator
29
29
/**
30
30
* @var bool
31
31
*/
32
- private $ rewindable ;
32
+ private $ ignoreFirstRewind = true ;
33
33
34
34
// these 3 properties take part of the performance optimization to avoid redoing the same work in all iterations
35
35
private $ rootPath ;
@@ -118,7 +118,6 @@ public function getChildren()
118
118
$ children ->ignoreUnreadableDirs = $ this ->ignoreUnreadableDirs ;
119
119
120
120
// performance optimization to avoid redoing the same work in all children
121
- $ children ->rewindable = &$ this ->rewindable ;
122
121
$ children ->rootPath = $ this ->rootPath ;
123
122
}
124
123
@@ -129,40 +128,30 @@ public function getChildren()
129
128
}
130
129
131
130
/**
132
- * Do nothing for non rewindable stream.
133
- *
134
131
* @return void
135
132
*/
136
133
#[\ReturnTypeWillChange]
137
- public function rewind ()
134
+ public function next ()
138
135
{
139
- if (false === $ this ->isRewindable ()) {
140
- return ;
141
- }
136
+ $ this ->ignoreFirstRewind = false ;
142
137
143
- parent ::rewind ();
138
+ parent ::next ();
144
139
}
145
140
146
141
/**
147
- * Checks if the stream is rewindable.
148
- *
149
- * @return bool
142
+ * @return void
150
143
*/
151
- public function isRewindable ()
144
+ #[\ReturnTypeWillChange]
145
+ public function rewind ()
152
146
{
153
- if (null !== $ this ->rewindable ) {
154
- return $ this ->rewindable ;
155
- }
156
-
157
- if (false !== $ stream = @opendir ($ this ->getPath ())) {
158
- $ infos = stream_get_meta_data ($ stream );
159
- closedir ($ stream );
147
+ // some streams like FTP are not rewindable, ignore the first rewind after creation,
148
+ // as newly created DirectoryIterator does not need to be rewind
149
+ if (true === $ this ->ignoreFirstRewind ) {
150
+ $ this ->ignoreFirstRewind = false ;
160
151
161
- if ($ infos ['seekable ' ]) {
162
- return $ this ->rewindable = true ;
163
- }
152
+ return ;
164
153
}
165
154
166
- return $ this -> rewindable = false ;
155
+ parent :: rewind () ;
167
156
}
168
157
}
0 commit comments