当前位置: 首页>>代码示例>>PHP>>正文


PHP SpoonFilter::isValidRegexp方法代码示例

本文整理汇总了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;
 }
开发者ID:JonckheereM,项目名称:Public,代码行数:86,代码来源:directory.php

示例2: testIsValidRegexp

 public function testIsValidRegexp()
 {
     $this->assertTrue(SpoonFilter::isValidRegexp('/boobies/'));
 }
开发者ID:jeroendesloovere,项目名称:library,代码行数:4,代码来源:SpoonFilterTest.php

示例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;
 }
开发者ID:ss23,项目名称:ECommerce,代码行数:50,代码来源:filesystem.php


注:本文中的SpoonFilter::isValidRegexp方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。