当前位置: 首页>>代码示例>>PHP>>正文


PHP SplFileObject::setCsvControl方法代码示例

本文整理汇总了PHP中SplFileObject::setCsvControl方法的典型用法代码示例。如果您正苦于以下问题:PHP SplFileObject::setCsvControl方法的具体用法?PHP SplFileObject::setCsvControl怎么用?PHP SplFileObject::setCsvControl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SplFileObject的用法示例。


在下文中一共展示了SplFileObject::setCsvControl方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: open

 /**
  * Open stream from a source
  *      A source can be anything: for instance a db, a file, or a socket
  *
  * @param String $path
  * @return void
  * @throws \Palmabit\Library\Exceptions\CannotOpenFileException
  */
 public function open($path)
 {
     $this->convertToLF($path);
     $this->spl_file_object = new SplFileObject($path);
     $this->spl_file_object->setCsvControl($this->delimiter);
     $this->columns_name = $this->spl_file_object->fgetcsv();
 }
开发者ID:palmabit,项目名称:library,代码行数:15,代码来源:CsvFileReader.php

示例2: __construct

 /**
  * @param \SplFileObject $file
  * @param string         $delimiter
  * @param string         $enclosure
  * @param string         $escape
  */
 public function __construct(\SplFileObject $file, $delimiter = ',', $enclosure = '"', $escape = '\\')
 {
     ini_set('auto_detect_line_endings', true);
     $this->file = $file;
     $this->file->setFlags(\SplFileObject::READ_CSV | \SplFileObject::SKIP_EMPTY | \SplFileObject::READ_AHEAD | \SplFileObject::DROP_NEW_LINE);
     $this->file->setCsvControl($delimiter, $enclosure, $escape);
 }
开发者ID:megamanhxh,项目名称:data-import,代码行数:13,代码来源:CsvReader.php

示例3: getFile

 /**
  * @return \SplFileObject
  */
 protected function getFile()
 {
     if (!$this->file instanceof \SplFileObject) {
         $this->file = $this->fileInfo->openFile();
         $this->file->setFlags(\SplFileObject::READ_CSV | \SplFileObject::READ_AHEAD | \SplFileObject::DROP_NEW_LINE);
         $this->file->setCsvControl($this->delimiter, $this->enclosure, $this->escape);
         if ($this->firstLineIsHeader && !$this->header) {
             $this->header = $this->file->fgetcsv();
         }
     }
     return $this->file;
 }
开发者ID:ashutosh-srijan,项目名称:findit_akeneo,代码行数:15,代码来源:CsvFileReader.php

示例4: __construct

 public function __construct($fileName)
 {
     parent::__construct();
     $this->fileName = $fileName;
     try {
         $this->fileHandle = new \SplFileObject($fileName, 'c+');
         $this->fileHandle->setFlags(\SplFileObject::READ_CSV);
         $this->fileHandle->setCsvControl(self::CSV_DELIMITER, self::CSV_SEPARATOR);
     } catch (\Exception $exception) {
         throw new PinqException('Invalid cache file: %s is not readable with the message, "%s"', $fileName, $exception->getMessage());
     }
     $this->fileName = $fileName;
 }
开发者ID:timetoogo,项目名称:pinq,代码行数:13,代码来源:CSVFileCache.php

示例5: loadResource

 /**
  * {@inheritdoc}
  */
 protected function loadResource($resource)
 {
     $messages = array();
     try {
         $file = new \SplFileObject($resource, 'rb');
     } catch (\RuntimeException $e) {
         throw new NotFoundResourceException(sprintf('Error opening file "%s".', $resource), 0, $e);
     }
     $file->setFlags(\SplFileObject::READ_CSV | \SplFileObject::SKIP_EMPTY);
     $file->setCsvControl($this->delimiter, $this->enclosure, $this->escape);
     foreach ($file as $data) {
         if (substr($data[0], 0, 1) === '#') {
             continue;
         }
         if (!isset($data[1])) {
             continue;
         }
         if (count($data) == 2) {
             $messages[$data[0]] = $data[1];
         } else {
             continue;
         }
     }
     return $messages;
 }
开发者ID:niyomja,项目名称:laravel_redis,代码行数:28,代码来源:CsvFileLoader.php

