本文整理汇总了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);
});
}