public function load($source)
    {
        if ($source instanceof File) {
            $resource = $source->readStream();
        } else {
            if (!is_file($source)) {
                throw new InvalidArgumentException("Expected CSV file '" . $source . "' could not be open.");
            }
            if (!is_readable($source)) {
                throw new InvalidArgumentException("CSV file '" . $source . "' is not readable.");
            }
            $resource = fopen($source, 'r');
        }

        // More readable variables
        $enclosure = preg_quote($this->options['field_encloser'], '/');
        $delimiter = $this->options['field_delimiter'];
        $multiValueSeparator = $this->options['multi_values_delimiter'];

        $adle = ini_get('auto_detect_line_endings');
        ini_set('auto_detect_line_endings', true);

        if ($this->options['first_row_column_names']) {
            $fields = fgetcsv($resource, 0, $delimiter, $enclosure);
            $this->setColumnMapping($fields);
        }

        $data = array();
        while (($rowFields = fgetcsv($resource, 0, $delimiter, $enclosure)) !== false) {
            $lineData = [];
            foreach ($rowFields as $fieldData) {
                // If there is nothing in the cell, replace by null for abstraction consistency.
                if ($fieldData == '') {
                    $fieldData = null;
                } elseif (!empty($multiValueSeparator) && mb_strpos($fieldData, $multiValueSeparator) !== false) {
                    // try to split by multi_value_delimiter
                    $multiField = [];
                    foreach (explode($multiValueSeparator, $fieldData) as $item) {
                        if (!empty($item)) {
                            $multiField[] = $item;
                        }
                    }
                    $fieldData = $multiField;
                }
                $lineData[] = $fieldData;
            }
            $data[] = $lineData;

            // Update the column count.
            $currentRowColumnCount = count($rowFields);
            if ($this->getColumnCount() < $currentRowColumnCount) {
                $this->setColumnCount($currentRowColumnCount);
            }

        }
        ini_set('auto_detect_line_endings', $adle);
        fclose($resource);
        $this->setData($data);
    }
public function load($source)
    {
        if ($source instanceof File) {
            $resource = $source->readStream();
        } else {
            if (!is_file($source)) {
                throw new InvalidArgumentException("Expected CSV file '" . $source . "' could not be open.");
            }
            if (!is_readable($source)) {
                throw new InvalidArgumentException("CSV file '" . $source . "' is not readable.");
            }
            $resource = fopen($source, 'r');
        }

        // More readable variables
        $enclosure = preg_quote($this->options['field_encloser'], '/');
        $delimiter = $this->options['field_delimiter'];
        $multiValueSeparator = $this->options['multi_values_delimiter'];

        $adle = ini_get('auto_detect_line_endings');
        ini_set('auto_detect_line_endings', true);

        if ($this->options['first_row_column_names']) {
            $fields = fgetcsv($resource, 0, $delimiter, $enclosure);
            $this->setColumnMapping($fields);
        }

        $data = array();
        while (($rowFields = fgetcsv($resource, 0, $delimiter, $enclosure)) !== false) {
            $lineData = [];
            foreach ($rowFields as $fieldData) {
                // If there is nothing in the cell, replace by null for abstraction consistency.
                if ($fieldData == '') {
                    $fieldData = null;
                } elseif (!empty($multiValueSeparator) && mb_strpos($fieldData, $multiValueSeparator) !== false) {
                    // try to split by multi_value_delimiter
                    $multiField = [];
                    foreach (explode($multiValueSeparator, $fieldData) as $item) {
                        if (!empty($item)) {
                            $multiField[] = $item;
                        }
                    }
                    $fieldData = $multiField;
                }
                $lineData[] = $fieldData;
            }
            $data[] = $lineData;

            // Update the column count.
            $currentRowColumnCount = count($rowFields);
            if ($this->getColumnCount() < $currentRowColumnCount) {
                $this->setColumnCount($currentRowColumnCount);
            }

        }
        ini_set('auto_detect_line_endings', $adle);
        fclose($resource);
        $this->setData($data);
    }
public function load ( $ source ) { if ( $ source instanceof File ) { $ resource = $ source -> readStream ( ) ; } else { if ( ! is_file ( $ source ) ) { throw new InvalidArgumentException ( "Expected CSV file '" . $ source . "' could not be open." ) ; } if ( ! is_readable ( $ source ) ) { throw new InvalidArgumentException ( "CSV file '" . $ source . "' is not readable." ) ; } $ resource = fopen ( $ source , 'r' ) ; } // More readable variables
 $ enclosure = preg_quote ( $ this -> options [ 'field_encloser' ] , '/' ) ; $ delimiter = $ this -> options [ 'field_delimiter' ] ; $ multiValueSeparator = $ this -> options [ 'multi_values_delimiter' ] ; $ adle = ini_get ( 'auto_detect_line_endings' ) ; ini_set ( 'auto_detect_line_endings' , true ) ; if ( $ this -> options [ 'first_row_column_names' ] ) { $ fields = fgetcsv ( $ resource , 0 , $ delimiter , $ enclosure ) ; $ this -> setColumnMapping ( $ fields ) ; } $ data = array ( ) ; while ( ( $ rowFields = fgetcsv ( $ resource , 0 , $ delimiter , $ enclosure ) ) !== false ) { $ lineData = [ ] ; foreach ( $ rowFields as $ fieldData ) { // If there is nothing in the cell, replace by null for abstraction consistency.
 if ( $ fieldData == '' ) { $ fieldData = null ; } elseif ( ! empty ( $ multiValueSeparator ) && mb_strpos ( $ fieldData , $ multiValueSeparator ) !== false ) { // try to split by multi_value_delimiter
 $ multiField = [ ] ; foreach ( explode ( $ multiValueSeparator , $ fieldData ) as $ item ) { if ( ! empty ( $ item ) ) { $ multiField [ ] = $ item ; } } $ fieldData = $ multiField ; } $ lineData [ ] = $ fieldData ; } $ data [ ] = $ lineData ; // Update the column count.
 $ currentRowColumnCount = count ( $ rowFields ) ; if ( $ this -> getColumnCount ( ) < $ currentRowColumnCount ) { $ this -> setColumnCount ( $ currentRowColumnCount ) ; } } ini_set ( 'auto_detect_line_endings' , $ adle ) ; fclose ( $ resource ) ; $ this -> setData ( $ data ) ; }
Load the file and parse csv lines

Extract headers if `first_row_column_names` is in $this->options

@access public
@author Jerome Bogaerts, <jerome.bogaerts@tudor.lu>
@param  string $source
@return void
Load the file and parse csv lines