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:

$registry = GeneralUtility::makeInstance(\Cobweb\Svconnector\Registry\ConnectorRegistry::class);
$connector = $registry->getServiceForType('csv');

An additional step could be to check if the service is indeed available, by calling $connector->isAvailable(), although - in this particular case - the CSV connector service is always available.

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

$parameters = [
        'filename' => 'path/to/your/file',
        'delimiter' => “\t”,
        'text_qualifier' => '',
        'encoding' => 'utf-8',
        'skip_rows' => 1,
];
$data = $connector->fetchArray($parameters);

In this 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

The resulting array stored in $data in the example above 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().