protected function readMonitoredDirectoryRecursively($path, $filenamePattern)
{
$directories = [Files::getNormalizedPath($path)];
while ($directories !== []) {
$currentDirectory = array_pop($directories);
if (is_file($currentDirectory . '.flowFileMonitorIgnore')) {
continue;
}
if ($handle = opendir($currentDirectory)) {
while (false !== ($filename = readdir($handle))) {
if ($filename[0] === '.') {
continue;
}
$pathAndFilename = $currentDirectory . $filename;
if (is_dir($pathAndFilename)) {
array_push($directories, $pathAndFilename . DIRECTORY_SEPARATOR);
} elseif ($filenamePattern === null || preg_match('|' . $filenamePattern . '|', $filename) === 1) {
(yield $pathAndFilename);
}
}
closedir($handle);
}
}
}