Ejemplo n.º 1
0
 /**
  * Skip any BOM in the file
  */
 private function _skipBom()
 {
     $bom = $this->_file->fgetc() . $this->_file->fgetc() . $this->_file->fgetc();
     // If there is no bom, then remove bom will return a 3 character string.
     // In that case the file position must be reset to the start of the file
     if (\MUtil_Encoding::removeBOM($bom)) {
         $this->_file->rewind();
     }
 }
Ejemplo n.º 2
0
 /**
  * Open the file and optionally restore the position
  *
  * @return void
  */
 private function _openFile()
 {
     $this->_fieldMap = array();
     $this->_fieldMapCount = 0;
     if (!file_exists($this->_filename)) {
         $this->_file = false;
         return;
     }
     try {
         $this->_file = new \SplFileObject($this->_filename, 'r');
         $firstline = trim(\MUtil_Encoding::removeBOM($this->_file->current(), "\r\n"));
         if ($firstline) {
             $this->_fieldMap = call_user_func($this->_splitFunction, $firstline);
             $this->_fieldMapCount = count($this->_fieldMap);
             // Check for fields, do not run when empty
             if (0 === $this->_fieldMapCount) {
                 $this->_file = false;
                 return;
             }
         }
         // Restore old file position if any
         if (null !== $this->_filepos) {
             $this->_file->fseek($this->_filepos, SEEK_SET);
         }
         // Always move to next, even if there was no first line
         $this->next();
     } catch (\Exception $e) {
         $this->_file = false;
     }
 }