Public Member Functions | |
read ($fileName, $projectRelative=true) | |
Read a File looks for the File in the Current Project Directory if $projectRelative is Given as true(default) returns the File Contents as String returns false on Failure Fires Error if the file doesn't exist or not readable. | |
write ($fileName, $data, $projectRelative=true) | |
Writes $data to a File looks for the File in the Current Project Directory if $projectRelative is Given as true(default) returns the Bytes Written as an Integer if $data is Provided as an Array concats it to make a String and then writes Opens the File in w Mode returns false on Failure. | |
parseINI ($fileName, $processSections=false, $projectRelative=true) | |
Parses an INI File looks for the File in the Current Project Directory if $projectRelative is Given as true(default) By setting the last $processSections parameter to TRUE, you get a multidimensional array, with the section names and settings included. | |
listSiblings ($baseDir, $pattern=null) | |
List's all the Files and Directories in the Current Directory You can optionally Specify a Pattern to match (will be matched using preg_match()) Returns all Entries as an Array Returns false on failure. | |
listSiblingFiles ($baseDir, $pattern=null) | |
List's all the Files (No Directory will be listed) in the Current Directory You can optionally Specify a Pattern to match (will be matched using preg_match()) Returns all Entries as an Array Returns false on failure. | |
listSiblingDirs ($baseDir, $pattern=null) | |
List's all the Directories (No Files will be listed) in the Current Directory You can optionally Specify a Pattern to match (will be matched using preg_match()) Returns all Entries as an Array Returns false on failure. | |
tree ($baseDir, $pattern=null) | |
Grabs all the Items in the $baseDir Recursively and generates a Highly useful LINEAR array which is Numarically Indexed with Full Paths of the Items as the Value Goes to the Ultimate Depth returns an array of all elements(Both Files and Directory) on Success Returns false on failure. | |
treeDirs ($baseDir, $pattern=null) | |
Grabs all the Directories(Omits all Files) in the $baseDir Recursively and generates a Highly use full LINEAR array which is Numarically Indexed with Full Paths of the Items as the Value Goes to the Ultimate Depth returns an array of all elements(Just Directories) on Success Returns false on failure. | |
treeFiles ($baseDir, $pattern=null) | |
Grabs all the Files(Omits all Directories) in the $baseDir Recursively and generates a Highly use full LINEAR array which is Numarically Indexed with Full Paths of the Items as the Value Goes to the Ultimate Depth returns an array of all elements(Just Files) on Success Returns false on failure. | |
getPerm ($fileName, $fullPerm=false) | |
Get the Permission of a File or directory if $fullPerm is given as true returns permission as string like -rw-r--r-- Instead of Octal 0644. | |
setPerm ($fileName, $perm) | |
Sets the Permission of a File or Directory you must provide an octal permission returns Boolean Success result. | |
copy ($src, $dest, $recursive=true) | |
Copies Files/Directories from one to another Location recursively or non recursively By defult it Copies recursively returns Boolean success result. | |
move ($src, $dest, $recursive=true) | |
Moves Files/Directories from one to another Location recursively or non recursively By defult it Copies recursively returns Boolean success result. | |
rename ($oldName, $newName) | |
Renames a file/Directory returns boolean success Result. | |
remove ($src) | |
Removes File/Directory Recursively or non Recursively $recursive default to true. | |
exists ($src) | |
Checks wheather or not a File/Directory Exists. | |
fileExists ($src) | |
Checks wheather or not a File Exists. | |
dirExists ($src) | |
Checks wheather or not a Directory Exists. | |
mkDir ($dirName, $perm=0777, $recursive=false) | |
Creates a Directory with the Given Permission (Default 0777) with Recursively or Non recursively (Default Recursively). | |
getExtension ($fileName) | |
get the Extension of a FileName Doesn't Check the existance of the File | |
createBlankFile ($fileName, $projectRelative=true) | |
Creates a Blank File Creates the file in the Current Project Directory if $projectRelative is Given as true(default). | |
getFileSize ($fileName, $projectRelative=true) | |
Return size of a File searches for the file in the Current Project Directory if $projectRelative is Given as true(default). |
Definition at line 29 of file faccess.php.
zFAccess::read | ( | $ | fileName, | |
$ | projectRelative = true | |||
) |
Read a File looks for the File in the Current Project Directory if $projectRelative is Given as true(default) returns the File Contents as String returns false on Failure Fires Error if the file doesn't exist or not readable.
$fileName string
$projectRelative | boolean optional |
Definition at line 41 of file faccess.php.
References perror().
Referenced by copy().
00041 { 00042 if($projectRelative){ 00043 $fileName = realpath(Z_PROJECT_ROOT.DRS.ltrim($fileName, '/')); 00044 } 00045 if(!file_exists($fileName)){ 00046 perror("<code>zigmoyd.FAccess.read</code><br />The File $fileName does not exists"); 00047 return false; 00048 } 00049 if(!is_readable($fileName)){ 00050 perror("<code>zigmoyd.FAccess.read</code><br />The File $fileName is not readable"); 00051 return false; 00052 } 00053 $fRes = fopen($fileName, 'rb'); 00054 if($fRes){ 00055 if(!$contents = fread($fRes, filesize($fileName))){ 00056 perror("<code>zigmoyd.FAccess.read</code><br />Failed to Read $fileName"); 00057 return false; 00058 } 00059 fclose($fRes); 00060 }else{ 00061 perror("<code>zigmoyd.FAccess.read</code><br />Failed to Open $fileName for reading"); 00062 return false; 00063 } 00064 return $contents; 00065 }
zFAccess::write | ( | $ | fileName, | |
$ | data, | |||
$ | projectRelative = true | |||
) |
Writes $data to a File looks for the File in the Current Project Directory if $projectRelative is Given as true(default) returns the Bytes Written as an Integer if $data is Provided as an Array concats it to make a String and then writes Opens the File in w Mode returns false on Failure.
$fileName | string | |
$projectRelative | boolean optional |
Definition at line 78 of file faccess.php.
References perror().
Referenced by createBlankFile().
00078 { 00079 if($projectRelative){ 00080 $fileName = (Z_PROJECT_ROOT.DRS.ltrim($fileName, '/')); 00081 } 00082 if($file = fopen($fileName, 'w')){ 00083 $bytes = fwrite($file, is_array($data) ? implode('', $data) : $data); 00084 fclose($file); return $bytes; //return the number of bytes written to the file 00085 }else{ 00086 perror("<code>zigmoyd.FAccess.write</code><br />Failed to Open $fileName for writing"); 00087 return false; 00088 } 00089 }
Parses an INI File looks for the File in the Current Project Directory if $projectRelative is Given as true(default) By setting the last $processSections parameter to TRUE, you get a multidimensional array, with the section names and settings included.
The default for $processSections is FALSE returns a Parsed array (Using PHP's parse_ini_file()) returns false on Failure Fires Error if the file doesn't exist or not readable
$fileName | string | |
$processSections | boolean | |
$projectRelative | boolean optional |
Definition at line 104 of file faccess.php.
References perror().
00104 { 00105 if($projectRelative){ 00106 $fileName = realpath(Z_PROJECT_ROOT.DRS.'etc'.DRS.Z_DIR_ETC_CONF.DRS.ltrim($fileName, '/')); 00107 } 00108 if(!file_exists($fileName)){ 00109 perror("<code>zigmoyd.FAccess.parseINI</code><br />The File $fileName does not exists"); 00110 return false; 00111 } 00112 if(!is_readable($fileName)){ 00113 perror("<code>zigmoyd.FAccess.parseINI</code><br />The File $fileName is not readable"); 00114 return false; 00115 } 00116 return parse_ini_file($fileName, $processSections); 00117 }
zFAccess::listSiblings | ( | $ | baseDir, | |
$ | pattern = null | |||
) |
List's all the Files and Directories in the Current Directory You can optionally Specify a Pattern to match (will be matched using preg_match()) Returns all Entries as an Array Returns false on failure.
$baseDir | string | |
$pattern | boolean optional |
Definition at line 128 of file faccess.php.
References perror().
Referenced by tree(), treeDirs(), and treeFiles().
00128 { 00129 if(!is_dir($baseDir)){ 00130 perror("<code>zigmoyd.faccess.listSibling</code><br />The Directory $baseDir doesn't exist"); 00131 return false; 00132 } 00133 if(!$dh = opendir($baseDir)){ 00134 perror("<code>zigmoyd.faccess.listSibling</code><br />Failed to open the Directory $baseDir for reading"); 00135 return false; 00136 } 00137 $files = array(); 00138 while(false !== ($entry = readdir($dh))){ 00139 if(!is_null($pattern)){ 00140 $regx = preg_match($pattern, $entry); 00141 if(is_bool($regx) && !$regx){ 00142 perror("<code>zigmoyd.zFAccess.listSiblings</code><br />Failed to match the Regular expression Provided. Invalid regular expression $pattern Supplied"); 00143 return false; 00144 } 00145 } 00146 if(is_null($pattern) || (!is_null($pattern) && $regx > 0)) 00147 $files[] = $entry; 00148 } 00149 //sort($files); 00150 return $files; 00151 }
zFAccess::listSiblingFiles | ( | $ | baseDir, | |
$ | pattern = null | |||
) |
List's all the Files (No Directory will be listed) in the Current Directory You can optionally Specify a Pattern to match (will be matched using preg_match()) Returns all Entries as an Array Returns false on failure.
$baseDir | string | |
$pattern | string optional |
Definition at line 162 of file faccess.php.
References perror().
00162 { 00163 if(!is_dir($baseDir)){ 00164 perror("<code>zigmoyd.faccess.listSiblingFiles</code><br />The Directory $baseDir doesn't exist"); 00165 return false; 00166 } 00167 if(!$dh = opendir($baseDir)){ 00168 perror("<code>zigmoyd.faccess.listSiblingFiles</code><br />Failed to open the Directory $baseDir for reading"); 00169 return false; 00170 } 00171 $files = array(); 00172 while(false !== ($entry = readdir($dh))){ 00173 if(is_null($pattern) || (!is_null($pattern) && preg_match($pattern, $entry) > 0)) 00174 if(is_file($entry)) 00175 $files[] = $entry; 00176 } 00177 sort($files); 00178 return $files; 00179 }
zFAccess::listSiblingDirs | ( | $ | baseDir, | |
$ | pattern = null | |||
) |
List's all the Directories (No Files will be listed) in the Current Directory You can optionally Specify a Pattern to match (will be matched using preg_match()) Returns all Entries as an Array Returns false on failure.
$baseDir | string | |
$pattern | boolean optional |
Definition at line 190 of file faccess.php.
References perror().
00190 { 00191 if(!is_dir($baseDir)){ 00192 perror("<code>zigmoyd.faccess.listSiblingDirs</code><br />The Directory $baseDir doesn't exist"); 00193 return false; 00194 } 00195 if(!$dh = opendir($baseDir)){ 00196 perror("<code>zigmoyd.faccess.listSiblingDirs</code><br />Failed to open the Directory $baseDir for reading"); 00197 return false; 00198 } 00199 $files = array(); 00200 while(false !== ($entry = readdir($dh))){ 00201 if(is_null($pattern) || (!is_null($pattern) && preg_match($pattern, $entry) > 0)) 00202 if(is_dir($entry)) 00203 $files[] = $entry; 00204 } 00205 sort($files); 00206 return $files; 00207 }
zFAccess::tree | ( | $ | baseDir, | |
$ | pattern = null | |||
) |
Grabs all the Items in the $baseDir Recursively and generates a Highly useful LINEAR array which is Numarically Indexed with Full Paths of the Items as the Value Goes to the Ultimate Depth returns an array of all elements(Both Files and Directory) on Success Returns false on failure.
$baseDir | string | |
$pattern | string optional |
Definition at line 219 of file faccess.php.
References listSiblings().
00219 { 00220 static $tree = array(); 00221 foreach(zFAccess::listSiblings($baseDir, $pattern) as $entry){ 00222 if(!($entry == '.' || $entry == '..')){ 00223 array_push($tree, $baseDir.DRS.$entry); 00224 if(is_dir($baseDir.DRS.$entry)){ 00225 zFAccess::tree($baseDir.DRS.$entry, $pattern); 00226 } 00227 } 00228 } 00229 return $tree; 00230 }
zFAccess::treeDirs | ( | $ | baseDir, | |
$ | pattern = null | |||
) |
Grabs all the Directories(Omits all Files) in the $baseDir Recursively and generates a Highly use full LINEAR array which is Numarically Indexed with Full Paths of the Items as the Value Goes to the Ultimate Depth returns an array of all elements(Just Directories) on Success Returns false on failure.
$baseDir | string | |
$pattern | string optional |
Definition at line 242 of file faccess.php.
References listSiblings(), and perror().
00242 { 00243 static $tree = array(); 00244 foreach(zFAccess::listSiblings($baseDir, $pattern) as $entry){ 00245 if((!($entry == '.' || $entry == '..')) && is_dir($baseDir.DRS.$entry)){ 00246 if(!is_null($pattern)){ 00247 $regx = preg_match($pattern, $entry); 00248 if(is_bool($regx) && !$regx){ 00249 perror("<code>zigmoyd.zFAccess.listSiblings</code><br />Failed to match the Regular expression Provided. Invalid regular expression $pattern Supplied"); 00250 return false; 00251 } 00252 } 00253 if(is_null($pattern) || (!is_null($pattern) && $regx > 0)){ 00254 array_push($tree, $baseDir.DRS.$entry); 00255 } 00256 if(is_dir($baseDir.DRS.$entry)){ 00257 zFAccess::treeDirs($baseDir.DRS.$entry, $pattern); 00258 } 00259 } 00260 } 00261 return $tree; 00262 }
zFAccess::treeFiles | ( | $ | baseDir, | |
$ | pattern = null | |||
) |
Grabs all the Files(Omits all Directories) in the $baseDir Recursively and generates a Highly use full LINEAR array which is Numarically Indexed with Full Paths of the Items as the Value Goes to the Ultimate Depth returns an array of all elements(Just Files) on Success Returns false on failure.
$baseDir | string | |
$pattern | string optional |
Definition at line 274 of file faccess.php.
References listSiblings(), and perror().
00274 { 00275 static $tree = array(); 00276 foreach(zFAccess::listSiblings($baseDir) as $entry){ 00277 if(!($entry == '.' || $entry == '..')){ 00278 if(file_exists($baseDir.DRS.$entry) && !is_dir($baseDir.DRS.$entry)){ 00279 if(!is_null($pattern)){ 00280 $regx = preg_match($pattern, $entry); 00281 if(is_bool($regx) && !$regx){ 00282 perror("<code>zigmoyd.zFAccess.listSiblings</code><br />Failed to match the Regular expression Provided. Invalid regular expression $pattern Supplied"); 00283 return false; 00284 } 00285 } 00286 if(is_null($pattern) || (!is_null($pattern) && $regx > 0)){ 00287 array_push($tree, $baseDir.DRS.$entry); 00288 } 00289 } 00290 if(is_dir($baseDir.DRS.$entry)){ 00291 zFAccess::treeFiles($baseDir.DRS.$entry, $pattern); 00292 } 00293 } 00294 } 00295 return $tree; 00296 }
zFAccess::getPerm | ( | $ | fileName, | |
$ | fullPerm = false | |||
) |
Get the Permission of a File or directory if $fullPerm is given as true returns permission as string like -rw-r--r-- Instead of Octal 0644.
$fileName | string | |
$fullPerm | boolean optional |
Definition at line 305 of file faccess.php.
References perror().
00305 { 00306 if(!file_exists($fileName)){ 00307 perror("<code>zigmoyd.FAccess.getPerm</code><br />The File $fileName does not exists"); 00308 return false; 00309 } 00310 if(!$fullPerm){ 00311 return substr(sprintf('%o', fileperms($fileName)), -4); 00312 }else{ 00313 $perms = fileperms($fileName); 00314 if(($perms & 0xC000) == 0xC000){ 00315 $info = 's'; 00316 }elseif(($perms & 0xA000) == 0xA000){ 00317 $info = 'l'; 00318 }elseif(($perms & 0x8000) == 0x8000){ 00319 $info = '-'; 00320 }elseif(($perms & 0x6000) == 0x6000){ 00321 $info = 'b'; 00322 }elseif(($perms & 0x4000) == 0x4000){ 00323 $info = 'd'; 00324 }elseif(($perms & 0x2000) == 0x2000){ 00325 $info = 'c'; 00326 }elseif(($perms & 0x1000) == 0x1000){ 00327 $info = 'p'; 00328 }else{ 00329 $info = 'u'; 00330 } 00331 $info .= (($perms & 0x0100) ? 'r' : '-'); 00332 $info .= (($perms & 0x0080) ? 'w' : '-'); 00333 $info .= (($perms & 0x0040) ? 00334 (($perms & 0x0800) ? 's' : 'x' ) : 00335 (($perms & 0x0800) ? 'S' : '-')); 00336 $info .= (($perms & 0x0020) ? 'r' : '-'); 00337 $info .= (($perms & 0x0010) ? 'w' : '-'); 00338 $info .= (($perms & 0x0008) ? 00339 (($perms & 0x0400) ? 's' : 'x' ) : 00340 (($perms & 0x0400) ? 'S' : '-')); 00341 $info .= (($perms & 0x0004) ? 'r' : '-'); 00342 $info .= (($perms & 0x0002) ? 'w' : '-'); 00343 $info .= (($perms & 0x0001) ? 00344 (($perms & 0x0200) ? 't' : 'x' ) : 00345 (($perms & 0x0200) ? 'T' : '-')); 00346 return $info; 00347 } 00348 }
zFAccess::setPerm | ( | $ | fileName, | |
$ | perm | |||
) |
Sets the Permission of a File or Directory you must provide an octal permission returns Boolean Success result.
$fileName | string | |
$perm | boolean |
Definition at line 358 of file faccess.php.
References perror().
00358 { 00359 if(!file_exists($fileName)){ 00360 perror("<code>zigmoyd.FAccess.getPerm</code><br />The File $fileName does not exists"); 00361 return false; 00362 } 00363 return chmod($fileName, $perm); 00364 }
zFAccess::copy | ( | $ | src, | |
$ | dest, | |||
$ | recursive = true | |||
) |
Copies Files/Directories from one to another Location recursively or non recursively By defult it Copies recursively returns Boolean success result.
$src | string | |
$dest | string | |
$recursive | boolean optional |
Definition at line 375 of file faccess.php.
References exists(), perror(), read(), and remove().
Referenced by move().
00375 { 00376 if(!zFAccess::exists($src)){ 00377 perror("<code>zigmoyd.zFAccess.copy</code><br />Source File/Directory $src doesnt exists"); 00378 return false; 00379 } 00380 if(!$recursive){ 00381 return copy($src, $dest); 00382 }else{ 00383 if(is_dir($dest))zFAccess::remove($dest); 00384 if(!mkdir($dest)){ 00385 perror("cannot make Directory `$dest`"); 00386 } 00387 $d = dir($src); 00388 while(FALSE !==($entry = $d->read())){ 00389 if($entry == '.' || $entry == '..'){continue;} 00390 $entry = $src . '/' . $entry; 00391 if(is_dir($entry)){ 00392 if(!zFAccess::copy($entry, $dest . '/' . pathinfo($entry, PATHINFO_BASENAME))){ 00393 return false; 00394 } 00395 continue; 00396 } 00397 if(!copy($entry, $dest . '/' . pathinfo($entry, PATHINFO_BASENAME))){ 00398 perror("Couldn't Copy `$entry` to `$dest`"); 00399 return false; 00400 } 00401 } 00402 $d->close(); 00403 return true; 00404 } 00405 }
zFAccess::move | ( | $ | src, | |
$ | dest, | |||
$ | recursive = true | |||
) |
Moves Files/Directories from one to another Location recursively or non recursively By defult it Copies recursively returns Boolean success result.
$src | string | |
$dest | string | |
$recursive | boolean optional |
Definition at line 416 of file faccess.php.
References copy(), perror(), and remove().
00416 { 00417 if(!zFAccess::copy($src, $dest, $recursive)){ 00418 perror("<code>zigmoyd.FAccess.move</code><br />Failed to Copy $src To $dest"); 00419 return false; 00420 } 00421 if(!zFAccess::remove($src, $recursive)){ 00422 perror("<code>zigmoyd.FAccess.move</code><br />Failed to remove Source Directory $src after Copying the Files"); 00423 return false; 00424 } 00425 return true; 00426 }
zFAccess::rename | ( | $ | oldName, | |
$ | newName | |||
) |
Renames a file/Directory returns boolean success Result.
$oldName | string | |
$newName | string |
Definition at line 435 of file faccess.php.
References exists(), and perror().
00435 { 00436 if(!zFAccess::exists($oldName)){ 00437 perror("<code>zigmoyd.FAccess.remove</code><br />source File/Directory $src doesn't exists so removing failed"); 00438 return false; 00439 } 00440 return rename($oldName, $newName); 00441 }
zFAccess::remove | ( | $ | src | ) |
Removes File/Directory Recursively or non Recursively $recursive default to true.
$src | string | |
$recursive | boolean optional |
Definition at line 450 of file faccess.php.
References exists(), and perror().
Referenced by copy(), and move().
00450 { 00451 if(!zFAccess::exists($src)){ 00452 perror("<code>zigmoyd.FAccess.remove</code><br />File/Directory $src doesn't exists"); 00453 return false; 00454 } 00455 if(is_file($src)){ 00456 return unlink($src); 00457 }else{ 00458 foreach(glob($src.'/*') as $sf){ 00459 if(is_dir($sf) && !is_link($sf)){ 00460 zFAccess::remove($sf); 00461 }else{ 00462 unlink($sf); 00463 } 00464 } 00465 return rmdir($src); 00466 } 00467 }
zFAccess::exists | ( | $ | src | ) |
Checks wheather or not a File/Directory Exists.
$src | string |
Definition at line 474 of file faccess.php.
Referenced by copy(), remove(), and rename().
zFAccess::fileExists | ( | $ | src | ) |
Checks wheather or not a File Exists.
$src | string |
Definition at line 483 of file faccess.php.
zFAccess::dirExists | ( | $ | src | ) |
Checks wheather or not a Directory Exists.
$src | string |
Definition at line 492 of file faccess.php.
zFAccess::mkDir | ( | $ | dirName, | |
$ | perm = 0777 , |
|||
$ | recursive = false | |||
) |
Creates a Directory with the Given Permission (Default 0777) with Recursively or Non recursively (Default Recursively).
$dirName | string | |
$perm | octal optional | |
$recursive | boolean optional |
Definition at line 503 of file faccess.php.
References perror().
00503 { 00504 if(!$recursive){ 00505 if(!is_dir(dirname($dirName))){ 00506 perror("<code>zigmoyd.FAccess.mkdir</code><br />Parent Directory of $dirName doesnt Exists plese use recursive Option"); 00507 return false; 00508 } 00509 return mkdir($dirName, $perm); 00510 }else{ 00511 is_dir(dirname($dirName)) || zFAccess::mkDir(dirname($dirName), $perm, $recursive); 00512 return is_dir($dirName) || mkdir($dirName, $perm); 00513 } 00514 }
zFAccess::getExtension | ( | $ | fileName | ) |
get the Extension of a FileName Doesn't Check the existance of the File
$fileName | string |
Definition at line 522 of file faccess.php.
zFAccess::createBlankFile | ( | $ | fileName, | |
$ | projectRelative = true | |||
) |
Creates a Blank File Creates the file in the Current Project Directory if $projectRelative is Given as true(default).
$fileName | string | |
$projectRelative | boolean optional |
Definition at line 534 of file faccess.php.
References write().
00534 { 00535 return zFAccess::write($fileName, '', $projectRelative); 00536 }
zFAccess::getFileSize | ( | $ | fileName, | |
$ | projectRelative = true | |||
) |
Return size of a File searches for the file in the Current Project Directory if $projectRelative is Given as true(default).
$fileName | string | |
$projectRelative | boolean |
Definition at line 545 of file faccess.php.
References perror().
00545 { 00546 if($projectRelative){ 00547 $fileName = realpath(Z_PROJECT_ROOT.DRS.ltrim($fileName, '/')); 00548 } 00549 if(!file_exists($fileName)){ 00550 perror("<code>zigmoyd.FAccess.getFileSize</code><br />File $fileName doesn't exist"); 00551 return false; 00552 } 00553 return filesize($fileName); 00554 }