Installation
Add the bundle to your composer.json:
composer require cekurte/generatorbundle
Register the bundle in config/bundles.php (Symfony 4+):
return [
// ...
Cekurte\GeneratorBundle\CekurteGeneratorBundle::class => ['all' => true],
];
First Use Case Generate a basic CRUD controller and form:
php bin/console generate:crud
Follow prompts to specify:
App\Entity\Product)App\Controller)Where to Look First
php bin/console list to see available generators.vendor/cekurte/generatorbundle/Resources/templates/ for default templates.config/packages/cekurte_generator.yaml (if available).Custom Generators Extend the bundle by creating custom generators:
php bin/console generate:custom --name=MyGenerator --template=my_template.twig
templates/ under your bundle.generator.Integration with Existing Code
kernel.request) to trigger generators dynamically.Cekurte\GeneratorBundle\Generator\GeneratorInterface methods like generate() or postGenerate().Template Inheritance
Extend default templates by copying them to templates/CekurteGeneratorBundle/ in your project. The bundle will auto-detect overrides.
php bin/console generate:service --class=ProductService --methods="findAll,findById"
Outputs a service class with stubbed methods in src/Service/ProductService.php.
Outdated Bundle
Template Overrides
templates/CekurteGeneratorBundle/ must match the original template structure exactly.var_dump() in templates to verify variables (e.g., {{ dump(_context) }} in Twig).Command Line Arguments
--help docs. Inspect the command class (e.g., vendor/cekurte/generatorbundle/Command/GenerateCrudCommand.php) for options.Namespace Conflicts
--bundle flag to specify output namespace.APP_DEBUG=true in .env to see detailed errors.php bin/console generate:crud > /dev/null 2>&1
vendor/cekurte/generatorbundle/Resources/templates/.Custom Templates
Override templates by copying from vendor/ to your project’s templates/ directory. Example:
templates/
└── CekurteGeneratorBundle/
└── Controller/
└── crud.html.twig # Override for CRUD templates
Generator Services Create a custom generator service:
# config/services.yaml
services:
App\Generator\MyCustomGenerator:
tags: ['generator']
arguments:
- '@twig'
- '%kernel.project_dir%/templates/MyGenerator/'
Event Listeners Listen to generator events (if supported) to modify behavior:
// src/EventListener/GeneratorListener.php
public function onGenerate(GenerateEvent $event) {
$event->setTemplate('custom_template.twig');
}
config/packages/cekurte_generator.yaml. Defaults are hardcoded._context: All available data (e.g., class name, bundle namespace).name: Generated class name.bundle: Target bundle namespace.How can I help you explore Laravel packages today?