本文整理匯總了PHP中SpoonFilter::isValidRegexp方法的典型用法代碼示例。如果您正苦於以下問題:PHP SpoonFilter::isValidRegexp方法的具體用法?PHP SpoonFilter::isValidRegexp怎麽用?PHP SpoonFilter::isValidRegexp使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類SpoonFilter
的用法示例。
在下文中一共展示了SpoonFilter::isValidRegexp方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: getList
/**
* Returns a list of directories within a directory.
*
* @return array An array containing all directories (and files if $showFiles is true).
* @param string $path Path of the directory.
* @param bool[optional] $showFiles Should files be included in the list.
* @param array[optional] $excluded An array containing directories/files to exclude.
* @param string[optional] $includeRegexp An regular expression that represents the directories/files to include in the list. Other directories will be excluded.
*/
public static function getList($path, $showFiles = false, array $excluded = null, $includeRegexp = null)
{
// redefine arguments
$path = (string) $path;
$showFiles = (bool) $showFiles;
// validate regex
if ($includeRegexp !== null) {
// redefine
$includeRegexp = (string) $includeRegexp;
// validate
if (!SpoonFilter::isValidRegexp($includeRegexp)) {
throw new SpoonDirectoryException('Invalid regular expression (' . $includeRegexp . ').');
}
}
// define file list
$directories = array();
// directory exists
if (self::exists($path)) {
// attempt to open directory
$directory = @opendir($path);
// do your thing if directory-handle isn't false
if ($directory !== false) {
// start reading
while (($file = readdir($directory)) !== false) {
// no '.' and '..' and it's a file
if ($file != '.' && $file != '..') {
// directory
if (is_dir($path . '/' . $file)) {
// exclude certain files
if (count($excluded) != 0) {
if (!in_array($file, $excluded)) {
if ($includeRegexp !== null) {
// init var
$matches = array();
// is this a match?
if (preg_match($includeRegexp, $file, $matches) != 0) {
$directories[] = $file;
}
} else {
$directories[] = $file;
}
}
} else {
if ($includeRegexp !== null) {
// init var
$matches = array();
// is this a match?
if (preg_match($includeRegexp, $file, $matches) != 0) {
$directories[] = $file;
}
} else {
$directories[] = $file;
}
}
} else {
// show files
if ($showFiles) {
// exclude certain files
if (count($excluded) != 0) {
if (!in_array($file, $excluded)) {
$directories[] = $file;
}
} else {
$directories[] = $file;
}
}
}
}
}
}
// close directory
@closedir($directory);
}
// cough up directory listing
natsort($directories);
return $directories;
}
示例2: testIsValidRegexp
public function testIsValidRegexp()
{
$this->assertTrue(SpoonFilter::isValidRegexp('/boobies/'));
}
示例3: getList
/**
* Retrieves a list of files within a directory.
*
* @return array An array containing a list of files in the given directory.
* @param string $path The path to the directory.
* @param string[optional] $includeRegexp A regular expresion that filters the files that should be included in the list.
*/
public static function getList($path, $includeRegexp = null)
{
// redefine arguments
$path = (string) $path;
// validate regex
if ($includeRegexp !== null) {
// redefine
$includeRegexp = (string) $includeRegexp;
// validate
if (!SpoonFilter::isValidRegexp($includeRegexp)) {
throw new SpoonFileSystemException('Invalid regular expression (' . $includeRegexp . ')');
}
}
// define list
$files = array();
// directory exists
if (SpoonDirectory::exists($path)) {
// attempt to open directory
if ($directory = @opendir($path)) {
// start reading
while (($file = readdir($directory)) !== false) {
// no '.' and '..' and it's a file
if ($file != '.' && $file != '..' && is_file($path . '/' . $file)) {
// is there a include-pattern?
if ($includeRegexp !== null) {
// init var
$matches = array();
// is this a match?
if (preg_match($includeRegexp, $file, $matches) != 0) {
$files[] = $file;
}
} else {
$files[] = $file;
}
}
}
}
// close directory
@closedir($directory);
}
// directory doesn't exist or a problem occured
return $files;
}