8000 [Filesystem] toIterable() in favor of toIterator() by ro0NL · Pull Request #24928 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Filesystem] toIterable() in favor of toIterator() #24928

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 10 additions & 14 deletions src/Symfony/Component/Filesystem/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {< 8000 /span>
if (is_dir($dir)) {
continue;
}
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
Expand Down Expand Up @@ -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);
}
Expand All @@ -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 8000 ($files) as $file) {
if ($recursive && is_dir($file) && !is_link($file)) {
$this->chown(new \FilesystemIterator($file), $user, true);
}
Expand All @@ -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);
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

/**
Expand Down
0