本文整理匯總了PHP中Finder::filter方法的典型用法代碼示例。如果您正苦於以下問題:PHP Finder::filter方法的具體用法?PHP Finder::filter怎麽用?PHP Finder::filter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Finder
的用法示例。
在下文中一共展示了Finder::filter方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: registerFilter
/**
* Registers the filter.
*
* @param Finder $finder
* @param string $name The filter's name
* @param string $filter The filter
*
* @throws Exception\Filter\ContinueException When the filter wasn't choosen
* @throws Exception\Filter\InvaildFilterException When the filter is wrong
* @throws Exception\Filter\InvaildFilterException When the filter doesn't implement FilterInterface
*/
private function registerFilter($finder, $name, $filter)
{
$filters = $this->getAvailableFilters();
$choosenFilters = $this->getFilters();
if (!in_array($name, $choosenFilters)) {
throw new Exception\Filter\ContinueException(sprintf('Filter "%s" is not choosen', $name));
}
if (is_callable($filter)) {
$filter = call_user_func($filter);
} elseif (isset($filters[$filter])) {
$filter = call_user_func($filters[$filter]);
} elseif (class_exists($filter)) {
$filter = new $filter();
} else {
throw new Exception\Filter\InvalidFilterException(array('a callable which returns a filter class', 'a build-in filter name'));
}
if (!$filter instanceof FilterInterface) {
throw new Exception\Filter\InvalidFilterException('an instance of Inspector\\Filter\\FilterInterface');
}
$finder->filter(function (\SplFileInfo $file) use($filter) {
return $filter->filter($file);
});
}