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

Generatorbundle Laravel Package

cekurte/generatorbundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. 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],
    ];
    
  2. First Use Case Generate a basic CRUD controller and form:

    php bin/console generate:crud
    

    Follow prompts to specify:

    • Entity class (e.g., App\Entity\Product)
    • Bundle namespace (e.g., App\Controller)
    • Optional: Override templates or output directory.
  3. Where to Look First

    • Command Reference: Run php bin/console list to see available generators.
    • Templates: Check vendor/cekurte/generatorbundle/Resources/templates/ for default templates.
    • Configuration: Override defaults in config/packages/cekurte_generator.yaml (if available).

Implementation Patterns

Workflows

  1. Custom Generators Extend the bundle by creating custom generators:

    php bin/console generate:custom --name=MyGenerator --template=my_template.twig
    
    • Place templates in templates/ under your bundle.
    • Define generator logic in a service tagged as generator.
  2. Integration with Existing Code

    • Hooks: Use Symfony events (e.g., kernel.request) to trigger generators dynamically.
    • Pre/Post-Generation: Override Cekurte\GeneratorBundle\Generator\GeneratorInterface methods like generate() or postGenerate().
  3. Template Inheritance Extend default templates by copying them to templates/CekurteGeneratorBundle/ in your project. The bundle will auto-detect overrides.

Common Use Cases

  • Rapid Prototyping: Generate controllers, services, and forms for new features.
  • Boilerplate Reduction: Automate repetitive code (e.g., API resources, DTOs).
  • Consistency: Enforce naming conventions and project structure via templates.

Example: Generating a Service

php bin/console generate:service --class=ProductService --methods="findAll,findById"

Outputs a service class with stubbed methods in src/Service/ProductService.php.


Gotchas and Tips

Pitfalls

  1. Outdated Bundle

    • Last release in 2015: Test thoroughly in a staging environment.
    • Symfony 4/5/6 Compatibility: May require manual adjustments (e.g., autowiring, namespace changes).
    • PHP Version: Test with PHP 7.4+; older PHP versions may lack required features.
  2. Template Overrides

    • Overrides in templates/CekurteGeneratorBundle/ must match the original template structure exactly.
    • Debugging: Use var_dump() in templates to verify variables (e.g., {{ dump(_context) }} in Twig).
  3. Command Line Arguments

    • Some generators lack --help docs. Inspect the command class (e.g., vendor/cekurte/generatorbundle/Command/GenerateCrudCommand.php) for options.
  4. Namespace Conflicts

    • Ensure generated classes don’t clash with existing ones. Use --bundle flag to specify output namespace.

Debugging Tips

  • Enable Debug Mode: Set APP_DEBUG=true in .env to see detailed errors.
  • Log Output: Redirect generator output to a file:
    php bin/console generate:crud > /dev/null 2>&1
    
  • Check Generated Files: Compare with expected output in vendor/cekurte/generatorbundle/Resources/templates/.

Extension Points

  1. 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
    
  2. Generator Services Create a custom generator service:

    # config/services.yaml
    services:
        App\Generator\MyCustomGenerator:
            tags: ['generator']
            arguments:
                - '@twig'
                - '%kernel.project_dir%/templates/MyGenerator/'
    
  3. 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');
    }
    

Configuration Quirks

  • No Config File: The bundle may not provide a config/packages/cekurte_generator.yaml. Defaults are hardcoded.
  • Template Variables: Common Twig variables include:
    • _context: All available data (e.g., class name, bundle namespace).
    • name: Generated class name.
    • bundle: Target bundle namespace.
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.
comsave/common
alecsammon/php-raml-parser
chrome-php/wrench
lendable/composer-license-checker
typhoon/reflection
mesilov/moneyphp-percentage
mike42/gfx-php
bookdown/themes
aura/view
aura/html
aura/cli
povils/phpmnd
nayjest/manipulator
omnipay/tests
psr-mock/http-message-implementation
psr-mock/http-factory-implementation
psr-mock/http-client-implementation
voku/email-check
voku/urlify
rtheunissen/guzzle-log-middleware