Base CSV Parser
Implements functionality that all CSV Parsers must have. Implementation of the inherited abstract parse method is left to concrete classes.
setHeaders(array $headers)
Set the headers to use
array
The headers
getHeaders() : array
Get the current headers in use
array
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
string
Path to the CSV file on disc
array|bool
getValidFields(string $type) : array
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');
string
The valid fields type
array
parse(array $row) : array
Abstract function that must be implemented by subclasses to define the parsing strategy.
array
The current row to parse
array