Readers
The three readers are final readonly classes of the Silarhi\Cfonb namespace, without state: one instance can parse
any number of files.
Cfonb120Reader
Section titled “Cfonb120Reader”use Silarhi\Cfonb\Cfonb120Reader;
$reader = new Cfonb120Reader();$statements = $reader->parse($content);| Member | Description |
|---|---|
parse(string $content, bool $strict = true): array |
Parses the contents of a CFONB 120 file into a list of Statement |
LINE_LENGTH |
120, the length of a line |
$strict = false turns blank operation references into empty strings instead of errors:
strict mode.
Cfonb240Reader
Section titled “Cfonb240Reader”use Silarhi\Cfonb\Cfonb240Reader;
$reader = new Cfonb240Reader();$transfers = $reader->parse($content);| Member | Description |
|---|---|
parse(string $content, bool $strict = true): array |
Parses the contents of a CFONB 240 file into a list of Transfer |
LINE_LENGTH |
240, the length of a line |
$strict has no effect on CFONB 240 files.
CfonbReader
Section titled “CfonbReader”Both formats behind one object, e.g. a single service to inject:
use Silarhi\Cfonb\Banking\Statement;use Silarhi\Cfonb\Banking\Transfer;use Silarhi\Cfonb\CfonbReader;
$reader = new CfonbReader();
foreach ($reader->parseCfonb120('My Content') as $statement) { assert($statement instanceof Statement);}
foreach ($reader->parseCfonb240('My Content') as $transfer) { assert($transfer instanceof Transfer);}| Member | Description |
|---|---|
__construct(Cfonb120Reader $cfonb120Reader = new …, Cfonb240Reader $cfonb240Reader = new …) |
The readers to delegate to |
parseCfonb120(string $content, bool $strict = true): array |
Cfonb120Reader::parse() |
parseCfonb240(string $content, bool $strict = true): array |
Cfonb240Reader::parse() |
$contentis the contents of the file, not its path: read it withfile_get_contents()or from an upload.- Lines are separated by
\n,\r\nor\r(\rsince 6.5); a file without line breaks is split everyLINE_LENGTHcharacters. Empty lines, and line breaks at the start and the end, are ignored; a line of spaces or tabs is not, and throws aParseException. - The characters are kept as they are: no encoding conversion, only the whitespace around each field is trimmed.
- An empty string gives an empty list.
The readers accept an optional FileParser in their constructor: it is internal (Silarhi\Cfonb\Parser), and not
meant to be replaced.
Errors
Section titled “Errors”parse() throws a ParseException on the first line it cannot parse: nothing is returned for
the lines before it.