示例6: load

 /**
  * {@inheritdoc}
  *
  * @api
  */
 public function load($resource, $locale, $domain = 'messages')
 {
     $messages = array();
     try {
         $file = new \SplFileObject($resource, 'rb');
     } catch (\RuntimeException $e) {
         throw new \InvalidArgumentException(sprintf('Error opening file "%s".', $resource));
     }
     $file->setFlags(\SplFileObject::READ_CSV | \SplFileObject::SKIP_EMPTY);
     $file->setCsvControl($this->delimiter, $this->enclosure, $this->escape);
     foreach ($file as $data) {
         if (substr($data[0], 0, 1) === '#') {
             continue;
         }
         if (!isset($data[1])) {
             continue;
         }
         if (count($data) == 2) {
             $messages[$data[0]] = $data[1];
         } else {
             continue;
         }
     }
     $catalogue = parent::load($messages, $locale, $domain);
     $catalogue->addResource(new FileResource($resource));
     return $catalogue;
 }
开发者ID:robertowest,项目名称:CuteFlow-V4,代码行数:32,代码来源:CsvFileLoader.php

示例7: load

 /**
  * {@inheritdoc}
  */
 public function load($resource, $locale, $domain = 'messages')
 {
     if (!stream_is_local($resource)) {
         throw new InvalidResourceException(sprintf('This is not a local file "%s".', $resource));
     }
     if (!file_exists($resource)) {
         throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource));
     }
     $messages = array();
     try {
         $file = new \SplFileObject($resource, 'rb');
     } catch (\RuntimeException $e) {
         throw new NotFoundResourceException(sprintf('Error opening file "%s".', $resource), 0, $e);
     }
     $file->setFlags(\SplFileObject::READ_CSV | \SplFileObject::SKIP_EMPTY);
     $file->setCsvControl($this->delimiter, $this->enclosure, $this->escape);
     foreach ($file as $data) {
         if ('#' !== substr($data[0], 0, 1) && isset($data[1]) && 2 === count($data)) {
             $messages[$data[0]] = $data[1];
         }
     }
     $catalogue = parent::load($messages, $locale, $domain);
     if (class_exists('Symfony\\Component\\Config\\Resource\\FileResource')) {
         $catalogue->addResource(new FileResource($resource));
     }
     return $catalogue;
 }
开发者ID:Dren-x,项目名称:mobit,代码行数:30,代码来源:CsvFileLoader.php

示例8: read

 /**
  * {@inheritdoc}
  */
 public function read()
 {
     if (null === $this->csv) {
         if (mime_content_type($this->filePath) === 'application/zip') {
             $this->extractZipArchive();
         }
         $this->csv = new \SplFileObject($this->filePath);
         $this->csv->setFlags(\SplFileObject::READ_CSV | \SplFileObject::READ_AHEAD | \SplFileObject::SKIP_EMPTY | \SplFileObject::DROP_NEW_LINE);
         $this->csv->setCsvControl($this->delimiter, $this->enclosure, $this->escape);
         $this->fieldNames = $this->csv->fgetcsv();
     }
     $data = $this->csv->fgetcsv();
     if (false !== $data) {
         if ($data === array(null) || $data === null) {
             return null;
         }
         if ($this->stepExecution) {
             $this->stepExecution->incrementSummaryInfo('read');
         }
         if (count($this->fieldNames) !== count($data)) {
             throw new InvalidItemException('pim_base_connector.steps.csv_reader.invalid_item_columns_count', $data, array('%totalColumnsCount%' => count($this->fieldNames), '%itemColumnsCount%' => count($data), '%csvPath%' => $this->csv->getRealPath(), '%lineno%' => $this->csv->key()));
         }
         $data = array_combine($this->fieldNames, $data);
     } else {
         throw new \RuntimeException('An error occured while reading the csv.');
     }
     return $data;
 }
开发者ID:NoelCamille,项目名称:pim-community-dev,代码行数:31,代码来源:CsvReader.php

