lacus/cpf-gen
Composer 安装命令:
composer require lacus/cpf-gen
包简介
Utility function to generate valid CPF (Brazilian personal ID)
README 文档
README
Utility function/class to generate valid CPF (Brazilian personal ID).
PHP Support
| Passing ✔ | Passing ✔ | Passing ✔ | Passing ✔ |
Installation
# using Composer
$ composer require lacus/cpf-gen
Import
<?php // Using class-based resource use Lacus\CpfGen\CpfGenerator; // Or using function-based one use function Lacus\CpfGen\cpf_gen;
Usage
Object-Oriented Usage
$generator = new CpfGenerator(); $cpf = $generator->generate(); // returns '47844241055' // With options $cpf = $generator->generate( format: true ); // returns '478.442.410-55' $cpf = $generator->generate( prefix: '528250911' ); // returns '52825091138' $cpf = $generator->generate( prefix: '528250911', format: true ); // returns '528.250.911-38'
The options can be provided to the constructor or the generate() method. If passed to the constructor, the options will be attached to the CpfGenerator instance. When passed to the generate() method, it only applies the options to that specific call.
$generator = new CpfGenerator(format: true); $cpf1 = $generator->generate(); // '478.442.410-55' (uses instance options) $cpf2 = $generator->generate(format: false); // '47844241055' (overrides instance options) $cpf3 = $generator->generate(); // '123.456.789-01' (uses instance options again)
Imperative programming
The helper function cpf_gen() is just a functional abstraction. Internally it creates an instance of CpfGenerator and calls the generate() method right away.
$cpf = cpf_gen(); // returns '47844241055' $cpf = cpf_gen(format: true); // returns '478.442.410-55' $cpf = cpf_gen(prefix: '528250911'); // returns '52825091138' $cpf = cpf_gen(prefix: '528250911', format: true); // returns '528.250.911-38'
Generator Options
| Parameter | Type | Default | Description |
|---|---|---|---|
format |
?bool |
false |
Whether to format the output with dots and dash |
prefix |
?string |
'' |
If you have CPF initials and want to complete it with valid digits. The string provided must contain between 0 and 9 digits! |
Contribution & Support
We welcome contributions! Please see our Contributing Guidelines for details. But if you find this project helpful, please consider:
- ⭐ Starring the repository
- 🤝 Contributing to the codebase
- 💡 Suggesting new features
- 🐛 Reporting bugs
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
lacus/cpf-gen 适用场景与选型建议
lacus/cpf-gen 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 562 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 09 月 03 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「generator」 「faker」 「fake」 「generate」 「cpf」 「br」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 lacus/cpf-gen 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 lacus/cpf-gen 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 lacus/cpf-gen 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Memio's PrettyPrinter, used to generate PHP code from given Model
Mocks, stubs, and spies for PHP.
Phony for Kahlan.
Symfony bundle to manage fixtures with Alice and Faker.
Additional plugin for fakerphp/faker that allows you to generate a random animal
Mock PSR-18 HTTP client
统计信息
- 总下载量: 562
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 7
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-09-03