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

Maker Bundle Laravel Package

customizer/maker-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps

  1. Installation Add the bundle via Composer:

    composer require symfony/maker-bundle --dev
    

    Enable it in config/bundles.php:

    return [
        // ...
        Symfony\MakerBundle\MakerBundle::class => ['dev' => true, 'test' => true],
    ];
    
  2. First Command Run the make:controller command to generate a basic controller:

    php bin/console make:controller Blog/PostController
    

    Follow prompts to customize (e.g., route path, template, CRUD actions).

  3. Where to Look First

    • Documentation: Symfony MakerBundle Docs
    • Commands List: Run php bin/console list make to see available generators.
    • Default Templates: Check vendor/symfony/maker-bundle/Resources/skeleton for boilerplate logic.

Implementation Patterns

Core Workflows

  1. CRUD Generation Use make:crud for full-stack scaffolding (controllers, forms, templates, and entities):

    php bin/console make:crud Blog/Post --field="title:string" --field="content:text"
    
    • Tip: Combine with --format=json for API-only CRUD.
  2. Customizing Generators Override default templates by copying skeletons from vendor to config/packages/symfony_maker/:

    mkdir -p config/packages/symfony_maker
    cp vendor/symfony/maker-bundle/Resources/skeleton/* config/packages/symfony_maker/
    

    Edit files like controller.php.twig to modify generated code.

  3. Integration with Existing Code

    • Entities: Use make:entity to add fields to existing Doctrine entities:
      php bin/console make:entity Blog/Post --add
      
    • Forms: Generate forms for existing entities:
      php bin/console make:form Blog/PostType --fields="title:text,content:ckeditor"
      
  4. Testing Generate test classes with make:test:

    php bin/console make:test Blog/PostControllerTest
    

    Supports PHPUnit and Pest frameworks.

  5. Automating with Custom Commands Extend the bundle by creating custom makers (see Custom Makers).


Integration Tips

  • Doctrine Fixtures: Generate fixtures alongside entities:
    php bin/console make:fixtures Blog/PostFixtures
    
  • API Platform: Use make:crud with --format=json for API-first projects.
  • Symfony UX: Pair with make:form to leverage Symfony UX components (e.g., Turbo, Stimulus):
    php bin/console make:form Blog/PostType --fields="title:text,content:stimulus"
    
  • Environment-Specific Generators Use --env=test to generate test-specific code (e.g., test controllers or fixtures).

Gotchas and Tips

Pitfalls

  1. Template Overrides

    • Issue: Custom templates in config/packages/symfony_maker/ may be overwritten during updates.
    • Fix: Use post-update-cmd in composer.json to preserve overrides:
      "scripts": {
          "post-update-cmd": [
              "php bin/console cache:clear",
              "cp -r vendor/symfony/maker-bundle/Resources/skeleton/* config/packages/symfony_maker/ 2>/dev/null || true"
          ]
      }
      
  2. Backward Compatibility

    • Generated code may change between minor versions (e.g., Symfony 5.x → 6.x).
    • Mitigation: Test generators in a staging environment before production use.
  3. Doctrine Entity Conflicts

    • Issue: Running make:entity on an existing entity may cause conflicts if fields already exist.
    • Fix: Use --add to append fields or manually merge changes.
  4. Command Argument Changes

    • Input arguments/options may change between releases (e.g., --field vs. --fields).
    • Tip: Check the changelog for breaking changes.
  5. Caching Issues

    • Symptom: Generators fail silently or use outdated templates.
    • Fix: Clear the cache after installing/updating:
      php bin/console cache:clear
      

Debugging

  • Verbose Output: Run commands with -v for debugging:
    php bin/console make:controller -v Blog/PostController
    
  • Dry Runs: Use --dry-run to preview changes without writing files (if supported by the command).
  • Template Debugging: Add {{ dump() }} to .twig templates to inspect variables during generation.

Extension Points

  1. Custom Makers Create reusable generators by extending AbstractMaker:

    // src/Maker/CustomCommandMaker.php
    namespace App\Maker;
    
    use Symfony\Bundle\MakerBundle\Maker\Generator;
    use Symfony\Bundle\MakerBundle\InputConfiguration;
    use Symfony\Bundle\MakerBundle\Maker\MakerInterface;
    
    class CustomCommandMaker implements MakerInterface
    {
        public function configureOptions(InputConfiguration $config): void
        {
            $config->setName('make:custom-command');
        }
    
        public function generate(InputConfiguration $config, Generator $generator): void
        {
            $generator->generateFile(
                'src/Command/CustomCommand.php',
                'custom_command.php.twig',
                ['command_name' => $config->getArgument('name')]
            );
        }
    }
    

    Register it in config/packages/symfony_maker.php:

    makers:
        App\Maker\CustomCommandMaker:
            command: make:custom-command
    
  2. Event Listeners Hook into the maker.generation event to modify generated files:

    // src/EventListener/MakerListener.php
    namespace App\EventListener;
    
    use Symfony\Component\EventDispatcher\Attribute\AsEventListener;
    use Symfony\Bundle\MakerBundle\Event\MakerEvent;
    
    #[AsEventListener(event: 'maker.generation', method: 'onGeneration')]
    class MakerListener
    {
        public function onGeneration(MakerEvent $event): void
        {
            $event->getGenerator()->addFileToGenerate(
                'custom_file.php',
                'custom_template.twig',
                ['custom_var' => 'value']
            );
        }
    }
    
  3. Environment-Specific Logic Use InputConfiguration to conditionally generate code based on environment:

    public function generate(InputConfiguration $config, Generator $generator): void
    {
        if ($config->getOption('env') === 'test') {
            $generator->generateFile('tests/TestController.php', 'test_controller.twig');
        }
    }
    

Pro Tips

  • Alias Commands: Add shortcuts to config/packages/symfony_maker.php:

    aliases:
        mc: make:controller
        me: make:entity
    

    Now use php bin/console mc Blog/PostController instead of the full command.

  • Git Ignore: Exclude generated files from version control by adding to .gitignore:

    /var/cache/*
    /config/packages/symfony_maker/*
    
  • IDE Support: Use // @formatter:off and // @formatter:on in generated files to preserve formatting in your IDE.

  • Symfony Flex Recipes: Leverage Symfony recipes to automate post-installation tasks (e.g., copying templates).

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.
andydefer/laravel-cluster
aimeos/ai-admin-mcp
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
christhompsontldr/laravel-inky
spatie/mailcoach-vapor