1
0
mirror of https://tildegit.org/sbgodin/HtmGem.git synced 2023-08-25 13:53:12 +02:00
HtmGem/tests/utils.inc.php

23 lines
811 B
PHP

<?php declare(strict_types=1);
function getFiles($directory, $targetExtension): generator {
$flags =
FilesystemIterator::KEY_AS_PATHNAME
| FilesystemIterator::CURRENT_AS_FILEINFO
| FilesystemIterator::SKIP_DOTS
;
#TODO: Prevent preloading of symlinks. Otherwise it keeps loading instead of not
# going into.
#TODO: Prevent going into .git/ by browsing "manually" instead of RecursiveIteratorIterator
$dir = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory, $flags));
foreach ($dir as $fileinfo) {
$filename = $fileinfo->getFilename();
$filePathname = $fileinfo->getPathname();
$extension = $fileinfo->getExtension();
if ($targetExtension == $extension) {
yield $filePathname;
}
}
}