Installation
Add the bundle to your composer.json:
composer require baconmanager/generator-bundle
Enable it in config/bundles.php:
BaconManager\GeneratorBundle\BaconGeneratorBundle::class => ['all' => true],
First Use Case
Override the default Symfony generator commands (e.g., make:controller, make:entity) by extending the bundle’s generator classes. Start by inspecting the bundle’s Generator classes in src/Generator/ to understand how to customize them.
Where to Look First
src/Generator/ for core generator logic.Command/ directory (if present) to see how commands are registered.Resources/config/services.yaml for service definitions and overrides.Extend Base Generators
Override the default generator classes (e.g., ControllerGenerator, EntityGenerator) by creating your own versions in src/Generator/:
namespace App\Generator;
use BaconManager\GeneratorBundle\Generator\ControllerGenerator as BaseControllerGenerator;
class ControllerGenerator extends BaseControllerGenerator
{
protected function generateTemplate()
{
// Customize template logic here
}
}
Register Custom Generators
Override the bundle’s services in config/services.yaml:
services:
BaconManager\GeneratorBundle\Generator\ControllerGenerator:
alias: App\Generator\ControllerGenerator
Adding New Generators
Create a new command by extending Symfony\Bundle\GeneratorBundle\Command\GenerateCommand and register it in services.yaml:
services:
app.command.my_generator:
class: App\Command\MyGeneratorCommand
tags: ['console.command']
Template Customization
Override templates in templates/ (e.g., templates/controller.twig) and ensure the generator uses your path:
$this->generateTemplate('controller.twig', 'path/to/output');
Integration with Workflows
kernel.request) to validate or modify inputs before generation.make:migration) after generation via ProcessBuilder or custom scripts.Namespace Conflicts
Ensure your custom generator classes have unique namespaces to avoid collisions with the bundle’s defaults. Prefix with your bundle name (e.g., App\Generator\).
Template Paths
If overriding templates, verify the generator’s getTemplate() method points to your custom path. Default paths may not auto-detect overrides.
Command Registration
The bundle may not auto-register custom commands. Explicitly tag them in services.yaml:
tags: ['console.command']
Dependency Injection
Generators rely on services like filesystem, twig, or router. Ensure these are properly bound in your container.
Symfony Version Compatibility The bundle is labeled as "Symfony2," but test thoroughly with Symfony 4/5/6+. Some generator logic may need adjustments for newer Symfony features (e.g., autowiring, attribute routes).
APP_DEBUG=1 to see detailed errors during generation.file_put_contents('debug/generator.log', $this->getTemplateContent(), FILE_APPEND);
--format=xml) match expected patterns.Add Custom Fields
Extend generators to accept additional arguments via configure() in commands:
protected function configure()
{
$this->addArgument('custom_field', InputArgument::OPTIONAL, 'Custom value');
}
Dynamic Template Selection
Use logic in generate() to switch templates based on runtime conditions:
$template = $this->isLegacy() ? 'legacy.twig' : 'modern.twig';
Post-Processing
Hook into postGenerate() or similar methods to run additional tasks (e.g., Git commits, notifications):
protected function postGenerate()
{
$this->runPostGenerationScript();
}
Configuration Overrides Use Symfony’s parameter system to customize behavior globally:
# config/packages/bacon_generator.yaml
bacon_generator:
default_template: 'custom.twig'
How can I help you explore Laravel packages today?