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

oscar at devel.lifetype.net oscar at devel.lifetype.net
Wed Aug 8 16:31:19 EDT 2007


Author: oscar
Date: 2007-08-08 16:31:18 -0400 (Wed, 08 Aug 2007)
New Revision: 5804

Modified:
   plog/trunk/class/file/file.class.php
   plog/trunk/class/file/fileproperties.class.php
Log:
Some cleanup work in this class:
- added File::readContents() and renamed readFile() to readToArray() as it better describes what the method does and modified all classes that used that method.
- Moved the mode creation constant to be come a class constant.
- Added a few '@' modifiers to suppress error output by php


Modified: plog/trunk/class/file/file.class.php
===================================================================
--- plog/trunk/class/file/file.class.php	2007-08-08 20:27:37 UTC (rev 5803)
+++ plog/trunk/class/file/file.class.php	2007-08-08 20:31:18 UTC (rev 5804)
@@ -7,13 +7,9 @@
 	 * is the most useful once, since provides OOP wrappers around some PHP
 	 * functions that work with files.
      */
-
-
 	 
 	 lt_include( PLOG_CLASS_PATH."class/misc/glob.class.php" );
 
-	 define( "FILE_DEFAULT_DIRECTORY_CREATION_MODE", 0700 );
-
     /**
 	 * \ingroup File
 	 *
@@ -23,6 +19,8 @@
 	 */
 	 class File  
 	 {
+		
+		const FILE_DEFAULT_DIRECTORY_CREATION_MODE = 0700;
 
 		 var $_fileName;
 		 var $_handler;
@@ -52,7 +50,7 @@
 		  */
 		 function open( $mode = "r" )
 		 {
-			 $this->_handler = fopen( $this->_fileName, $mode );
+			 $this->_handler = @fopen( $this->_fileName, $mode );
 			 
 			 $this->_mode = $mode;
 			 
@@ -76,7 +74,7 @@
 		  *
 		  * @return An array where every position is a line from the file.
 		  */
-		 function readFile()
+		 function readToArray()
 		 {
 			 $contents = Array();
 			 
@@ -87,6 +85,16 @@
 			 
 			 return $contents;
 		 }
+		
+		/**
+		 * Reads the entire content of the file into memory
+		 *
+		 * @return The file contents as a string 
+		 */
+		function readContents()
+		{
+			return( file_get_contents( $this->_fileName ));
+		}
 		 
 		 /**
 		  * Reads bytes from the currently opened file
@@ -118,7 +126,7 @@
 		  */
 		 function write( $data )
 		 {
-			 return fwrite( $this->_handler, $data );
+			 return( @fwrite( $this->_handler, $data ));
 		 }
 		 
 		 /**
@@ -302,7 +310,7 @@
 		  * @return Returns true if no problem or false otherwise.
 		  */
 		 function createDir( $dirName, 
-		                     $mode = FILE_DEFAULT_DIRECTORY_CREATION_MODE )
+		                     $mode = File::FILE_DEFAULT_DIRECTORY_CREATION_MODE )
 		 {
              if(File::exists($dirName)) return true;
 
@@ -335,7 +343,7 @@
 		 {
 			 return( chdir( $dir ));
 		 }
-		 
+				 
 		 /**
 		  * returns a temporary filename in a pseudo-random manner
 		  *

Modified: plog/trunk/class/file/fileproperties.class.php
===================================================================
--- plog/trunk/class/file/fileproperties.class.php	2007-08-08 20:27:37 UTC (rev 5803)
+++ plog/trunk/class/file/fileproperties.class.php	2007-08-08 20:31:18 UTC (rev 5804)
@@ -48,7 +48,7 @@
 			// open and load the contents of the file
 			$this->_file->open( "r" );
 
-			$this->_contents = $this->_file->readFile();
+			$this->_contents = $this->_file->readToArray();
 		}
 
 		/**



More information about the pLog-svn mailing list