本文整理匯總了PHP中Nette\Utils\Finder::compare方法的典型用法代碼示例。如果您正苦於以下問題:PHP Finder::compare方法的具體用法?PHP Finder::compare怎麽用?PHP Finder::compare使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Nette\Utils\Finder
的用法示例。
在下文中一共展示了Finder::compare方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: date
/**
* Restricts the search by modified time.
* @param string "[operator] [date]" example: >1978-01-23
* @param mixed
* @return self
*/
public function date($operator, $date = NULL)
{
if (func_num_args() === 1) {
// in $operator is predicate
if (!preg_match('#^(?:([=<>!]=?|<>)\\s*)?(.+)\\z#i', $operator, $matches)) {
throw new Nette\InvalidArgumentException('Invalid date predicate format.');
}
list(, $operator, $date) = $matches;
$operator = $operator ? $operator : '=';
}
$date = Nette\DateTime::from($date)->format('U');
return $this->filter(function ($file) use($operator, $date) {
return Finder::compare($file->getMTime(), $operator, $date);
});
}
示例2: function
/**
* Restricts the search by images dimensions.
* @param string
* @param string
* @return Nette\Utils\Finder provides a fluent interface
*/
Finder::extensionMethod('dimensions', function($finder, $width, $height){
if (!preg_match('#^([=<>!]+)\s*(\d+)$#i', $width, $mW) || !preg_match('#^([=<>!]+)\s*(\d+)$#i', $height, $mH)) {
throw new InvalidArgumentException('Invalid dimensions predicate format.');
}
return $finder->filter(function($file) use ($mW, $mH) {
return $file->getSize() >= 12 && ($size = getimagesize($file->getPathname()))
&& (!$mW || Finder::compare($size[0], $mW[1], $mW[2]))
&& (!$mH || Finder::compare($size[1], $mH[1], $mH[2]));
});
});
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Nette\Finder custom filters | Nette Framework</title>