コード例 #1
0
ファイル: CsvReader.php プロジェクト: AgenceStratis/migrator
 /**
  * CsvReader constructor.
  * @param Configuration $config
  * @throws \Exception
  */
 public function __construct(Configuration $config)
 {
     $filename = $config->get(array('filename'));
     $delimiter = $config->get(array('delimiter'), ',');
     $header = $config->get(array('header'), true);
     parent::__construct(new \SplFileObject($filename), $delimiter);
     if ($header) {
         $this->setHeaderRowNumber(0);
     }
 }
コード例 #2
0
 /**
  *
  * @param string $jotFormUrl        	
  * @param string|null $password        	
  * @throws UnableToRetrieveCsvFile
  */
 public function __construct($jotFormUrl, $password = null)
 {
     // My Constructor
     $this->jotFormUrl = $jotFormUrl;
     $this->password = $password;
     $downloadHelper = new JotFormDownloadHelper();
     // Download CSV-File from jotForm
     $filePath = $downloadHelper->downloadFromJotForm($jotFormUrl, $password);
     $splFile = $downloadHelper->fileNameToSplFile($filePath);
     // Parent Construct
     parent::__construct($splFile, $delimiter = ',', $enclosure = '"', $escape = "\n");
     $this->file->seek(0);
     // jotForm Specific CSV-Options
     $this->setHeaderRowNumber(0, CsvReader::DUPLICATE_HEADERS_INCREMENT);
     $this->file->setFlags(\SplFileObject::READ_CSV | \SplFileObject::READ_AHEAD | \SplFileObject::SKIP_EMPTY);
     // Sometimes the CSV-Entry contains a "," at the end and sometimes not
     // Stupid jotForm
     $this->setStrict(false);
 }