Developer's manual

Reading a flat file using the CSV connector service becomes a really easy task. The first step is to get the proper service object with the desired parameters:

$parameters = [
   'filename' => 'path/to/your/file',
   'delimiter' => "\t",
   'text_qualifier' => '',
   'encoding' => 'utf-8',
   'skip_rows' => 1,
];
$registry = GeneralUtility::makeInstance(\Cobweb\Svconnector\Registry\ConnectorRegistry::class);
$connector = $registry->getServiceForType('csv');
Copied!

The next step is simply to call the appropriate method from the API depending on which format you want to have in return. For a PHP array:

$data = $connector->fetchArray($parameters);
Copied!

In the above example we declare the file as using tabs as delimiter and no text qualifier. Furthermore the file is declared as being encoded in UTF-8 and its first line should be ignored.

Let's assume the file looks something like this:

last_name	first_name
Wellington	Nicholas
Oshiro	Ki
Duncan	Dwayne
Copied!

The resulting array stored in $data will be:

last_name first_name
Wellington Nicholas
Oshiro Ki
Duncan Dwayne

The fetchRaw() method returns a two-dimensional array with one entry per line in the file and in each of these an entry per column. The fetchXML() method returns the array created by fetchArray() transformed to XML using \TYPO3\CMS\Core\Utility\GeneralUtility::array2xml_cs().