alt="Latest Stable Version"> alt="CI Status"> CFONB Parser Parse French CFONB 120 and 240 bank files into typed PHP objects. Bank statements and transfers, with zero runtime dependencies. 📖 Documentation Features Zero dependencies — only PHP is required, nothing else gets pulled into your project. CFONB 120 statements — Statement objects with opening/closing balances (01/07), operations (04) and their details (05)…
Zero dependencies — only PHP is required, nothing else gets pulled into your project.
CFONB 120 statements — Statement objects with opening/closing balances (01/07), operations (04) and their details (05).
CFONB 240 transfers — Transfer objects with a header (31), transactions (34) and a total (39).
Signed amounts — CFONB 120 decimals and sign characters are decoded: credits are positive, debits are negative.
Exact amounts — since 6.6, every amount is also an exact decimal string (getAmount(true), "-22.79"), to store and add without float errors.
Consistency checks — since 6.6, validate() checks that a statement’s operations belong to its account and add up to its closing balance, and that a transfer’s transactions add up to its total.
SEPA details — since 6.7, the payer, beneficiary, remittance information, end-to-end reference and mandate of an operation, decoded from its 05 records by getSepaInformation().
IBAN — since 6.7, getAccount() computes the RIB key and the IBAN of an account.
Operation codes as an enum — since 6.7, getOperationCode() returns an OperationCode with its label, direction and SWIFT code.
Large files — since 6.7, iterateFile() reads a file line by line and yields one statement or transfer at a time; CfonbReader::parse() detects the format.
JSON — since 6.7, every object has a toArray() and is JsonSerializable.
Typed value objects — getters return floats, dates (DateTimeImmutable for CFONB 120, typed DateTimeInterface for CFONB 240) and nullable strings, not raw arrays.
Tolerant input — handles \n, \r\n and \r (since 6.5) line endings, and files with no line breaks at all.
Strict parsing — malformed lines and, since 6.5, records out of order and zero-filled dates throw a ParseException instead of producing silent garbage, whatever the mode: non-strict mode only accepts blank CFONB 120 operation references. Since 6.6, its message keeps the line (account numbers, labels) out: getRawContent() returns it.
Requirements
PHP 8.2+
Installation
composer require silarhi/cfonb-parser
Quick start
use Silarhi\Cfonb\Cfonb120Reader;
$reader = new Cfonb120Reader();
foreach ($reader->parse(file_get_contents('statements.txt')) as $statement) {
echo sprintf("Opening balance: %.2f\n", $statement->getOldBalance()->getAmount());
foreach ($statement->getOperations() as $operation) {
echo sprintf("%s %s %.2f\n", $operation->getDate()->format('Y-m-d'), $operation->getLabel(), $operation->getAmount());
}
echo sprintf("Closing balance: %.2f\n", $statement->getNewBalance()->getAmount());
}
CFONB 240 transfers are read the same way with Cfonb240Reader, both formats with CfonbReader.
评论