/** * 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; }
/** * 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; }