From 9415561605df361bfdc74ad73e29029909197803 Mon Sep 17 00:00:00 2001 From: Roland Franssen Date: Sat, 11 Nov 2017 21:57:50 +0100 Subject: [PATCH 1/2] [Filesystem] toIterable() in favor of toIterator() --- .../Component/Filesystem/Filesystem.php | 22 ++++++++----------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/Symfony/Component/Filesystem/Filesystem.php b/src/Symfony/Component/Filesystem/Filesystem.php index 0354a49d3d105..d065f151840de 100644 --- a/src/Symfony/Component/Filesystem/Filesystem.php +++ b/src/Symfony/Component/Filesystem/Filesystem.php @@ -90,7 +90,7 @@ public function copy($originFile, $targetFile, $overwriteNewerFiles = false) */ public function mkdir($dirs, $mode = 0777) { - foreach ($this->toIterator($dirs) as $dir) { + foreach ($this->toIterable($dirs) as $dir) { if (is_dir($dir)) { continue; } @@ -119,7 +119,7 @@ public function exists($files) { $maxPathLength = PHP_MAXPATHLEN - 2; - foreach ($this->toIterator($files) as $file) { + foreach ($this->toIterable($files) as $file) { if (strlen($file) > $maxPathLength) { throw new IOException(sprintf('Could not check if file exist because path length exceeds %d characters.', $maxPathLength), 0, null, $file); } @@ -143,7 +143,7 @@ public function exists($files) */ public function touch($files, $time = null, $atime = null) { - foreach ($this->toIterator($files) as $file) { + foreach ($this->toIterable($files) as $file) { $touch = $time ? @touch($file, $time, $atime) : @touch($file); if (true !== $touch) { throw new IOException(sprintf('Failed to touch "%s".', $file), 0, null, $file); @@ -199,7 +199,7 @@ public function remove($files) */ public function chmod($files, $mode, $umask = 0000, $recursive = false) { - foreach ($this->toIterator($files) as $file) { + foreach ($this->toIterable($files) as $file) { if (true !== @chmod($file, $mode & ~$umask)) { throw new IOException(sprintf('Failed to chmod file "%s".', $file), 0, null, $file); } @@ -220,7 +220,7 @@ public function chmod($files, $mode, $umask = 0000, $recursive = false) */ public function chown($files, $user, $recursive = false) { - foreach ($this->toIterator($files) as $file) { + foreach ($this->toIterable($files) as $file) { if ($recursive && is_dir($file) && !is_link($file)) { $this->chown(new \FilesystemIterator($file), $user, true); } @@ -247,7 +247,7 @@ public function chown($files, $user, $recursive = false) */ public function chgrp($files, $group, $recursive = false) { - foreach ($this->toIterator($files) as $file) { + foreach ($this->toIterable($files) as $file) { if ($recursive && is_dir($file) && !is_link($file)) { $this->chgrp(new \FilesystemIterator($file), $group, true); } @@ -722,15 +722,11 @@ public function appendToFile($filename, $content) /** * @param mixed $files * - * @return \Traversable + * @return array|\Traversable */ - private function toIterator($files) + private function toIterable($files) { - if (!$files instanceof \Traversable) { - $files = new \ArrayObject(is_array($files) ? $files : array($files)); - } - - return $files; + return is_array($files) || $files instanceof \Traversable ? $files : array($files); } /** From 8691c1af64a79172f9ff63be0c69339e39c0b9b7 Mon Sep 17 00:00:00 2001 From: Roland Franssen Date: Sun, 12 Nov 2017 20:37:53 +0100 Subject: [PATCH 2/2] Update Filesystem.php --- src/Symfony/Component/Filesystem/Filesystem.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Filesystem/Filesystem.php b/src/Symfony/Component/Filesystem/Filesystem.php index d065f151840de..0141708c9d69a 100644 --- a/src/Symfony/Component/Filesystem/Filesystem.php +++ b/src/Symfony/Component/Filesystem/Filesystem.php @@ -369,7 +369,7 @@ public function hardlink($originFile, $targetFiles) throw new FileNotFoundException(sprintf('Origin file "%s" is not a file', $originFile)); } - foreach ($this->toIterator($targetFiles) as $targetFile) { + foreach ($this->toIterable($targetFiles) as $targetFile) { if (is_file($targetFile)) { if (fileinode($originFile) === fileinode($targetFile)) { continue;