{"id":34933298,"url":"https://github.com/silarhi/cfonb-parser","last_synced_at":"2026-01-29T14:12:43.495Z","repository":{"id":45921172,"uuid":"253896771","full_name":"silarhi/cfonb-parser","owner":"silarhi","description":"A zero dependencies PHP parser for CFONB 120 / 240 format","archived":false,"fork":false,"pushed_at":"2025-12-26T16:46:48.000Z","size":839,"stargazers_count":12,"open_issues_count":0,"forks_count":8,"subscribers_count":3,"default_branch":"6.x","last_synced_at":"2025-12-28T03:54:44.630Z","etag":null,"topics":["cfonb","cfonb-parser","ebics","parser","php"],"latest_commit_sha":null,"homepage":"https://silarhi.fr","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/silarhi.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2020-04-07T19:50:16.000Z","updated_at":"2025-12-26T16:46:48.000Z","dependencies_parsed_at":"2026-01-29T14:04:23.243Z","dependency_job_id":null,"html_url":"https://github.com/silarhi/cfonb-parser","commit_stats":null,"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"purl":"pkg:github/silarhi/cfonb-parser","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/silarhi%2Fcfonb-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/silarhi%2Fcfonb-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/silarhi%2Fcfonb-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/silarhi%2Fcfonb-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/silarhi","download_url":"https://codeload.github.com/silarhi/cfonb-parser/tar.gz/refs/heads/6.x","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/silarhi%2Fcfonb-parser/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28879103,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-29T10:31:27.438Z","status":"ssl_error","status_checked_at":"2026-01-29T10:31:01.017Z","response_time":59,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cfonb","cfonb-parser","ebics","parser","php"],"created_at":"2025-12-26T17:32:29.250Z","updated_at":"2026-01-29T14:12:43.486Z","avatar_url":"https://github.com/silarhi.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cfonb-parser\n\n![Build Status](https://github.com/silarhi/cfonb-parser/actions/workflows/continuous-integration.yml/badge.svg?branch=6.x)\n[![Latest Stable Version](https://poser.pugx.org/silarhi/cfonb-parser/v/stable)](https://packagist.org/packages/silarhi/cfonb-parser)\n[![Total Downloads](https://poser.pugx.org/silarhi/cfonb-parser/downloads)](https://packagist.org/packages/silarhi/cfonb-parser)\n[![License](https://poser.pugx.org/silarhi/cfonb-parser/license)](https://packagist.org/packages/silarhi/cfonb-parser)\n\nA zero dependencies PHP Parser for CFONB statements\n\nSupports CFONB 120/240 format\n\n## Installation\n\nThe preferred method of installation is via [Composer][]. Run the following\ncommand to install the package and add it as a requirement to your project's\n`composer.json`:\n\n```bash\ncomposer require silarhi/cfonb-parser\n```\n\n## How to use\n\n### Parse CFONB 120\n\n```php\n\u003c?php\n\nuse Silarhi\\Cfonb\\Cfonb120Reader;\n\n$reader = new Cfonb120Reader();\n\n//Gets all statements day by day\nforeach($reader-\u003eparse('My Content') as $statement) {\n  if ($statement-\u003ehasOldBalance()) {\n    echo sprintf(\"Old balance : %f\\n\", $statement-\u003egetOldBalance()-\u003egetAmount());\n  }\n  foreach($statement-\u003egetOperations() as $operation) {\n    //Gets all statement operations\n  }\n  \n  if ($statement-\u003ehasNewBalance()) {\n    echo sprintf(\"New balance : %f\\n\", $statement-\u003egetNewBalance()-\u003egetAmount());\n  }\n}\n```\n\n#### Reading CFONB 120 from file\n\n```php\n\u003c?php\n\nuse Silarhi\\Cfonb\\Cfonb120Reader;\n\n$reader = new Cfonb120Reader();\n$content = file_get_contents('/path/to/cfonb120-file.txt');\n\nforeach($reader-\u003eparse($content) as $statement) {\n    // Process each daily statement\n    echo \"Statement date: \" . $statement-\u003egetOldBalance()-\u003egetDate()-\u003eformat('Y-m-d') . \"\\n\";\n}\n```\n\n#### Detailed operation processing\n\n```php\n\u003c?php\n\nuse Silarhi\\Cfonb\\Cfonb120Reader;\n\n$reader = new Cfonb120Reader();\n\nforeach($reader-\u003eparse($content) as $statement) {\n    foreach($statement-\u003egetOperations() as $operation) {\n        echo \"Date: \" . $operation-\u003egetDate()-\u003eformat('Y-m-d') . \"\\n\";\n        echo \"Value Date: \" . $operation-\u003egetValueDate()-\u003eformat('Y-m-d') . \"\\n\";\n        echo \"Amount: \" . $operation-\u003egetAmount() . \"\\n\";\n        echo \"Label: \" . $operation-\u003egetLabel() . \"\\n\";\n        echo \"Reference: \" . $operation-\u003egetReference() . \"\\n\";\n        echo \"Bank Code: \" . $operation-\u003egetBankCode() . \"\\n\";\n        echo \"Account: \" . $operation-\u003egetAccountNumber() . \"\\n\";\n        \n        // Access optional fields\n        if ($operation-\u003egetInternalCode()) {\n            echo \"Internal Code: \" . $operation-\u003egetInternalCode() . \"\\n\";\n        }\n        \n        // Process operation details (additional information)\n        foreach($operation-\u003egetDetails() as $detail) {\n            echo \"Additional Info: \" . $detail-\u003egetAdditionalInformations() . \"\\n\";\n        }\n        \n        echo \"---\\n\";\n    }\n}\n```\n\n#### Using strict mode (default) vs non-strict mode\n\n```php\n\u003c?php\n\nuse Silarhi\\Cfonb\\Cfonb120Reader;\nuse Silarhi\\Cfonb\\Exceptions\\ParseException;\n\n$reader = new Cfonb120Reader();\n\n// Strict mode (default) - throws exception on parsing errors\ntry {\n    $statements = $reader-\u003eparse($content); // strict=true by default\n} catch (ParseException $e) {\n    echo \"Parsing error: \" . $e-\u003egetMessage() . \"\\n\";\n}\n\n// Non-strict mode - continues parsing despite errors\n$statements = $reader-\u003eparse($content, false); // strict=false\n```\n\n### Parse CFONB 240\n\n```php\n\u003c?php\n\nuse Silarhi\\Cfonb\\Cfonb240Reader;\nuse Silarhi\\Cfonb\\Banking\\Transfer;\n\n$reader = new Cfonb240Reader();\n\nforeach($reader-\u003eparse('My Content') as $transfer) {\n    assert($transfer instanceof Transfer);\n}\n```\n\n#### Detailed CFONB 240 transfer processing\n\n```php\n\u003c?php\n\nuse Silarhi\\Cfonb\\Cfonb240Reader;\n\n$reader = new Cfonb240Reader();\n\nforeach($reader-\u003eparse($content) as $transfer) {\n    // Access transfer header information\n    $header = $transfer-\u003egetHeader();\n    echo \"Transfer Date: \" . $header-\u003egetPrevTransactionFileDate()-\u003eformat('Y-m-d') . \"\\n\";\n    echo \"Bank Code: \" . $header-\u003egetRecipientBankCode1() . \"\\n\";\n    echo \"Account: \" . $header-\u003egetRecipientAccountNumber1() . \"\\n\";\n    \n    // Process all transactions in the transfer\n    foreach($transfer-\u003egetTransactions() as $transaction) {\n        echo \"Transaction Date: \" . $transaction-\u003egetSettlementDate()-\u003eformat('Y-m-d') . \"\\n\";\n        echo \"Amount: \" . $transaction-\u003egetTransactionAmount() . \"\\n\";\n        echo \"Recipient: \" . $transaction-\u003egetRecipientName1() . \"\\n\";\n        echo \"Reference: \" . $transaction-\u003egetPresenterReference() . \"\\n\";\n    }\n    \n    // Access transfer total\n    $total = $transfer-\u003egetTotal();\n    echo \"Total Amount: \" . $total-\u003egetTotalAmount() . \"\\n\";\n    echo \"Sequence Number: \" . $total-\u003egetSequenceNumber() . \"\\n\";\n}\n```\n\n#### Reading CFONB 240 from file with error handling\n\n```php\n\u003c?php\n\nuse Silarhi\\Cfonb\\Cfonb240Reader;\nuse Silarhi\\Cfonb\\Exceptions\\ParseException;\nuse Silarhi\\Cfonb\\Exceptions\\HeaderUnavailableException;\n\n$reader = new Cfonb240Reader();\n\ntry {\n    $content = file_get_contents('/path/to/cfonb240-file.txt');\n    \n    foreach($reader-\u003eparse($content) as $transfer) {\n        // Safely access optional header\n        try {\n            $header = $transfer-\u003egetHeader();\n            echo \"Processing transfer from: \" . $header-\u003egetRecipientBankCode1() . \"\\n\";\n        } catch (HeaderUnavailableException $e) {\n            echo \"Transfer header not available\\n\";\n        }\n        \n        // Process transactions...\n    }\n} catch (ParseException $e) {\n    echo \"Failed to parse CFONB file: \" . $e-\u003egetMessage() . \"\\n\";\n}\n```\n\n### Parse both CFONB 120 and CFONB 240\n\n```php\n\u003c?php\n\nuse Silarhi\\Cfonb\\CfonbReader;\nuse Silarhi\\Cfonb\\Banking\\Statement;\nuse Silarhi\\Cfonb\\Banking\\Transfer;\n\n$reader = new CfonbReader();\n\nforeach($reader-\u003eparseCfonb120('My Content') as $statement) {\n    assert($statement instanceof Statement);\n}\n\nforeach($reader-\u003eparseCfonb240('My Content') as $transfer) {\n    assert($transfer instanceof Transfer);\n}\n```\n\n## Advanced Usage Examples\n\n### Processing bank statements with filtering\n\n```php\n\u003c?php\n\nuse Silarhi\\Cfonb\\Cfonb120Reader;\nuse Silarhi\\Cfonb\\Banking\\Operation;\n\n$reader = new Cfonb120Reader();\n$statements = $reader-\u003eparse($content);\n\n// Filter operations by amount\nforeach ($statements as $statement) {\n    $largeOperations = array_filter(\n        $statement-\u003egetOperations(), \n        fn(Operation $op) =\u003e abs($op-\u003egetAmount()) \u003e 1000\n    );\n    \n    foreach ($largeOperations as $operation) {\n        echo \"Large operation: {$operation-\u003egetAmount()} - {$operation-\u003egetLabel()}\\n\";\n    }\n}\n```\n\n### Building a transaction summary\n\n```php\n\u003c?php\n\nuse Silarhi\\Cfonb\\Cfonb120Reader;\n\n$reader = new Cfonb120Reader();\n$statements = $reader-\u003eparse($content);\n\n$summary = [\n    'total_debit' =\u003e 0,\n    'total_credit' =\u003e 0,\n    'operation_count' =\u003e 0\n];\n\nforeach ($statements as $statement) {\n    foreach ($statement-\u003egetOperations() as $operation) {\n        $amount = $operation-\u003egetAmount();\n        if ($amount \u003e 0) {\n            $summary['total_credit'] += $amount;\n        } else {\n            $summary['total_debit'] += abs($amount);\n        }\n        $summary['operation_count']++;\n    }\n}\n\necho \"Summary:\\n\";\necho \"Total Credits: {$summary['total_credit']}\\n\";\necho \"Total Debits: {$summary['total_debit']}\\n\";\necho \"Operation Count: {$summary['operation_count']}\\n\";\n```\n\n### Converting to array for API usage\n\n```php\n\u003c?php\n\nuse Silarhi\\Cfonb\\Cfonb120Reader;\n\n$reader = new Cfonb120Reader();\n$statements = $reader-\u003eparse($content);\n\n$data = [];\nforeach ($statements as $statement) {\n    $statementData = [\n        'date' =\u003e $statement-\u003egetOldBalance()-\u003egetDate()-\u003eformat('Y-m-d'),\n        'opening_balance' =\u003e $statement-\u003ehasOldBalance() ? $statement-\u003egetOldBalance()-\u003egetAmount() : null,\n        'closing_balance' =\u003e $statement-\u003ehasNewBalance() ? $statement-\u003egetNewBalance()-\u003egetAmount() : null,\n        'operations' =\u003e []\n    ];\n    \n    foreach ($statement-\u003egetOperations() as $operation) {\n        $statementData['operations'][] = [\n            'date' =\u003e $operation-\u003egetDate()-\u003eformat('Y-m-d'),\n            'value_date' =\u003e $operation-\u003egetValueDate()-\u003eformat('Y-m-d'),\n            'amount' =\u003e $operation-\u003egetAmount(),\n            'label' =\u003e $operation-\u003egetLabel(),\n            'reference' =\u003e $operation-\u003egetReference(),\n            'bank_code' =\u003e $operation-\u003egetBankCode(),\n            'account_number' =\u003e $operation-\u003egetAccountNumber()\n        ];\n    }\n    \n    $data[] = $statementData;\n}\n\n// Convert to JSON for API response\necho json_encode($data, JSON_PRETTY_PRINT);\n```\n\n### Handling multiple account statements\n\n```php\n\u003c?php\n\nuse Silarhi\\Cfonb\\Cfonb120Reader;\n\n$reader = new Cfonb120Reader();\n$statements = $reader-\u003eparse($content);\n\n// Group statements by account\n$accountStatements = [];\nforeach ($statements as $statement) {\n    if ($statement-\u003ehasOldBalance()) {\n        $accountNumber = $statement-\u003egetOldBalance()-\u003egetAccountNumber();\n        $accountStatements[$accountNumber][] = $statement;\n    }\n}\n\n// Process each account separately\nforeach ($accountStatements as $accountNumber =\u003e $statements) {\n    echo \"Account: $accountNumber\\n\";\n    echo \"Number of statements: \" . count($statements) . \"\\n\";\n    \n    $totalBalance = 0;\n    foreach ($statements as $statement) {\n        if ($statement-\u003ehasNewBalance()) {\n            $totalBalance = $statement-\u003egetNewBalance()-\u003egetAmount();\n        }\n    }\n    echo \"Final balance: $totalBalance\\n\\n\";\n}\n```\n\n## Troubleshooting\n\n### Common parsing errors\n\n```php\n\u003c?php\n\nuse Silarhi\\Cfonb\\Cfonb120Reader;\nuse Silarhi\\Cfonb\\Exceptions\\ParseException;\n\n$reader = new Cfonb120Reader();\n\ntry {\n    $statements = $reader-\u003eparse($content);\n} catch (ParseException $e) {\n    // Common issues:\n    // - Invalid line length (should be 120 characters)\n    // - Malformed line format\n    // - Invalid date format\n    // - Invalid amount format\n    \n    echo \"Parse error on line: \" . $e-\u003egetMessage() . \"\\n\";\n    \n    // Try non-strict mode to continue parsing\n    $statements = $reader-\u003eparse($content, false);\n}\n```\n\n### Validating file format before parsing\n\n```php\n\u003c?php\n\nuse Silarhi\\Cfonb\\Cfonb120Reader;\n\nfunction validateCfonbFormat(string $content): bool {\n    $lines = explode(\"\\n\", trim($content));\n    \n    foreach ($lines as $line) {\n        // Skip empty lines\n        if (empty(trim($line))) continue;\n        \n        // Check line length for CFONB 120\n        if (strlen($line) !== 120) {\n            return false;\n        }\n        \n        // Check if line starts with valid CFONB code\n        $lineCode = substr($line, 0, 2);\n        if (!in_array($lineCode, ['01', '04', '05', '07'])) {\n            return false;\n        }\n    }\n    \n    return true;\n}\n\n// Usage\nif (validateCfonbFormat($content)) {\n    $reader = new Cfonb120Reader();\n    $statements = $reader-\u003eparse($content);\n} else {\n    echo \"Invalid CFONB format\\n\";\n}\n```\n\n[composer]: http://getcomposer.org/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsilarhi%2Fcfonb-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsilarhi%2Fcfonb-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsilarhi%2Fcfonb-parser/lists"}