CSVParser

Extends \APAPI\Parser\Parser

Base CSV Parser

Implements functionality that all CSV Parsers must have. Implementation of the inherited abstract parse method is left to concrete classes.

Methods

setHeaders

setHeaders(array $headers) 

Set the headers to use

Arguments

$headers

array

The headers

getHeaders

getHeaders() : array

Get the current headers in use

Response

array

parseFile

parseFile(string $file) : array|bool

Reads a CSV file and executes a concrete parse method on each one, returning an array of parsed rows (or false if the file can't be read). The first line is not parsed, as it's considered headers which must be set prior to calling parseFile via setHeaders

Arguments

$file

string

Path to the CSV file on disc

Response

array|bool

Get valid fields

getValidFields(string $type) : array
inherited

Get which fields are considered valid in a specific Parser subclass. The mechanism is very simple: valid fields are declared as protected properties in the subclass, and named with a typeValidFields nomenclature.

Example:

class CSVActivateParser extends CSVParser {
    protected $activateValidFields = array(
        "loanid"    => "loanId",
        "activate"  => "activate"
    );
}

In this case 'activate' is the type, so to get this class valid fields:

getValidFields('activate');

Arguments

$type

string

The valid fields type

Response

array

Parse row

parse(array $row) : array
inherited abstract

Abstract function that must be implemented by subclasses to define the parsing strategy.

Arguments

$row

array

The current row to parse

Response

array

Properties


                                
inherited


                                
inherited


                                
inherited


                                
inherited


                                
inherited


                                
inherited


                                
inherited


                                
inherited


                                
inherited


                                
inherited


                                
inherited


                                
inherited


                                
inherited


                                
inherited


                                
inherited


                                
inherited


                                
inherited


                                
inherited


                                
inherited


                                
inherited


                                
inherited


                                
inherited


                                
inherited


                                
inherited


                                
inherited


                                
inherited


                                
inherited


                                
inherited


                                
inherited


                                
inherited


                                
inherited


                                
inherited


                                
inherited