Skip to content

Instantly share code, notes, and snippets.

@cognifloyd
Last active December 21, 2015 23:19
Show Gist options
  • Save cognifloyd/6381518 to your computer and use it in GitHub Desktop.
Save cognifloyd/6381518 to your computer and use it in GitHub Desktop.
<?
$userFilterIsCallable = is_callable($userFilter)
/**
* Anonymous function to filter the DirectoryIterator's results
*
* @param $fileInfo \SplFileInfo Current file's FileInfo
* @param $pathname string Current file's path
* @param $iterator RecursiveCallbackFilterIterator
* @return boolean true if the current element is acceptable, otherwise false.
*/
$filter = function ($fileInfo, $pathname, $iterator) use ($returnDotFiles, $suffix, $suffixLength, $userFilter, $userFilterIsCallable) {
$return = FALSE;
$filename = $fileInfo->getFilename();
if ($returnDotFiles === FALSE && $filename[0] === '.') {
$return = FALSE;
} elseif (($fileInfo->isFile() && ($suffix === NULL || substr($filename, -$suffixLength) === $suffix)) || $iterator->hasChildren()) {
$return = TRUE;
}
if ($userFilterIsCallable) {
$return = $userFilter($fileInfo, $pathname, $iterator, $filename, $returnDotFiles, $suffix, $suffixLength, &$return);
}
return $return;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment