NewsNewsFeaturesDownloadsDevelopmentSupportForumDocumentsAbout Us

Glob 類別 參考文件
[Misc]

類別Glob的繼承圖:

Object 全部成員列表

公開方法(Public Methods)

 myGlob ($folder=".", $pattern="*")
 myFnmatch ($pattern, $file)

靜態公開方法(Static Public Methods)

 Glob ($folder=".", $pattern="*", $flags=0)
 fnmatch ($pattern, $file)

詳細描述

Alternative implementation of the glob() function, since the latter is only available in php versions 4.3 or higher and many many hosts have not updated yet. Original glob function: http://www.php.net/manual/en/function.glob.php. Original fnmatch function: http://www.php.net/manual/en/function.fnmatch.php.

The class is capable of detecting the version of php and using the native (and probably faster) version instead of the custom one.

定義在 glob.class.php 檔案之第 24 行.


建構子與解構子說明文件

Glob::Glob folder = ".",
pattern = "*",
flags = 0
[static]
 

This function checks wether we're running a version of php at least or newer than 4.3. If its newer, then we will use the native version of glob otherwise we will use our own version. The order of the parameters is not the same as the native version of glob, but they will be converted. The flags parameter is not used when using the custom version of glob.

參數:
folder The folder where would like to search for files. This function is not recursive.
pattern The shell pattern that will match the files we are searching for.
flags This parameter is only used when using the native version of glob. For possible values of this parameter, please check the glob function page.
傳回值:
Returns an array of the files that match the given pattern in the given folder or false if there was an error.

定義在 glob.class.php 檔案之第 43 行.

參考 myGlob().

00044         {
00045             if( function_exists("glob")) {
00046                 // call the native glob function with parameters
00047                 $fileName = $folder;
00048                 if( substr($fileName, -1) != "/" )
00049                     $fileName .= "/";
00050                 $fileName .= $pattern;
00051 
00052                 return glob( $fileName, $flags );
00053             }
00054             else {
00055                 // call our own implementation
00056                 return Glob::myGlob( $folder, $pattern );
00057             }
00058         }


函式成員說明文件

Glob::fnmatch pattern,
file
[static]
 

Front-end function that does the same as the glob function above but this time with the fnmnatch version. Checks the php version and if it is at least or greater than 4.3, then we will use the native and faster version of fnmatch or otherwise we will fall back to using our own custom version.

參數:
pattern The shell pattern.
file The filename we would like to match.
傳回值:
True if the file matches the pattern or false if not.

定義在 glob.class.php 檔案之第 71 行.

參考 myFnmatch().

被參考於 myGlob().

00072         {
00073             if( function_exists("fnmatch")) {
00074                 // use the native fnmatch version
00075                 return fnmatch( $pattern, $file );
00076             }
00077             else {
00078                 // otherwise, use our own
00079                 return Glob::myFnmatch( $pattern, $file );
00080             }
00081         }

Glob::myFnmatch pattern,
file
 

Our own equivalent of fnmatch that is only available in php 4.3.x.

Based on a user-contributed code for the fnmatch php function here: http://www.php.net/manual/en/function.fnmatch.php

定義在 glob.class.php 檔案之第 130 行.

被參考於 fnmatch(), 及 UploadValidator::validate().

00131         {
00132 
00133 
00134             for($i=0; $i<strlen($pattern); $i++) {
00135                 if($pattern[$i] == "*") {
00136                     for($c=$i; $c<max(strlen($pattern), strlen($file)); $c++) {
00137                         if(Glob::myFnmatch(substr($pattern, $i+1), substr($file, $c))) {
00138                             return true;
00139                         }
00140                     }
00141                     return false;
00142                 }
00143                 if($pattern[$i] == "[") {
00144                     $letter_set = array();
00145                     for($c=$i+1; $c<strlen($pattern); $c++) {
00146                         if($pattern[$c] != "]") {
00147                             array_push($letter_set, $pattern[$c]);
00148                         }
00149                         else
00150                             break;
00151                     }
00152                     foreach ($letter_set as $letter) {
00153                         if(Glob::myFnmatch($letter.substr($pattern, $c+1), substr($file, $i))) {
00154                             return true;
00155                         }
00156                     }
00157                     return false;
00158                }
00159                if($pattern[$i] == "?") {
00160                     continue;
00161               }
00162               if($pattern[$i] != $file[$i]) {
00163                 return false;
00164               }
00165          }
00166          return true;
00167        }

Glob::myGlob folder = ".",
pattern = "*"
 

Our own implementation of the glob function for those sites which run a version of php lower than 4.3. For more information on the function glob: http://www.php.net/manual/en/function.glob.php

Returns an array with all the files and subdirs that match the given shell expression.

參數:
folder Where to start searching.
pattern A shell expression including wildcards '*' and '?' defining which files will match and which will not.
傳回值:
An array with the matching files and false if error.

定義在 glob.class.php 檔案之第 94 行.

參考 fnmatch().

被參考於 TemplateSandbox::checkForbiddenFiles(), File::deleteDir(), FileFinder::find(), Glob(), 及 Captcha::purgeOld().

00095         {
00096             // Note that !== did not exist until 4.0.0-RC2
00097             // what if the temp folder is deleted?  or $folder is not exist? then will raise
00098             // ugly error or warning message. so first check if $folder readable
00099             if( !file_exists( $folder )) return Array();
00100 
00101             if ( $handle = opendir( $folder )) {
00102                 $files = Array();
00103 
00104                 while (false !== ($file = readdir($handle))) {
00105                     if( $file !="." && $file != ".." )  // ignore '.' and '..'
00106                         if( Glob::fnmatch($pattern,$file)) {
00107                             if( $folder[strlen($folder)-1] != "/")
00108                                 $filePath = $folder."/".$file;
00109                             else
00110                                 $filePath = $folder.$file;
00111                             array_push( $files, $filePath );
00112 
00113                         }
00114                 }
00115 
00116                 closedir($handle);
00117             }
00118             else
00119                 return Array();
00120 
00121             return $files;
00122         }


此類別(class) 文件是由下列檔案中產生: