jtc-solutions/code-generator
Composer 安装命令:
composer require jtc-solutions/code-generator
包简介
Package that helps generating CRUD, services and repository boilerplate.
README 文档
README
Symfony bundle that helps generate boilerplate code for CRUD Controllers (List, Detail, Create, Update, Delete), DTOs, Repositories and Services.
Designed primarily for Domain-Driven Design structured applications.
Installation
- Require the bundle using Composer:
composer require jtc-solutions/code-generator --dev
(Note: Typically used as a dev dependency)
- Enable the bundle:
If your application doesn't use Symfony Flex, you'll need to manually enable the bundle by adding it to your config/bundles.php file:
// config/bundles.php return [ // ... other bundles JtcSolutions\CodeGenerator\JtcSolutionsCodeGeneratorBundle::class => ['dev' => true], ];
Configuration
Create a configuration file (e.g., config/packages/dev/jtc_solutions_code_generator.yaml) to define how the generator should behave.
# config/packages/dev/jtc_solutions_code_generator.yaml jtc_solutions_code_generator: global: # Supported variables are {domain} and {entity} # Example: App\Domain\Catalog\Entity\Product -> domain=Catalog, entity=Product namespace: # Template for generated controller namespaces. controllerNamespaceTemplate: 'App\{domain}\App\Api\{entity}' # Template for generated DTO namespaces. dtoNamespaceTemplate: 'App\{domain}\Domain\Dto\{entity}' # Template for generated Service namespace. serviceNamespaceTemplate: 'App\{domain}\Domain\Service\{entity}' # Template for generated Repository namespace. repositoryNamespaceTemplate: 'App\{domain}\Infrastructure\Repository' project: # Project source directory relative to kernel.project_dir # Example: 'src' or '.' if source is in the root projectDir: '%kernel.project_dir%/src' # Required # Base namespace corresponding to the projectDir # Example: 'App' for 'src/...' projectBaseNamespace: 'project' # Required # Fully qualified class name (FQCN) of the interface that all your entities implement. # Used by the DTO generator to identify entity properties. entityInterface: JtcSolutions\Core\Entity\IEntity # Required # Fully qualified class name (FQCN) of the class to use as a type hint # in DTOs when an entity property is detected. # Example: A property 'product' of type Product (implements IEntity) # will become 'product' of type EntityId in the DTO. dtoEntityReplacement: JtcSolutions\Core\Dto\EntityId # Fully qualified class name (FQCN) of an interface that generated # Request DTOs (for Create/Update) should implement. requestDtoInterface: JtcSolutions\Core\Dto\IEntityRequestBody # Properties that will be skipped and ignored for generations # useful for common properties that you do not want in your DTOs and service such as entity Id, or timestamps. ignoredProperties: - "id" - "createdAt" - "createdBy" openApi: # Fully qualified class name (FQCN) of the DTO used for error responses # in generated OpenAPI documentation. errorResponseClass: JtcSolutions\Core\Dto\ErrorRequestJsonResponse # Fully qualified class name (FQCN) of the DTO used for pagination metadata # in generated OpenAPI documentation for list endpoints. paginationClass: JtcSolutions\Core\Dto\Pagination # Configuration for controllers. # - "parent" is default extended class controllers: create: parent: JtcSolutions\Core\Controller\BaseEntityCRUDController update: parent: JtcSolutions\Core\Controller\BaseEntityCRUDController delete: parent: JtcSolutions\Core\Controller\BaseEntityCRUDController detail: parent: JtcSolutions\Core\Controller\BaseController list: parent: JtcSolutions\Core\Controller\BaseController
Placeholders
{domain}: Extracted from the entity's namespace (e.g.,CatalogfromApp\Catalog\Domain\Entity\Product).{entity}: The short class name of the entity (e.g.,ProductfromApp\Domain\Catalog\Entity\Product).
Usage
The primary way to use the bundle is via the provided Symfony console command.
php bin/console jtc-solutions:generate-crud <TargetEntityFQCN>
Note: The TargetEntityFQCN must be in quotes. Otherwise it is escaped.
Example:
php bin/console jtc-solutions:generate-crud 'App\Domain\Catalog\Entity\Product'
jtc-solutions/code-generator 适用场景与选型建议
jtc-solutions/code-generator 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.61k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 04 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 jtc-solutions/code-generator 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 jtc-solutions/code-generator 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 3.61k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 11
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: proprietary
- 更新时间: 2025-04-11