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