Example #1
0
 /**
  * Load CSV data from the file identified by the current hash. If no hash is
  * set, this method does nothing.
  * @return void
  * @throws \Exception If the hash-identified file doesn't exist.
  */
 public function loadData()
 {
     if (!$this->hash) {
         return;
     }
     $file_path = Config::storageDirTmp('import') . '/' . $this->hash;
     if (!file_exists($file_path)) {
         throw new \Exception("No import was found with the identifier ‘{$this->hash}’");
     }
     // Get all rows.
     $this->data = array();
     $file = fopen($file_path, 'r');
     while ($line = fgetcsv($file)) {
         $this->data[] = $line;
     }
     fclose($file);
     // Extract headers.
     $this->headers = $this->data[0];
     unset($this->data[0]);
 }