コード例 #1
0
/**
 * @param string[] $paths
 * @return \Generator
 */
function flatten_input_paths(array $paths)
{
    foreach ($paths as $path) {
        foreach (recursive_scan(realpath($path)) as $file) {
            if (pathinfo($file, PATHINFO_EXTENSION) === 'php') {
                (yield $file);
            }
        }
    }
}
コード例 #2
0
/**
 * @param string $path
 * @param bool   $followLinks
 * @return \Generator
 */
function recursive_scan($path, $followLinks = false)
{
    (yield $path);
    if (is_dir($path) && ($followLinks || !is_link($path))) {
        foreach (array_diff(scandir($path), ['.', '..']) as $p) {
            foreach (recursive_scan($path . DIRECTORY_SEPARATOR . $p, $followLinks) as $p2) {
                (yield $p2);
            }
        }
    }
}