[pLog-svn] r5824 - plog/trunk/class/file

oscar at devel.lifetype.net oscar at devel.lifetype.net
Tue Aug 14 17:03:37 EDT 2007


Author: oscar
Date: 2007-08-14 17:03:37 -0400 (Tue, 14 Aug 2007)
New Revision: 5824

Modified:
   plog/trunk/class/file/file.class.php
Log:
Turned the File::exists() into a real static class and added the $recursive parameter to File::createFolder() to determine whether we realy want to use its recursive behaviour or not.


Modified: plog/trunk/class/file/file.class.php
===================================================================
--- plog/trunk/class/file/file.class.php	2007-08-14 21:02:39 UTC (rev 5823)
+++ plog/trunk/class/file/file.class.php	2007-08-14 21:03:37 UTC (rev 5824)
@@ -307,29 +307,42 @@
 		  * @static
 		  * @param dirName The name of the new folder
 		  * @param mode Attributes that will be given to the folder
+		  * @param recursive
 		  * @return Returns true if no problem or false otherwise.
 		  */
 		 function createDir( $dirName, 
-		                     $mode = File::FILE_DEFAULT_DIRECTORY_CREATION_MODE )
+		                     $mode = File::FILE_DEFAULT_DIRECTORY_CREATION_MODE,
+		 					 $recursive = true )
 		 {
-             if(File::exists($dirName)) return true;
+             if( File::exists( $dirName )) return true;
 
              if(substr($dirName, strlen($dirName)-1) == "/" ){
                  $dirName = substr($dirName, 0,strlen($dirName)-1);
              }
 
-             // for example, we will create dir "/a/b/c"
-             // $firstPart = "/a/b"
-             $firstPart = substr($dirName,0,strrpos($dirName, "/" ));           
+			 if( $recursive ) {
+	             // for example, we will create dir "/a/b/c"
+	             // $firstPart = "/a/b"
+	             $firstPart = substr($dirName,0,strrpos($dirName, "/" ));           
 
-             if(file_exists($firstPart)){
-                 if(!mkdir($dirName,$mode)) return false;
-			     chmod( $dirName, $mode );
-             } else {
-                 File::createDir($firstPart,$mode);
-                 if(!mkdir($dirName,$mode)) return false;
-			     chmod( $dirName, $mode );
-         	}
+	             if(file_exists($firstPart)){
+	                 if(!mkdir($dirName,$mode)) return false;
+				     chmod( $dirName, $mode );
+	             } else {
+	                 File::createDir( $firstPart, $mode, $recursive );
+	                 if(!mkdir($dirName,$mode)) return false;
+				     chmod( $dirName, $mode );
+	         	}
+			}
+			else {
+				if( mkdir( $dirName )) {
+					chmod( $dirName, $mode );
+					return( true );
+				}
+				else {
+					return( false );
+				}
+			}
 			 
 			 return true;
 		 }
@@ -460,12 +473,10 @@
 		  * @param fileName optinally, name of the file whose existance we'd
 		  * like to check
 		  * @return true if successful or false otherwise
+		  * @static 
 		  */
-		 function exists( $fileName = null ) 
+		 static function exists( $fileName ) 
 		 {
-			 if( $fileName == null )
-				 $fileName = $this->_fileName;
-				 
 			clearstatcache();
 			 
 			 return file_exists( $fileName );



More information about the pLog-svn mailing list