CSVLoanParser

Extends \APAPI\Parser\CSVParser

Parse loan CSV data

Implements a CSV parser to convert loan CSV data into a proper array that may be used with the API. The parse implementation provides simple data type checking, to ensure in some cases proper values are passed (for instance it converts boolean true|false to string '0'|'1' as that's the expected value in the API). It also provides two static functions to create ready to be used parser instances: withHeaders and withFile.

withHeaders creates a parser from an array of header information:

$parser = CSVLoanParser(array('foo', 'bar', 'baz'));

withFile creates a parser from a CSV file, and treats the first line as header information so it's not necessary to set it independently:

$parser = CSVLoanParser(array('foo', 'bar', 'baz'));

Methods

Create a new instance with headers

withHeaders(array $headers) : \APAPI\Parser\CSVLoanParser
static

Create a new parser instance using the header information passed as argument.

Arguments

$headers

array

The headers to use

Response

\APAPI\Parser\CSVLoanParser

Create a new instance from a file

withFile(string $file) : \APAPI\Parser\CSVLoanParser|bool
static

Create a new parser instance using a file as starting point. The first line is considered header information. Returns the new instance, or false otherwise.

Arguments

$file

string

Path to the file to use

Response

\APAPI\Parser\CSVLoanParser|bool

Parse a data row

parse(array $row) : array|bool

Concrete implementation of the parse function. Parses a data row, performs type conversion when necessary. Fields not present in the valid fields array are not included in the resulting array. If there's an exception parsing the data row, returns false

Arguments

$row

array

The data row to parse

Response

array|bool

setHeaders

setHeaders(array $headers) 
inherited

Set the headers to use

Arguments

$headers

array

The headers

getHeaders

getHeaders() : array
inherited

Get the current headers in use

Response

array

parseFile

parseFile(string $file) : array|bool
inherited

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

Properties


                                
inherited


                                
inherited


                                
inherited


                                
inherited


                                
inherited

headers

headers
inherited

Stores headers in use by this parser


                                
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