Last active
December 21, 2015 23:19
-
-
Save cognifloyd/6381518 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
$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