jtc-solutions / code-generator
Package that helps generating CRUD, services and repository boilerplate.
Installs: 163
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: >=8.3
- jtc-solutions/core: ^0.1
- jtc-solutions/helpers: ^0.2
- nelmio/api-doc-bundle: ^5.0
- nikic/php-parser: ^5.0
- ramsey/uuid: ^4.7
- symfony/console: ^7.2
- symfony/filesystem: ^7.2
- symfony/http-foundation: ^7.2
Requires (Dev)
- grifart/phpstan-oneline: ^0.5.0
- mikey179/vfsstream: ^1.6
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^10.0
- slevomat/coding-standard: ^8.16
- symplify/easy-coding-standard: ^12.1
This package is not auto-updated.
Last update: 2025-04-24 18:38:35 UTC
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.,Catalog
fromApp\Catalog\Domain\Entity\Product
).{entity}
: The short class name of the entity (e.g.,Product
fromApp\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'