Wrapper for fgetcsv function

@return array|null|false
771065
private function read()
    {
        $out = fgetcsv($this->handle, null, $this->delimiter, $this->enclosure);

        if (!is_array($out)) {
            return $out;
        }

        if ($this->encodingFrom !== null && $this->encodingTo !== null) {
            foreach ($out as $k => $v) {
                $out[$k] = iconv($this->encodingFrom, $this->encodingTo, $v);
            }
        }

        return $out;
    }
918668
protected function get_file() {
        if (!$this->file) {
            return null;
        }
        // The get_file_by_id call can return false, so normalise to null.
        $file = get_file_storage()->get_file_by_id($this->file);
        return ($file) ? $file : null;
    }
835139
private function getFieldValues()
    {
        $requestFields = [];
        if (!empty($this->payload->body) && !is_string($this->payload->body)) {
            $this->tokenHelper->newSession(
                $this->contactClient,
                $this->contact,
                $this->payload,
                $this->campaign,
                $this->event
            );
            $requestFields = $this->fieldValues($this->payload->body);
            if ($this->file) {
                $nullCsv = $this->file->getCsvNull();
                if (!empty($nullCsv)) {
                    foreach ($requestFields as $field => &$value) {
                        if (empty($value) && false !== $value) {
                            $value = $nullCsv;
                        }
                    }
                }
                // Filter out exclusion characters.
                $exclusions = $this->file->getExclusions();
                if (!empty($exclusions)) {
                    $exclusionArray = array_unique(str_split($exclusions));
                    foreach ($requestFields as $field => &$value) {
                        $value = str_replace($exclusionArray, ' ', $value);
                    }
                }
            }
        }

        return $requestFields;
    }
841023
protected function getNextDataSet()
    {
        $set = $this->file->fgetcsv($this->delimiter, $this->enclosure, $this->escape);

        if (is_array($set) && 1 === count($set) && null === $set[0]) {
            if ($this->skipEmptyLines && !$this->file->eof()) {
                return $this->getNextDataSet();
            }

            return null;
        }

        if ($this->removeBom) {
            if (substr($set[0], 0, 3) == pack("CCC", 0xef, 0xbb, 0xbf)) {
                $set[0] = substr($set[0], 3);
            }
            $this->removeBom = false;
        }

        $set = $this->convertEncoding($set);

        $this->line++;

        return $set;
    }
1256771
public function readCSV($data)
    {
        $content = array();
        if (!file_exists($data['uploadTranslate']['tmp_name'])) {
            return false;
        }
        if (($handle = fopen($data['uploadTranslate']['tmp_name'], "r")) === false) {
            return false;
        }
    
        while (($cols = fgetcsv($handle, 0, "\t")) !== false) {
            foreach ($cols as $row) {
                $rowTab = explode(";", $row);
                if (!empty($rowTab[0]) && !empty($rowTab[1])) {
                    $content[$rowTab[0]] = $rowTab[1];
                }
            }
        }

        return $content;
    }
917319
private static function getFopen()
    {
        if (\count($args = func_get_args()) === 1) {
            $args = $args[0];
        }

        $uri      = $args[0];
        $options  = $args[1] ?? [];
        $callback = $args[2] ?? null;

        if ($callback) {
            $options['fopen']['notification'] = ['self', 'progress'];
        }

        if (isset($options['fopen']['ssl'])) {
            $ssl = $options['fopen']['ssl'];
            unset($options['fopen']['ssl']);

            $stream  = stream_context_create([
                'http' => $options['fopen'],
                'ssl' => $ssl
            ], $options['fopen']);
        } else {
            $stream  = stream_context_create(['http' => $options['fopen']], $options['fopen']);
        }


        $content = @file_get_contents($uri, false, $stream);

        if ($content === false) {
            $code = null;
            // Function file_get_contents() creates local variable $http_response_header, check it
            if (isset($http_response_header)) {
                $code = explode(' ', $http_response_header[0] ?? '')[1] ?? null;
            }

            switch ($code) {
                case '404':
                    throw new \RuntimeException('Page not found');
                case '401':
                    throw new \RuntimeException('Invalid LICENSE');
                default:
                    throw new \RuntimeException("Error while trying to download (code: {$code}): {$uri}\n");
            }
        }

        return $content;
    }
29198
public function getCsvFiles()
    {
        // parse what's in cache before returning results
        while ($batch = $this->cache->getNext()) {
            // root node is always array
            $this->parse($batch["data"], new NodePath([$batch['type'], Structure::ARRAY_NAME]), $batch["parentId"]);
        }
        return $this->csvFiles;
    }
