/**
* Search the specified directory tree with the specified pattern. Return
* an array containing all matching files (no directories included).
*
* @param string $pattern the pattern to match every file with.
*
* @param string $directory the directory tree to search in.
*
* @param string $type the type of regular expression support to use, either
* 'php' or 'perl'.
*
* @param bool $fullpath whether the regex should be matched against the
* full path or only against the filename
*
* @param string $match can be either 'files', 'dirs' or 'both' to specify
* the kind of list to return
*
* @return array a list of files matching the pattern parameter in the the
* directory path specified by the directory parameter
*
* @author Sterling Hughes <*****@*****.**>
* @access public
* @static
*/
function &search($pattern, $directory, $type = 'php', $fullpath = true, $match = 'files')
{
$matches = array();
list($directories, $files) = File_Find::maptree($directory);
switch ($match) {
case 'directories':
$data = $directories;
break;
case 'both':
$data = array_merge($directories, $files);
break;
case 'files':
default:
$data = $files;
}
unset($files, $directories);
$match_function = File_Find::_determineRegex($pattern, $type);
reset($data);
while (list(, $entry) = each($data)) {
if ($match_function($pattern, $fullpath ? $entry : basename($entry))) {
$matches[] = $entry;
}
}
return $matches;
}