示例9: insert

 public function insert($file, array $callback, $scan_info)
 {
     $class = $callback[0];
     $method = $callback[1];
     $class = Model::factory($class);
     $this->_handle = fopen($file, 'r');
     $headers = fgetcsv($this->_handle, $file);
     $scan_data = array();
     $file = new SplFileObject($file);
     $file->setFlags(SplFileObject::SKIP_EMPTY);
     $file->setFlags(SplFileObject::READ_AHEAD);
     $file->setFlags(SplFileObject::READ_CSV);
     $file->setCsvControl(",", '"', "\"");
     $c = 0;
     foreach ($file as $row) {
         $c++;
         if (count($row) === count($headers)) {
             $scan_data[] = array_combine($headers, $row);
             $row = array();
         }
         if ($c % $this->insert_threshold == 0) {
             Logger::msg('info', array('message' => 'flushing ' . $this->insert_threshold . ' rows', "class" => $callback[0], "method" => $callback[1], 'rows_inserted' => $c));
             Logger::msg('info', array('memory_usage' => $this->file_size(memory_get_usage())));
             $flush = $class->{$method}($scan_data, $scan_info);
             $scan_data = array();
         }
     }
     $flush = $class->{$method}($scan_data, $scan_info);
     $scan_data = array();
     Logger::msg('info', array('memory_usage' => $this->file_size(memory_get_usage())));
     return $c;
 }
开发者ID:pombredanne,项目名称:vulnDB,代码行数:32,代码来源:csv.php

示例10: exportedFileOfShouldContain

 /**
  * @param string       $code
  * @param PyStringNode $csv
  *
  * @Then /^exported file of "([^"]*)" should contain:$/
  *
  * @throws ExpectationException
  * @throws \Exception
  */
 public function exportedFileOfShouldContain($code, PyStringNode $csv)
 {
     $config = $this->getFixturesContext()->getJobInstance($code)->getRawConfiguration();
     $path = $this->getMainContext()->getSubcontext('job')->getJobInstancePath($code);
     if (!is_file($path)) {
         throw $this->getMainContext()->createExpectationException(sprintf('File "%s" doesn\'t exist', $path));
     }
     $delimiter = isset($config['delimiter']) ? $config['delimiter'] : ';';
     $enclosure = isset($config['enclosure']) ? $config['enclosure'] : '"';
     $escape = isset($config['escape']) ? $config['escape'] : '\\';
     $csvFile = new \SplFileObject($path);
     $csvFile->setFlags(\SplFileObject::READ_CSV | \SplFileObject::READ_AHEAD | \SplFileObject::SKIP_EMPTY | \SplFileObject::DROP_NEW_LINE);
     $csvFile->setCsvControl($delimiter, $enclosure, $escape);
     $expectedLines = [];
     foreach ($csv->getLines() as $line) {
         if (!empty($line)) {
             $expectedLines[] = explode($delimiter, str_replace($enclosure, '', $line));
         }
     }
     $actualLines = [];
     while ($data = $csvFile->fgetcsv()) {
         if (!empty($data)) {
             $actualLines[] = array_map(function ($item) use($enclosure) {
                 return str_replace($enclosure, '', $item);
             }, $data);
         }
     }
     $expectedCount = count($expectedLines);
     $actualCount = count($actualLines);
     assertSame($expectedCount, $actualCount, sprintf('Expecting to see %d rows, found %d', $expectedCount, $actualCount));
     if (md5(json_encode($actualLines[0])) !== md5(json_encode($expectedLines[0]))) {
         throw new \Exception(sprintf('Header in the file %s does not match expected one: %s', $path, implode(' | ', $actualLines[0])));
     }
     unset($actualLines[0]);
     unset($expectedLines[0]);
     foreach ($expectedLines as $expectedLine) {
         $originalExpectedLine = $expectedLine;
         $found = false;
         foreach ($actualLines as $index => $actualLine) {
             // Order of columns is not ensured
             // Sorting the line values allows to have two identical lines
             // with values in different orders
             sort($expectedLine);
             sort($actualLine);
             // Same thing for the rows
             // Order of the rows is not reliable
             // So we generate a hash for the current line and ensured that
             // the generated file contains a line with the same hash
             if (md5(json_encode($actualLine)) === md5(json_encode($expectedLine))) {
                 $found = true;
                 // Unset line to prevent comparing it twice
                 unset($actualLines[$index]);
                 break;
             }
         }
         if (!$found) {
             throw new \Exception(sprintf('Could not find a line containing "%s" in %s', implode(' | ', $originalExpectedLine), $path));
         }
     }
 }
开发者ID:SamirBoulil,项目名称:pim-community-dev,代码行数:69,代码来源:ExportProfilesContext.php