1260068
protected function getCsvDelimiter()
    {
        if ($this->hasOption(self::CSV_DELIMITER_OPTION)) {
            return $this->getOption(self::CSV_DELIMITER_OPTION);
        }

        return self::CSV_DELIMITER;
    }
46876
public function readElement()
  {
    $csv_line_data = $this->spl_file_object->fgetcsv();
    if($csv_line_data)
    {
      $csv_line_data[0] = $this->convertToUtf8($csv_line_data);
      if($this->isValidLine($csv_line_data))
      {
        $csv_line         = array_combine($this->columns_name, $csv_line_data);
        // we cast it to StdClass
        return (object)$csv_line;
      }
    }

    return false;
  }
947387
public function parseCsv($file)
    {
        $handle = fopen($file, 'r');

        if (!is_resource($handle)) {
            return array();
        }

        $content = array();

        while (($data = fgetcsv($handle)) !== false) {
            $content[] = $data;
        }

        fclose($handle);
        return $content;
    }
346386
public function stringArrayToCsv()
    {
        $value = $this->getParameter('value');
        if (!is_array($value)) {
            $value = explode($this->getParameter('delimiter', ','), $value);
        }

        $value = array_map('trim', $value);
        if (empty($value)) {
            return '';
        }
        $value = array_filter($value, 'strlen');

        if ($this->getParameter('lowercase', false)) {
            $value = array_map('strtolower', $value);
            if ($this->getParameter('unique', true)) {
                $value = array_keys(array_flip($value));
            }
        } else {
            if ($this->getParameter('unique', true)) {
                $value = array_values(array_intersect_key($value, array_unique(array_map('strtolower', $value))));
            }
        }

        return implode(',', $value);
    }
981780
public function getBytes()
    {
        if ($this->isDirty && $this->bytes) {
            return $this->bytes;
        }
        if ($this->isDirty && $this->filename) {
            return file_get_contents($this->filename);
        }
        if ($this->mongoGridFSFile instanceof \MongoGridFSFile) {
            return $this->mongoGridFSFile->getBytes();
        }
        return null;
    }
276214
public function read()
	{
		
		$csvPath = self::buildCsvFilePath($this->prefectureCode);
		
		$buf = mb_convert_encoding(
			file_get_contents($csvPath), 
			mb_internal_encoding(), 
			'sjis-win'
		);
		
		return $buf;
		
	}
773538
public function getFileContents()
        {
            if ($this->fileContentsCache === null && $filePath = $this->getFile()) {

                // Return null if the file doesn't actually exist - this may
                // happen in cases where the filename is provided as, for
                // example, 'Unknown'
                if (!File::exists($filePath)) {
                    return null;
                }

                $this->fileContentsCache = File::read($filePath);
            }

            return $this->fileContentsCache;
        }
951671
public function getCSV($array)
    {
        ob_start(); // buffer the output ...
        $out = fopen('php://output', 'w');
        fputcsv($out, array_keys($array[0]), ";");
        array_shift($array);
        foreach ($array as $line) {
            fputcsv($out, $line, ";");
        }
        fclose($out);
        return ob_get_clean(); // ... then return it as a string!
    }
748011
public function parse_sv( $data = null, $delimiter = null ) {

		if ( ! empty( $data ) ) {
			$this->input = $data;
		}

		if ( ! empty( $delimiter ) ) {
			$this->delimiter = $delimiter;
		}

		$rows = $this->str_getcsv( $this->input, '\n' );

		if ( empty( $rows ) || 2 > count( $rows ) ) {
			return false;
		}

		$data = array(
			'columns' => array(),
			'items'   => array(),
		);

		foreach ( $rows as $key => $row ) {
			if ( 0 === $key ) {
				$data['columns'] = $this->str_getcsv( $row, $this->delimiter );
			} else {
				$row = $this->str_getcsv( $row, $this->delimiter );

				$data['items'][ $key ] = array();

				foreach ( $data['columns'] as $ckey => $column ) {
					$data['items'][ $key ][ $column ] = ( isset( $row[ $ckey ] ) ? $row[ $ckey ] : '' );

					if ( 'NULL' === $data['items'][ $key ][ $column ] ) {
						$data['items'][ $key ][ $column ] = null;
					}
				}
			}
		}

		$this->parsed = $data;

		return $this->parsed;
	}
1157141
public function init() {
        global $CFG, $USER;

        if (!empty($this->_fp)) {
            $this->close();
        }
        $filename = $CFG->tempdir.'/csvimport/'.$this->_type.'/'.$USER->id.'/'.$this->_iid;
        if (!file_exists($filename)) {
            return false;
        }
        if (!$this->_fp = fopen($filename, "r")) {
            return false;
        }
        //skip header
        return (fgetcsv($this->_fp) !== false);
    }