compare() 공개 정적인 메소드

Compares two values.
public static compare ( $l, $operator, $r ) : boolean
리턴 boolean
 /**
  * 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
0

/**
 * 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>