jtc-solutions/code-generator 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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

  1. Require the bundle using Composer:
composer require jtc-solutions/code-generator --dev

(Note: Typically used as a dev dependency)

  1. 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., Catalog from App\Catalog\Domain\Entity\Product).
  • {entity}: The short class name of the entity (e.g., Product from App\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 我们能提供哪些服务?
定制开发 / 二次开发

基于 jtc-solutions/code-generator 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 3.61k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 11
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: proprietary
  • 更新时间: 2025-04-11