public function test_register_filter()
 {
     ConvertMbstringEncoding::register();
     $filterName = ConvertMbstringEncoding::getFilterName();
     $registeredFilters = stream_get_filters();
     $this->assertTrue(in_array($filterName, $registeredFilters));
 }
Beispiel #2
0
 /**
  * {@inherit}
  */
 public function parse($filename, InterpreterInterface $interpreter)
 {
     ini_set('auto_detect_line_endings', true);
     // For mac's office excel csv
     $delimiter = $this->config->getDelimiter();
     $enclosure = $this->config->getEnclosure();
     $escape = $this->config->getEscape();
     $fromCharset = $this->config->getFromCharset();
     $toCharset = $this->config->getToCharset();
     $flags = $this->config->getFlags();
     $ignoreHeader = $this->config->getIgnoreHeaderLine();
     if ($fromCharset === null) {
         $url = $filename;
     } else {
         $url = ConvertMbstringEncoding::getFilterURL($filename, $fromCharset, $toCharset);
     }
     $csv = new SplFileObject($url);
     $csv->setCsvControl($delimiter, $enclosure, $escape);
     $csv->setFlags($flags);
     $originalLocale = setlocale(LC_ALL, '0');
     // Backup current locale
     setlocale(LC_ALL, 'en_US.UTF-8');
     foreach ($csv as $lineNumber => $line) {
         if ($ignoreHeader && $lineNumber == 0 || count($line) === 1 && empty($line[0])) {
             continue;
         }
         $interpreter->interpret($line);
     }
     parse_str(str_replace(';', '&', $originalLocale), $locale_array);
     setlocale(LC_ALL, $locale_array);
     // Reset locale
 }
Beispiel #3
0
 /**
  * {@inherit}
  */
 public function parse($filename, InterpreterInterface $interpreter)
 {
     ini_set('auto_detect_line_endings', true);
     // For mac's office excel csv
     $delimiter = $this->config->getDelimiter();
     $enclosure = $this->config->getEnclosure();
     $escape = $this->config->getEscape();
     $fromCharset = $this->config->getFromCharset();
     $toCharset = $this->config->getToCharset();
     if ($fromCharset === null) {
         $url = $filename;
     } else {
         $url = ConvertMbstringEncoding::getFilterURL($filename, $fromCharset, $toCharset);
     }
     $csv = new SplFileObject($url);
     $csv->setCsvControl($delimiter, $enclosure, $escape);
     $csv->setFlags(SplFileObject::READ_CSV);
     $originalLocale = setlocale(LC_ALL, '0');
     // Backup current locale
     setlocale(LC_ALL, 'en_US.UTF-8');
     foreach ($csv as $line) {
         $interpreter->interpret($line);
     }
     setlocale(LC_ALL, $originalLocale);
     // Reset locale
 }