public getListOfConfigFilesIn ( $directory, $pattern ) : array | ||
Результат | array |
public function getListOfConfigFilesIn($directory, $pattern)
{
// does the directory exist?
if (!is_dir($directory)) {
return [];
}
// use the SPL to do the heavy lifting
$dirIter = new RecursiveDirectoryIterator($directory);
$recIter = new RecursiveIteratorIterator($dirIter);
$regIter = new RegexIterator($recIter, '|^.+' . $pattern . '$|i', RegexIterator::GET_MATCH);
// what happened?
$filenames = [];
foreach ($regIter as $match) {
$filenames[] = $match[0];
}
// let's get the list into some semblance of order
sort($filenames);
// all done
return $filenames;
}
/** * build a list of the config files in the $searchFolder * * @return array<string> */ protected function findConfigFilenames($searchPattern) { // where are we looking? $searchFolders = $this->getSearchFolders(); // our return value $filenames = []; foreach ($searchFolders as $searchFolder) { // do we have somewhere to look? if (null === $searchFolder || !is_dir($searchFolder)) { continue; } // build our list $configFinder = new ConfigFinder(); $filenames = array_merge($filenames, $configFinder->getListOfConfigFilesIn($searchFolder, $searchPattern)); } // all done return $filenames; }