facebook/hack-codegen
最新稳定版本:v4.5.1
Composer 安装命令:
composer require facebook/hack-codegen
包简介
Hack Codegen is a library for programmatically generating Hack code
关键字:
README 文档
README
Hack Codegen is a library for easily generating Hack code and writing it into signed files that prevent undesired modifications. The idea behind writing code that writes code is to raise the level of abstraction and reduce coupling. You can use your own way of describing a problem and generate the corresponding code. E.g. see examples/dorm. In this example, we use a schema to describe the structure of the data, and we use Hack Codegen to write the matching code.
Examples
The DORM example shows how to use the different aspects of the code generation in a simplified real-life example. The included tests also exemplify the usage of the different components.
Requirements
Hack Codegen requires:
- HHVM
- Composer
Installing Hack Codegen
This package can be installed via composer:
composer require facebook/hack-codegen
Usage
Include the autoload file generated by composer and you are ready to start using it. For example:
<?hh require 'vendor/autoload.php'; use Facebook\HackCodegen\HackCodegenFactory; $cg = new HackCodegenFactory(new HackCodegenConfig()); echo $cg->codegenFile('HelloWorld.php') ->addClass( $cg->codegenClass('HelloWorld') ->addMethod( $cg->codegenMethod('sayHi') ->setReturnType('void') ->setBody( $cg->codegenHackBuilder() ->addAssignment( '$some_vector', Vector { 1, 2, 3 }, HackBuilderValues::vector( HackBuilderValues::export(), ), ) ->addAssignment( '$debug_info', Map { 'file' => '__FILE__', 'line' => '__LINE__' }, HackBuilderValues::map( HackBuilderKeys::export(), HackBuilderValues::literal(), ), ) ->addAssignment( '$some_vector_of_vectors', Vector { Vector { 1, 2, 3 }, Vector { 4, 5, 6 } }, HackBuilderValues::vector( HackBuilderValues::vector( HackBuilderValues::export(), ), ), ) ->addLine('echo "hello world\n";') ->getCode(); ); ) )->save();
Configuration
You can configure some options such as the maximum line width, spacing and headers by implementing IHackCodegenConfig and passing an instance to HackCodegenFactory's constructor.
License
Hack Codegen is MIT-licensed.
facebook/hack-codegen 适用场景与选型建议
facebook/hack-codegen 是一款 基于 Hack 开发的 Composer 扩展包,目前已累计 546.08k 次下载、GitHub Stars 达 345, 最近一次更新时间为 2026 年 01 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「code generation」 「hack」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 facebook/hack-codegen 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 facebook/hack-codegen 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 facebook/hack-codegen 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Memio's PrettyPrinter, used to generate PHP code from given Model
Toolset for generating PHP code
Fabricates patterns.
Hack Logging Package
Dependency Injection Container For HHVM/Hack
PHP PDF library for generating and importing PDF documents. A component of the Pop PHP Framework
统计信息
- 总下载量: 546.08k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 347
- 点击次数: 36
- 依赖项目数: 7
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2026-01-04