示例11: readRecords

 /**
  * Reads csv records
  *
  * @param string $fileName
  * @param int $position
  * @param int $step
  * @return array
  * @throws \Exception
  */
 public function readRecords($fileName, $position, $step)
 {
     $tempFileName = '';
     if (file_exists($fileName)) {
         $tempFileName = $this->uploadPathProvider->getRealPath(md5(microtime() . '.csv'));
         file_put_contents($tempFileName, file_get_contents($fileName));
         $fileName = $tempFileName;
     }
     $file = new \SplFileObject($fileName);
     $file->setCsvControl(";", '"');
     $file->setFlags(\SplFileObject::READ_CSV);
     $columnNames = $this->getColumnNames($file);
     //moves the file pointer to a certain line
     // +1 to ignore the first line of the file
     $file->seek($position + 1);
     $readRows = [];
     $data = [];
     for ($i = 1; $i <= $step; $i++) {
         $row = $file->current();
         if ($this->isInvalidRecord($row)) {
             break;
         }
         foreach ($columnNames as $key => $name) {
             $data[$name] = isset($row[$key]) ? $row[$key] : '';
         }
         $readRows[] = $data;
         // Move the pointer to the next line
         $file->next();
     }
     unlink($tempFileName);
     return $this->toUtf8($readRows);
 }
开发者ID:shopwareLabs,项目名称:SwagImportExport,代码行数:41,代码来源:CsvFileReader.php

示例12: initializeRead

 /**
  * Initialize read process by extracting zip if needed, setting CSV options
  * and settings field names.
  */
 protected function initializeRead()
 {
     if (mime_content_type($this->filePath) === 'application/zip') {
         $this->extractZipArchive();
     }
     $this->csv = new \SplFileObject($this->filePath);
     $this->csv->setFlags(\SplFileObject::READ_CSV | \SplFileObject::READ_AHEAD | \SplFileObject::SKIP_EMPTY | \SplFileObject::DROP_NEW_LINE);
     $this->csv->setCsvControl($this->delimiter, $this->enclosure, $this->escape);
     $this->fieldNames = $this->csv->fgetcsv();
 }
开发者ID:vpetrovych,项目名称:pim-community-dev,代码行数:14,代码来源:CsvReader.php

示例13: initializeRead

 /**
  * Initialize read process by extracting zip if needed, setting CSV options
  * and settings field names.
  */
 protected function initializeRead()
 {
     // TODO mime_content_type is deprecated, use Symfony\Component\HttpFoundation\File\MimeTypeMimeTypeGuesser?
     if ('application/zip' === mime_content_type($this->filePath)) {
         $this->extractZipArchive();
     }
     $this->csv = new \SplFileObject($this->filePath);
     $this->csv->setFlags(\SplFileObject::READ_CSV | \SplFileObject::READ_AHEAD | \SplFileObject::SKIP_EMPTY | \SplFileObject::DROP_NEW_LINE);
     $this->csv->setCsvControl($this->delimiter, $this->enclosure, $this->escape);
     $this->fieldNames = $this->csv->fgetcsv();
 }
开发者ID:umpirsky,项目名称:pim-community-dev,代码行数:15,代码来源:CsvReader.php

示例14: getRows

 public function getRows($chemin)
 {
     //jLog::dump($chemin);
     $csv = new SplFileObject($chemin, 'r');
     $csv->setFlags(SplFileObject::READ_CSV);
     $csv->setCsvControl(',');
     $rows = array();
     $i = 0;
     foreach ($csv as $ligne) {
         $rows[$i] = $ligne;
         $i++;
     }
     return $rows;
 }
开发者ID:aurellemeless,项目名称:favoris,代码行数:14,代码来源:import.class.php

示例15: all

 /**
  *
  * @return array
  */
 private function all($resource)
 {
     try {
         $file = new \SplFileObject($resource, 'rb');
     } catch (\RuntimeException $e) {
         throw new \InvalidArgumentException(sprintf('Error opening file "%s".', $resource));
     }
     $file->setFlags(\SplFileObject::SKIP_EMPTY | \SplFileObject::READ_CSV);
     $file->setCsvControl(';');
     $lines = array();
     // iterate over the file's rows
     // fgets increments file descriptor to next line
     while ($data = $file->fgetcsv()) {
         $lines[] = $data;
     }
     return $lines;
 }
开发者ID:2lenet,项目名称:TranslatorBundle,代码行数:21,代码来源:CsvDumper.php


注:本文中的SplFileObject::setCsvControl方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。