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
Raw Permalink Normal View History

2021-03-24 10:53:12 +01:00
<?php declare(strict_types=1);
2021-04-04 22:23:38 +02:00
function getFiles($directory, $targetExtension): generator {
2021-03-24 10:53:12 +01:00
$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();
2021-04-04 22:23:38 +02:00
if ($targetExtension == $extension) {
2021-03-24 10:53:12 +01:00
yield $filePathname;
}
}
}