PHPackages                             flavioheleno/bank-utils - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. flavioheleno/bank-utils

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

flavioheleno/bank-utils
=======================

Bank Utilities: CNAB Handling, Boleto Parsing and Validation

771[3 PRs](https://github.com/flavioheleno/bank-utils/pulls)PHP

Since Dec 1Pushed 3y ago1 watchersCompare

[ Source](https://github.com/flavioheleno/bank-utils)[ Packagist](https://packagist.org/packages/flavioheleno/bank-utils)[ RSS](/packages/flavioheleno-bank-utils/feed)WikiDiscussions main Synced 4d ago

READMEChangelogDependenciesVersions (4)Used By (0)

bank-utils [![Maintainability](https://camo.githubusercontent.com/0b029af03daf86d16f13b2ccb31b89793bd368ffd582091b00570870ec1babf7/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f64373738656231353134353039643538313837362f6d61696e7461696e6162696c697479)](https://codeclimate.com/github/flavioheleno/bank-utils/maintainability) [![Total Downloads](https://camo.githubusercontent.com/ad2489f7f7cb2c4dc66fb615cbe512b374692f85eef0ac31973805e3e0ebdcdb/68747470733a2f2f706f7365722e707567782e6f72672f666c6176696f68656c656e6f2f62616e6b2d7574696c732f646f776e6c6f616473)](//packagist.org/packages/flavioheleno/bank-utils)
==============================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

[](#bank-utils--)

Simple and straightforward Bank Utilities.

Install with composer
---------------------

[](#install-with-composer)

```
composer require flavioheleno/bank-utils
```

Boleto
------

[](#boleto)

### Parsing a typable line

[](#parsing-a-typable-line)

```
$line = '00190000090281913600966281313172600000000000000';
$boleto = BankUtils\Boleto\Parser::fromLine($line);

// string(3) "001"
$boleto->getIssuerBank();

// int(9)
$boleto->getCurrency();

// string(5) "00000"
$boleto->getIssuerReserve1();

// int(9)
$boleto->getCheckDigit1();

// string(10) "0281913600"
$boleto->getIssuerReserve2();

 // int(9)
$boleto->getCheckDigit2();

// string(10) "6628131317"
$boleto->getIssuerReserve3();

 // int(2)
$boleto->getCheckDigit3();

// int(6)
$boleto->getGeneralCheckDigit();

// object(DateTimeImmutable)#2380 (3) {
//   ["date"]=>
//   string(26) "1997-10-07 00:00:00.000000"
//   ["timezone_type"]=>
//   int(3)
//   ["timezone"]=>
//   string(17) "America/Sao_Paulo"
// }
$boleto->getDueDate();

// object(Money\Money)#2376 (2) {
//   ["amount":"Money\Money":private]=>
//   string(1) "0"
//   ["currency":"Money\Money":private]=>
//   object(Money\Currency)#2379 (1) {
//     ["code":"Money\Currency":private]=>
//     string(3) "BRL"
//   }
// }
$boleto->getAmount();
```

### Validating a typable line

[](#validating-a-typable-line)

```
$line = '00190000090281913600966281313172600000000000000';

// bool(true)
BankUtils\Boleto\Validator::checkLine($line);
```

You could also validate a parsed Boleto:

```
$line = '00190000090281913600966281313172600000000000000';
$boleto = BankUtils\Boleto\Parser::fromLine($line);

// bool(true)
BankUtils\Boleto\Validator::checkBoleto($boleto);
```

CNAB Files
----------

[](#cnab-files)

CNAB parsing depends on a Provider implementation, which is nothing more than a few field naming and size setup.

A sample can be seen [here](src/Cnab/Provider/Febraban/Cnab240.php).

### Parsing a CNAB file

[](#parsing-a-cnab-file)

```
$filePath = '/path/to/file.cnab';
$provider = BankUtils\Cnab\Provider\Febraban\Cnab240::class;

$cnabFile = BankUtils\Cnab\Reader::fromFile($filePath, $provider);
```

Alternatively, you can also parse from a `string` or an `array`:

```
$filePath = '/path/to/file.cnab';
$provider = BankUtils\Cnab\Provider\Febraban\Cnab240::class;

$str = file_get_contents($filePath);
$cnabFile = BankUtils\Cnab\Reader::fromString($str, $provider);

$arr = file($filePath, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
$cnabFile = BankUtils\Cnab\Reader::fromArray($arr, $provider);
```

### Writing a CNAB file

[](#writing-a-cnab-file)

```
$cnabFile = new BankUtils\Cnab\Container\File(...);
$filePath = '/path/to/file.cnab';
$provider = BankUtils\Cnab\Provider\Febraban\Cnab240::class;

$bool = BankUtils\Cnab\Writer::toFile($filePath, $cnabFile, $provider);
```

Alternatively, you can also write to a `string` or an `array`:

```
$cnabFile = new BankUtils\Cnab\Container\File(...);
$provider = BankUtils\Cnab\Provider\Febraban\Cnab240::class;

$str = BankUtils\Cnab\Writer::toString($cnabFile, $provider);

$arr = BankUtils\Cnab\Writer::toArray($cnabFile, $provider);
```

Helpers
-------

[](#helpers)

### Bank Codes

[](#bank-codes)

This helper is ideal for using along with Boleto and CNAB as they only carry bank codes.

#### Checking code validity

[](#checking-code-validity)

```
// bool(true)
BankUtils\Common\BankCode::validCode('001');

// bool(false)
BankUtils\Common\BankCode::validCode('000');
```

#### Get bank name

[](#get-bank-name)

```
// string(20) "Banco do Brasil S.A."
BankUtils\Common\BankCode::getName('001');
```

#### Get bank url

[](#get-bank-url)

```
// string(13) "www.bb.com.br"
BankUtils\Common\BankCode::getUrl('001');
```

Contributing
------------

[](#contributing)

There are a few helper scripts that can be called by composer, such as:

- Static Code Analysis: `php composer.phar run check`
- Code Linting: `php composer.phar run lint`
- Tests: `php composer.phar run test`

**NOTE:** to run the *Code Linting*, you must download the ruleset from [here](https://github.com/flavioheleno/phpcs-ruleset/blob/master/ruleset.xml) first.

License
-------

[](#license)

This library is licensed under the [MIT License](LICENSE).

###  Health Score

18

—

LowBetter than 8% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity28

Early-stage or recently created project

 Bus Factor1

Top contributor holds 68.1% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/42b9c9cbc06973a61587667fc811b853f4d71843f35ba2535f3900083e69ab3f?d=identicon)[flavioheleno](/maintainers/flavioheleno)

---

Top Contributors

[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (64 commits)")[![flavioheleno](https://avatars.githubusercontent.com/u/471860?v=4)](https://github.com/flavioheleno "flavioheleno (29 commits)")[![andrew-demb](https://avatars.githubusercontent.com/u/12499813?v=4)](https://github.com/andrew-demb "andrew-demb (1 commits)")

---

Tags

bankbank-utilsboletocnabhacktoberfestparserutilitiesvalidator

### Embed Badge

![Health badge](/badges/flavioheleno-bank-utils/health.svg)

```
[![Health](https://phpackages.com/badges/flavioheleno-bank-utils/health.svg)](https://phpackages.com/packages/flavioheleno-bank-utils)
```

###  Alternatives

[mtdowling/jmespath.php

Declaratively specify how to extract elements from a JSON document

2.0k472.8M135](/packages/mtdowling-jmespathphp)[opis/closure

A library that can be used to serialize closures (anonymous functions) and arbitrary data.

2.6k230.0M284](/packages/opis-closure)[masterminds/html5

An HTML5 parser and serializer.

1.8k242.8M229](/packages/masterminds-html5)[sabberworm/php-css-parser

Parser for CSS Files written in PHP

1.8k191.2M65](/packages/sabberworm-php-css-parser)[michelf/php-markdown

PHP Markdown

3.5k52.4M345](/packages/michelf-php-markdown)[jms/metadata

Class/method/property metadata management in PHP

1.8k152.8M88](/packages/jms-metadata)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
