Example #1
0
 /**
  * Return or create the file descriptor associated with a file
  *
  * @param string $file The name of the file
  * @param array  &$conf The configuration
  * @param string $mode The open node (ex: FILE_MODE_READ or FILE_MODE_WRITE)
  * @param boolean $reset if passed as true and resource for the file exists
  *                       than the file pointer will be moved to the beginning
  *
  * @return mixed A file resource or false
  */
 function getPointer($file, &$conf, $mode = FILE_MODE_READ, $reset = false)
 {
     static $resources = array();
     static $config;
     if (isset($resources[$file][$mode])) {
         $conf = $config;
         if ($reset) {
             fseek($resources[$file][$mode], 0);
         }
         return $resources[$file][$mode];
     }
     File_CSV::_conf($error, $conf);
     if ($error) {
         return File_CSV::raiseError($error);
     }
     $config = $conf;
     PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
     $fp = File::_getFilePointer($file, $mode);
     PEAR::popErrorHandling();
     if (PEAR::isError($fp)) {
         return File_CSV::raiseError($fp);
     }
     $resources[$file][$mode] = $fp;
     return $fp;
 }
Example #2
0
 /**
  * Return or create the file descriptor associated with a file
  *
  * @param string $file The name of the file
  * @param array  &$conf The configuration
  * @param string $mode The open node (ex: FILE_MODE_READ or FILE_MODE_WRITE)
  *
  * @return mixed A file resource or false
  */
 function getPointer($file, &$conf, $mode = FILE_MODE_READ)
 {
     static $resources = array();
     static $config;
     if (isset($resources[$file])) {
         $conf = $config;
         return $resources[$file];
     }
     File_CSV::_conf($conf, $error);
     if ($error) {
         return File_CSV::raiseError($error);
     }
     $config = $conf;
     PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
     $fp =& File::_getFilePointer($file, $mode);
     PEAR::popErrorHandling();
     if (PEAR::isError($fp)) {
         return File_CSV::raiseError($fp);
     }
     $resources[$file] = $fp;
     if ($mode == FILE_MODE_READ && !empty($conf['header'])) {
         if (!File_CSV::read($file, $conf)) {
             return false;
         }
     }
     return $fp;
 }
Example #3
0
 /**
  * This unlocks a locked file pointer.
  * 
  * @access  public 
  * @param   string  $filename The filename that was opened
  * @param   string  $mode Mode the file was opened in
  * @return  mixed   PEAR Error on error, true otherwise
  */
 function unlock($filename, $mode)
 {
     if (PEAR::isError($fp =& File::_getFilePointer($filename, $mode))) {
         return $fp;
     }
     if (!@flock($fp, LOCK_UN)) {
         return PEAR::raiseError("Cacnnot unlock file: {$filename}");
     }
     return true;
 }
Example #4
0
 /**
  * This closes an open file pointer
  *
  * @access public
  * @param  string $filename The filename that was opened
  * @param  string $mode     Mode the file was opened in
  * @return mixed            PEAR Error on error, true otherwise
  */
 function close($filename, $mode)
 {
     if (!PEAR::isError($fp =& File::_getFilePointer($filename, $mode))) {
         $filePointers =& PEAR::getStaticProperty('File', 'filePointers');
         unset($filePointers[$filename][$mode]);
         return fclose($fp) ? true : PEAR::raiseError('Failed to close file: ' . $filename);
     }
     return $fp;
 }