Weave 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

Generatorbundle Laravel Package

4h/generatorbundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation Add the bundle to your composer.json:

    composer require 4h/generatorbundle
    

    Register it in config/bundles.php:

    return [
        // ...
        FourH\GeneratorBundle\FourHGeneratorBundle::class => ['all' => true],
    ];
    
  2. First Command Generate a basic CRUD controller:

    php bin/console generate:controller --entity=App\Entity\Post --no-interaction
    

    (Check bin/console for available commands—this bundle extends Symfony’s sensio:generator with custom templates.)

  3. Key Files to Review

    • config/packages/four_h_generator.yaml (default config, if present)
    • templates/ (custom generator templates, if extended)
    • src/Generator/ (core logic, if overriding behavior).

Implementation Patterns

Common Workflows

  1. Custom Templates Override default templates by copying them from vendor/4h/generatorbundle/templates/ to templates/four_h_generator/ in your project. Example:

    mkdir -p templates/four_h_generator
    cp vendor/4h/generatorbundle/templates/controller/* templates/four_h_generator/
    

    Update config/packages/four_h_generator.yaml to point to your custom path:

    four_h_generator:
        templates_dir: '%kernel.project_dir%/templates/four_h_generator'
    
  2. Dynamic Generation Use --dry-run to preview changes before applying:

    php bin/console generate:controller --entity=App\Entity\User --dry-run
    

    Chain commands with --no-interaction for CI/CD pipelines.

  3. Entity-Specific Logic Extend generators by creating a custom command:

    // src/Command/CustomGeneratorCommand.php
    namespace App\Command;
    use FourH\GeneratorBundle\Generator\Generator;
    use Symfony\Component\Console\Command\Command;
    use Symfony\Component\Console\Input\InputInterface;
    use Symfony\Component\Console\Output\OutputInterface;
    
    class CustomGeneratorCommand extends Command {
        protected function execute(InputInterface $input, OutputInterface $output) {
            $generator = $this->getContainer()->get(Generator::class);
            $generator->generate('custom_template', ['entity' => 'App\Entity\Post']);
        }
    }
    
  4. Integration with Doctrine Generate repositories, services, or DTOs alongside entities:

    php bin/console generate:repository --entity=App\Entity\Product
    php bin/console generate:dto --entity=App\Entity\Product
    

Gotchas and Tips

Pitfalls

  1. Template Overrides

    • Issue: Custom templates may break if not named identically to the originals.
    • Fix: Use php bin/console debug:generator to list available templates and their paths.
  2. Namespace Conflicts

    • Issue: Generated classes may clash with existing ones (e.g., src/Controller/ already has PostController).
    • Fix: Use --target-dir to specify output:
      php bin/console generate:controller --entity=App\Entity\Post --target-dir=src/Generated/
      
  3. Doctrine Metadata Cache

    • Issue: Generators may fail if Doctrine’s metadata cache is stale.
    • Fix: Clear cache before generating:
      php bin/console cache:clear
      php bin/console doctrine:cache:clear-metadata
      
  4. Bundle Updates

    • Issue: Updating the bundle may overwrite custom templates.
    • Fix: Use composer.json’s "replace" or "extra" fields to pin versions or document overrides.

Debugging Tips

  • Verbose Output: Add -vvv to commands for detailed logs:
    php bin/console generate:controller -vvv --entity=App\Entity\Post
    
  • Dry Runs: Always test with --dry-run before committing changes.
  • Event Listeners: Extend generation logic via Symfony events (e.g., generator.generate):
    # config/services.yaml
    services:
        App\EventListener\CustomGeneratorListener:
            tags:
                - { name: kernel.event_listener, event: generator.generate, method: onGenerate }
    

Extension Points

  1. Custom Generators Create new generator types by extending FourH\GeneratorBundle\Generator\Generator and register them in services.yaml:

    services:
        app.custom_generator:
            class: App\Generator\CustomGenerator
            tags: [four_h_generator.generator]
    
  2. Pre/Post-Generation Hooks Use Symfony’s kernel.request event to validate entities before generation or clean up afterward.

  3. Template Variables Pass custom data to templates via --option flags or environment variables:

    php bin/console generate:controller --entity=App\Entity\Post --namespace=Admin
    
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.
tequilarapido/trackit
gregsphotography/site-builder-filament
cabaoctavio/laravel-query-log
gregsphotography/site-builder-components
io-digital/clickatell
snowsoft/laravel-admin
oxygen/auth
relicsoftware/barakah-payment-gateway
tobya/work-with-composer
equipc/laravel-email-validator
equipc/laravel-email-database-log
adedsec/nova-translated-labels
wazza/laravel-db-encryption
hokny/laravel-generator
vonsogt/backup
jengo/queues
jeremykenedy/laravel-observability
coleus/frame
thtg88/journalism
filagora/filagora-ai-forums