@@ -91,7 +91,7 @@ public function copy($originFile, $targetFile, $overwriteNewerFiles = false)
91
91
*/
92
92
public function mkdir ($ dirs , $ mode = 0777 )
93
93
{
94
- foreach ($ this ->toIterator ($ dirs ) as $ dir ) {
94
+ foreach ($ this ->toIterable ($ dirs ) as $ dir ) {
95
95
if (is_dir ($ dir )) {
96
96
continue ;
97
97
}
@@ -120,7 +120,7 @@ public function exists($files)
120
120
{
121
121
$ maxPathLength = PHP_MAXPATHLEN - 2 ;
122
122
123
- foreach ($ this ->toIterator ($ files ) as $ file ) {
123
+ foreach ($ this ->toIterable ($ files ) as $ file ) {
124
124
if (strlen ($ file ) > $ maxPathLength ) {
125
125
throw new IOException (sprintf ('Could not check if file exist because path length exceeds %d characters. ' , $ maxPathLength ), 0 , null , $ file );
126
126
}
@@ -144,7 +144,7 @@ public function exists($files)
144
144
*/
145
145
public function touch ($ files , $ time = null , $ atime = null )
146
146
{
147
- foreach ($ this ->toIterator ($ files ) as $ file ) {
147
+ foreach ($ this ->toIterable ($ files ) as $ file ) {
148
148
$ touch = $ time ? @touch ($ file , $ time , $ atime ) : @touch ($ file );
149
149
if (true !== $ touch ) {
150
150
throw new IOException (sprintf ('Failed to touch "%s". ' , $ file ), 0 , null , $ file );
@@ -200,7 +200,7 @@ public function remove($files)
200
200
*/
201
201
public function chmod ($ files , $ mode , $ umask = 0000 , $ recursive = false )
202
202
{
203
- foreach ($ this ->toIterator ($ files ) as $ file ) {
203
+ foreach ($ this ->toIterable ($ files ) as $ file ) {
204
204
if (true !== @chmod ($ file , $ mode & ~$ umask )) {
205
205
throw new IOException (sprintf ('Failed to chmod file "%s". ' , $ file ), 0 , null , $ file );
206
206
}
@@ -221,7 +221,7 @@ public function chmod($files, $mode, $umask = 0000, $recursive = false)
221
221
*/
222
222
public function chown ($ files , $ user , $ recursive = false )
223
223
{
224
- foreach ($ this ->toIterator ($ files ) as $ file ) {
224
+ foreach ($ this ->toIterable ($ files ) as $ file ) {
225
225
if ($ recursive && is_dir ($ file ) && !is_link ($ file )) {
226
226
$ this ->chown (new \FilesystemIterator ($ file ), $ user , true );
227
227
}
@@ -248,7 +248,7 @@ public function chown($files, $user, $recursive = false)
248
248
*/
249
249
public function chgrp ($ files , $ group , $ recursive = false )
250
250
{
251
- foreach ($ this ->toIterator ($ files ) as $ file ) {
251
+ foreach ($ this ->toIterable ($ files ) as $ file ) {
252
252
if ($ recursive && is_dir ($ file ) && !is_link ($ file )) {
253
253
$ this ->chgrp (new \FilesystemIterator ($ file ), $ group , true );
254
254
}
@@ -370,7 +370,7 @@ public function hardlink($originFile, $targetFiles)
370
370
throw new FileNotFoundException (sprintf ('Origin file "%s" is not a file ' , $ originFile ));
371
371
}
372
372
373
- foreach ($ this ->toIterator ($ targetFiles ) as $ targetFile ) {
373
+ foreach ($ this ->toIterable ($ targetFiles ) as $ targetFile ) {
374
374
if (is_file ($ targetFile )) {
375
375
if (fileinode ($ originFile ) === fileinode ($ targetFile )) {
376
376
continue ;
@@ -724,18 +724,9 @@ public function appendToFile($filename, $content)
724
724
}
725
725
}
726
726
727
- /**
728
- * @param mixed $files
729
- *
730
- * @return \Traversable
731
- */
732
- private function toIterator ($ files )
727
+ private function toIterable ($ files ): iterable
733
728
{
734
- if (!$ files instanceof \Traversable) {
735
- $ files = new \ArrayObject (is_array ($ files ) ? $ files : array ($ files ));
736
- }
737
-
738
- return $ files ;
729
+ return is_array ($ files ) || $ files instanceof \Traversable ? $ files : array ($ files );
739
730
}
740
731
741
732
/**
0 commit comments