_determineRegex() public method

internal function to determine the type of regular expression to use, implemented by File_Find::glob() and File_Find::search()
public _determineRegex ( $pattern, string $type ) : string
$type string given RegExp type
return string kind of function ( "eregi", "ereg" or "preg_match") ;
コード例 #1
0
ファイル: Find.php プロジェクト: rhempen/cms
 /**
  * Search the specified directory tree with the specified pattern.  Return
  * an array containing all matching files (no directories included).
  *
  * @param string $pattern the pattern to match every file with.
  *
  * @param string $directory the directory tree to search in.
  *
  * @param string $type the type of regular expression support to use, either
  * 'php' or 'perl'.
  *
  * @param bool $fullpath whether the regex should be matched against the
  * full path or only against the filename
  *
  * @param string $match can be either 'files', 'dirs' or 'both' to specify
  * the kind of list to return
  *
  * @return array a list of files matching the pattern parameter in the the
  * directory path specified by the directory parameter
  *
  * @author Sterling Hughes <*****@*****.**>
  * @access public
  * @static
  */
 function &search($pattern, $directory, $type = 'php', $fullpath = true, $match = 'files')
 {
     $matches = array();
     list($directories, $files) = File_Find::maptree($directory);
     switch ($match) {
         case 'directories':
             $data = $directories;
             break;
         case 'both':
             $data = array_merge($directories, $files);
             break;
         case 'files':
         default:
             $data = $files;
     }
     unset($files, $directories);
     $match_function = File_Find::_determineRegex($pattern, $type);
     reset($data);
     while (list(, $entry) = each($data)) {
         if ($match_function($pattern, $fullpath ? $entry : basename($entry))) {
             $matches[] = $entry;
         }
     }
     return $matches;
 }
コード例 #2
0
ファイル: Find.php プロジェクト: bantudevelopment/polysmis
 /**
  * Search the specified directory tree with the specified pattern.  Return an
  * array containing all matching files (no directories included).
  *
  * @param string $pattern the pattern to match every file with.
  *
  * @param string $directory the directory tree to search in.
  *
  * @param string $type the type of regular expression support to use, either
  * 'php' or 'perl'.
  *
  * @return array a list of files matching the pattern parameter in the the directory
  * path specified by the directory parameter
  *
  * @author Sterling Hughes <*****@*****.**>
  * @access public
  */
 function &search($pattern, $directory, $type = 'php')
 {
     $matches = array();
     list(, $files) = File_Find::maptree($directory);
     $match_function = File_Find::_determineRegex($pattern, $type);
     reset($files);
     while (list(, $entry) = each($files)) {
         if ($match_function($pattern, $entry)) {
             $matches[] = $entry;
         }
     }
     return $matches;
 }
コード例 #3
0
ファイル: Find.php プロジェクト: altesien/FinalProject
 /**
  * Search the specified directory tree with the specified pattern.  Return
  * an array containing all matching files (no directories included).
  *
  * @param string $pattern the pattern to match every file with.
  *
  * @param string $directory the directory tree to search in.
  *
  * @param string $type the type of regular expression support to use, either
  * 'php', 'perl' or 'shell'.
  *
  * @param bool $fullpath whether the regex should be matched against the
  * full path or only against the filename
  *
  * @param string $match can be either 'files', 'dirs' or 'both' to specify
  * the kind of list to return
  *
  * @return array a list of files matching the pattern parameter in the the
  * directory path specified by the directory parameter
  *
  * @author Sterling Hughes <*****@*****.**>
  * @access public
  * @static
  */
 function &search($pattern, $directory, $type = 'php', $fullpath = true, $match = 'files')
 {
     $matches = array();
     list($directories, $files) = File_Find::maptree($directory);
     switch ($match) {
         case 'directories':
             $data = $directories;
             break;
         case 'both':
             $data = array_merge($directories, $files);
             break;
         case 'files':
         default:
             $data = $files;
     }
     unset($files, $directories);
     $match_function = File_Find::_determineRegex($pattern, $type);
     reset($data);
     // check if empty string given (ok for 'shell' method, but bad for others)
     if ($pattern || $type != 'php' && $type != 'perl') {
         while (list(, $entry) = each($data)) {
             if ($match_function($pattern, $fullpath ? $entry : basename($entry))) {
                 $matches[] = $entry;
             }
         }
     }
     sort($matches);
     return $matches;
 }
コード例 #4
0
ファイル: Find.php プロジェクト: BackupTheBerlios/smart-svn
 /**
  * Search the specified directory tree with the specified pattern.  Return
  * an array containing all matching files (no directories included).
  *
  * @param string $pattern the pattern to match every file with.
  *
  * @param string $directory the directory tree to search in.
  *
  * @param string $type the type of regular expression support to use, either
  * 'php' or 'perl'.
  *
  * @param bool $fullpath whether the regex should be matched against the
  * full path or only against the filename
  *
  * @return array a list of files matching the pattern parameter in the the
  * directory path specified by the directory parameter
  *
  * @author Sterling Hughes <*****@*****.**>
  * @access public
  */
 function &search($pattern, $directory, $type = 'php', $fullpath = true)
 {
     /* if called statically */
     /* TODO: this will fail if File_Find::search() is called inside */
     /* instance of some other object                                */
     if (!isset($this)) {
         $obj =& new File_Find();
         return $obj->search($pattern, $directory, $type, $fullpath);
     } else {
         $matches = array();
         list(, $files) = File_Find::maptree($directory);
         $match_function = File_Find::_determineRegex($pattern, $type);
         reset($files);
         while (list(, $entry) = each($files)) {
             if ($match_function($pattern, $fullpath ? $entry : basename($entry))) {
                 $matches[] = $entry;
             }
         }
     }
     return $matches;
 }