Ejemplo n.º 1
0
 /**
  *
  * @param  string $str
  * @param  string $from
  * @param  string $to
  * @return string
  */
 protected function convertEncoding($str, $from, $to)
 {
     return $str !== false ? Converter::convertEncoding($str, $from, $to, $this->dialect->getTranslit()) : $str;
 }
Ejemplo n.º 2
0
 /**
  *
  * @param  resource|null $fileHandler
  * @return array
  *
  * @throws \InvalidArgumentException
  */
 protected function readLine($fileHandler)
 {
     $row = null;
     if (!is_resource($fileHandler)) {
         throw new \InvalidArgumentException('A valid file handler resource must be passed as parameter.');
     }
     if (!feof($fileHandler)) {
         $enclosure = $this->dialect->getEnclosure();
         $escape = $this->dialect->getEscape();
         $line = fgetcsv($fileHandler, null, $this->dialect->getDelimiter(), $enclosure, $escape);
         if ($line !== false) {
             $trim = $this->dialect->getTrim();
             $translit = $this->dialect->getTranslit();
             $detectedEncoding = $this->detectedEncoding;
             if ($this->position <= 0) {
                 $line[0] = $this->removeBom($line[0]);
             }
             $row = array_map(function ($var) use($enclosure, $escape, $trim, $translit, $detectedEncoding) {
                 // workaround when escape char is not equals to double quote
                 if ($enclosure === '"' && $escape !== $enclosure) {
                     $var = str_replace($escape . $enclosure, $enclosure, $var);
                 }
                 $var = Converter::convertEncoding($var, $detectedEncoding, 'UTF-8', $translit);
                 return $trim ? trim($var) : $var;
             }, $line);
             $notEmptyCount = count(array_filter($row, function ($var) {
                 return $var !== false && $var !== null && $var !== '';
             }));
             if ($this->dialect->getSkipEmptyLines() && 0 === $notEmptyCount) {
                 $row = false;
             }
         }
     }
     return $row;
 }