extensionMethod() 공개 정적인 메소드

public static extensionMethod ( $name, $callback )
예제 #1
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">
예제 #2
0
<?php

\Nette\Utils\Finder::extensionMethod('imported', function ($finder, $shouldBeImported) {
    return $finder->filter(function ($file) use($shouldBeImported) {
        $lockFile = $file->getPathname() . '/.imported';
        return file_exists($lockFile) === $shouldBeImported;
    });
});
\Nette\Utils\Finder::extensionMethod('aborted', function ($finder, $shouldBeAborted) {
    return $finder->filter(function ($file) use($shouldBeAborted) {
        $lockFile = $file->getPathname() . '/.notimported';
        return file_exists($lockFile) === $shouldBeAborted;
    });
});
\Nette\Utils\Finder::extensionMethod('toArray', function ($finder) {
    $files = array();
    foreach ($finder as $file) {
        $files[] = $file->getPathname();
    }
    return $files;
});