Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Generator Bundle Laravel Package

baconmanager/generator-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. 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],
    
  2. 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.

  3. Where to Look First

    • Generator Classes: Check src/Generator/ for core generator logic.
    • Command Overrides: Look for Command/ directory (if present) to see how commands are registered.
    • Configuration: Review Resources/config/services.yaml for service definitions and overrides.

Implementation Patterns

Customizing Generators

  1. 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
        }
    }
    
  2. Register Custom Generators Override the bundle’s services in config/services.yaml:

    services:
        BaconManager\GeneratorBundle\Generator\ControllerGenerator:
            alias: App\Generator\ControllerGenerator
    
  3. 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']
    
  4. 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');
    
  5. Integration with Workflows

    • Pre-Generation Hooks: Use Symfony events (e.g., kernel.request) to validate or modify inputs before generation.
    • Post-Generation Tasks: Chain commands (e.g., make:migration) after generation via ProcessBuilder or custom scripts.

Gotchas and Tips

Pitfalls

  1. 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\).

  2. Template Paths If overriding templates, verify the generator’s getTemplate() method points to your custom path. Default paths may not auto-detect overrides.

  3. Command Registration The bundle may not auto-register custom commands. Explicitly tag them in services.yaml:

    tags: ['console.command']
    
  4. Dependency Injection Generators rely on services like filesystem, twig, or router. Ensure these are properly bound in your container.

  5. 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).

Debugging Tips

  • Enable Debug Mode: Use APP_DEBUG=1 to see detailed errors during generation.
  • Log Generator Output: Temporarily log template paths or generated content:
    file_put_contents('debug/generator.log', $this->getTemplateContent(), FILE_APPEND);
    
  • Check Command Arguments: Validate CLI arguments passed to generators (e.g., --format=xml) match expected patterns.

Extension Points

  1. Add Custom Fields Extend generators to accept additional arguments via configure() in commands:

    protected function configure()
    {
        $this->addArgument('custom_field', InputArgument::OPTIONAL, 'Custom value');
    }
    
  2. Dynamic Template Selection Use logic in generate() to switch templates based on runtime conditions:

    $template = $this->isLegacy() ? 'legacy.twig' : 'modern.twig';
    
  3. Post-Processing Hook into postGenerate() or similar methods to run additional tasks (e.g., Git commits, notifications):

    protected function postGenerate()
    {
        $this->runPostGenerationScript();
    }
    
  4. Configuration Overrides Use Symfony’s parameter system to customize behavior globally:

    # config/packages/bacon_generator.yaml
    bacon_generator:
        default_template: 'custom.twig'
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
besmartand-pro/php-quality-config
sentix/ai-chatbot
terminal42/code-quality-tools
codifyo/ts-generator-bundle
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity