Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7a843da

Browse files
[Finder] always return RecursiveDirectoryIterator from its getChildren() method
1 parent 58c7f74 commit 7a843da

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

src/Symfony/Component/Finder/Iterator/RecursiveDirectoryIterator.php

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,29 @@ public function current()
7979
}
8080

8181
/**
82-
* @return \RecursiveIterator
82+
* @return bool
83+
*/
84+
#[\ReturnTypeWillChange]
85+
public function hasChildren(bool $allowLinks = false)
86+
{
87+
$hasChildren = parent::hasChildren($allowLinks);
88+
89+
if (!$hasChildren || !$this->ignoreUnreadableDirs) {
90+
return $hasChildren;
91+
}
92+
93+
try {
94+
parent::getChildren();
95+
96+
return true;
97+
} catch (\UnexpectedValueException $e) {
98+
// If directory is unreadable and finder is set to ignore it, skip children
99+
return false;
100+
}
101+
}
102+
103+
/**
104+
* @return \RecursiveDirectoryIterator
83105
*
84106
* @throws AccessDeniedException
85107
*/
@@ -100,12 +122,7 @@ public function getChildren()
100122

101123
return $children;
102124
} catch (\UnexpectedValueException $e) {
103-
if ($this->ignoreUnreadableDirs) {
104-
// If directory is unreadable and finder is set to ignore it, a fake empty content is returned.
105-
return new \RecursiveArrayIterator([]);
106-
} else {
107-
throw new AccessDeniedException($e->getMessage(), $e->getCode(), $e);
108-
}
125+
throw new AccessDeniedException($e->getMessage(), $e->getCode(), $e);
109126
}
110127
}
111128

0 commit comments

Comments
 (0)