Download the PHP package lacus/br-utils without Composer

On this page you can find all versions of the php package lacus/br-utils. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package br-utils

br-utils for PHP

Packagist Version Packagist Downloads PHP Version Test Status Last Update Date Project License

🚀 Full support for the new alphanumeric CNPJ format.

🌎 Acessar documentação em português

A PHP toolkit to handle the main operations with Brazilian-related data: CPF (Individual's Taxpayer ID) and CNPJ (Business Tax ID). It provides a top-level BrUtils wrapper around lacus/cpf-utils and lacus/cnpj-utils, exposing all bundled resources under unified namespaces.

PHP Support

PHP 8.2 PHP 8.3 PHP 8.4 PHP 8.5
Passing ✔ Passing ✔ Passing ✔ Passing ✔

Features

Installation

This installs lacus/br-utils together with lacus/cpf-utils and lacus/cnpj-utils (which in turn pulls in the CNPJ component packages). You do not need separate composer require calls for the domain packages when using lacus/br-utils.

Import

Pick the API that fits your use case.

Top-level façade:

Domain aggregators:

CPF components (object-oriented):

CNPJ components (object-oriented):

Functional helpers:

Quick start

With BrUtils (all-in-one):

With domain aggregators:

With functional helpers:

Usage

You can work in four equivalent ways:

  1. BrUtils — single instance with shared defaults across both CPF and CNPJ domains.
  2. Domain aggregatorsCpfUtils and CnpjUtils directly (same classes used internally by BrUtils).
  3. Component classesCpfFormatter, CnpjGenerator, and so on.
  4. Functional helperscpf_fmt(), cnpj_gen(), and related functions for one-off calls.

All approaches expose the same options and behavior within each domain. For full option tables and component-specific details, see the README of each bundled package.

BrUtils

Instance defaults and per-call overrides

Passing a CnpjFormatterOptions, CnpjGeneratorOptions, or CnpjValidatorOptions instance to the BrUtils constructor stores that object by reference — mutating it later affects subsequent calls with no per-call override.

CPF operations

CPF methods are accessed via $utils->cpf, CpfUtils, or the cpf_*() helpers. CPF uses the v1 API from lacus/cpf-utils: string-only input, positional/named formatter and generator options, and no validator settings.

Formatting (format / cpf_fmt)

Parameter Type Default Description
escape ?bool false When true, HTML-escapes the final string
hidden ?bool false When true, replaces the inclusive index range [hiddenStart, hiddenEnd] on the normalized 11-digit string before punctuation is applied
hiddenKey ?string '*' Replacement for each hidden position
hiddenStart ?int 3 Start index 010 (inclusive)
hiddenEnd ?int 10 End index 010 (inclusive)
dotKey ?string '.' Separator between digit groups
dashKey ?string '-' Separator before the last two digits
onFail ?\Closure see below Closure(mixed $value, Exception $e): string — used when sanitized length ≠ 11

Default onFail returns the original input unchanged. Invalid length does not throw from format().

Generation (generate / cpf_gen)

Parameter Type Default Description
format ?bool false When true, returns formatted CPF (000.000.000-00); otherwise returns compact 11-digit output
prefix ?string '' Base seed for generation. Non-digit characters are stripped; only the first 9 digits (indexes 08) are used

Validation (isValid / cpf_val)

Accepts formatted or unformatted CPF strings. Returns true or false without throwing for invalid CPF.

CNPJ operations

CNPJ methods are accessed via $utils->cnpj, CnpjUtils, or the cnpj_*() helpers. CNPJ uses the v2 API from lacus/cnpj-utils.

Formatting (format / cnpj_fmt)

Supports the same options as lacus/cnpj-fmt. Input accepts string or list<string>.

Parameter Type Default Description
hidden ?bool false When true, replaces the inclusive index range [hiddenStart, hiddenEnd] on the normalized 14-character string before punctuation is applied
hiddenKey ?string '*' Replacement for each hidden position (may be multi-character or empty); must not use disallowed key characters
hiddenStart ?int 5 Start index 013 (inclusive)
hiddenEnd ?int 13 End index 013 (inclusive); if hiddenStart > hiddenEnd, they are swapped
dotKey ?string '.' Separator between groups XX / XXX / XXX
slashKey ?string '/' Separator before the branch block
dashKey ?string '-' Separator before the last two characters
escape ?bool false When true, HTML-escapes the final string
encode ?bool false When true, URL-encodes the final string
onFail ?\Closure see below Closure(mixed $value, CnpjFormatterException $e): string — used when sanitized length ≠ 14

Default onFail returns an empty string. Wrong input types throw CnpjFormatterInputTypeError.

Generation (generate / cnpj_gen)

Supports the same options as lacus/cnpj-gen.

Parameter Type Default Description
format ?bool false When true, returns formatted CNPJ (XX.XXX.XXX/XXXX-XX); otherwise returns compact 14-character output
prefix ?string '' Base seed for generation. Non-alphanumeric chars are stripped, letters are uppercased, and only first 12 chars (indexes 011) are used; characters at index 12+ are ignored
type CnpjGenerationType\|'alphanumeric'\|'alphabetic'\|'numeric'\|null CnpjGenerationType::Alphanumeric Character family used for generated base positions

prefix validation rules:

Validation (isValid / cnpj_val)

Supports the same options as lacus/cnpj-val. Input accepts string or list<string>.

Parameter Type Default Description
type CnpjValidationType\|'alphanumeric'\|'numeric'\|null CnpjValidationType::Alphanumeric Character set after sanitization
caseSensitive ?bool true When false, lowercase letters are uppercased before alphanumeric validation

Invalid CNPJ returns false without throwing. Wrong input types throw CnpjValidatorInputTypeError.

Domain aggregators (standalone)

Use CpfUtils or CnpjUtils directly when you only need one domain:

Accessing components

Each domain aggregator exposes its internal formatter, generator, and validator:

Use getCpfUtils() / getCnpjUtils() on BrUtils, or the component getters on each domain utils instance, when you already have a configured instance and want the underlying component without creating a new one.

Mixing styles

Use BrUtils where a shared configuration helps, and standalone components or helpers elsewhere — they are the same underlying classes:

Errors & exceptions

BrUtils does not define its own exception types; it propagates errors from the bundled packages:

Invalid option types on CNPJ are TypeError subclasses; invalid option values are Exception subclasses. CPF and CNPJ validation failures return false. CPF formatting length failure is handled by onFail (default: return input); CNPJ formatting length failure uses onFail (default: return '').

For exhaustive exception lists and edge-case behavior, see each bundled package README.

Bundled packages

Package Main resources README
lacus/cpf-utils CpfUtils, CpfFormatter, CpfGenerator, CpfValidator, cpf_fmt(), cpf_gen(), cpf_val() docs
lacus/cnpj-utils CnpjUtils, CnpjFormatter, CnpjGenerator, CnpjValidator, CnpjType, CnpjValidationType, cnpj_fmt(), cnpj_gen(), cnpj_val() docs

All CPF symbols are available under Lacus\BrUtils\Cpf\; all CNPJ symbols under Lacus\BrUtils\Cnpj\. Interactive demos: CPF and CNPJ.

API

Contribution & Support

We welcome contributions! Please see our Contributing Guidelines for details. If you find this project helpful, please consider:

License

This project is licensed under the MIT License — see the LICENSE file for details.

Changelog

See CHANGELOG for a list of changes and version history.


Made with ❤️ by Lacus Solutions


All versions of br-utils with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
lacus/cnpj-utils Version ~2.0.0
lacus/cpf-utils Version ~1.1.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package lacus/br-utils contains the following files

Loading the files please wait ...