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