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

edlcdmc/generator-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps

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

    composer require edlcdmc/generator-bundle
    

    Register the bundle in config/bundles.php:

    return [
        // ...
        Edlcdmc\GeneratorBundle\EdlcdmcGeneratorBundle::class => ['all' => true],
    ];
    
  2. First Use Case Check the bundle’s Resources/config/services.yaml (or config/packages/edlcdmc_generator.yaml if using Symfony Flex) for default configurations. Run a basic generator command (if provided) via:

    php bin/console edlcdmc:generate:basic
    

    (Note: Since the package lacks a README, verify available commands via php bin/console list edlcdmc or inspect src/Command/ for custom commands.)

  3. Where to Look First

    • Command Structure: Inspect src/Command/ for generator logic (e.g., GenerateBasicCommand.php).
    • Templates: Check Resources/views/ or Resources/templates/ for Twig/Php templates.
    • Configuration: Look for config/ or Resources/config/ for customizable settings.

Implementation Patterns

Usage Patterns

  1. Command-Driven Workflows

    • Extend GeneratorBundle's base command (if available) to create custom generators:
      namespace App\Command;
      
      use Edlcdmc\GeneratorBundle\Command\AbstractGeneratorCommand;
      use Symfony\Component\Console\Input\InputArgument;
      
      class CustomGeneratorCommand extends AbstractGeneratorCommand {
          protected function configure() {
              $this->setName('app:generate:custom')
                   ->addArgument('name', InputArgument::REQUIRED);
          }
      
          protected function execute(InputInterface $input, OutputInterface $output) {
              $name = $input->getArgument('name');
              $this->generateFiles($name); // Hypothetical method
          }
      }
      
    • Register the command as a service in services.yaml:
      services:
          App\Command\CustomGeneratorCommand:
              tags: ['console.command']
      
  2. Template Integration

    • Use Twig templates (if supported) for dynamic file generation:
      {# Resources/templates/custom_class.php.twig #}
      <?php
      namespace App\Entity;
      
      class {{ className }} {
          // Auto-generated logic
      }
      
    • Render templates via:
      $template = $this->get('twig')->createTemplate($templatePath);
      $content = $template->render(['className' => $name]);
      
  3. Event-Driven Extensions

    • Listen for bundle events (if documented) to hook into generation lifecycle:
      use Edlcdmc\GeneratorBundle\Event\PreGenerateEvent;
      use Symfony\Component\EventDispatcher\EventSubscriberInterface;
      
      class GeneratorSubscriber implements EventSubscriberInterface {
          public static function getSubscribedEvents() {
              return [
                  'edlcdmc.generator.pre_generate' => 'onPreGenerate',
              ];
          }
      
          public function onPreGenerate(PreGenerateEvent $event) {
              // Modify $event->getData() before generation
          }
      }
      

Integration Tips

  • Leverage Symfony’s Dependency Injection: Inject services (e.g., Filesystem, Twig) into commands for reusable logic.
  • Configuration Overrides: Extend default settings via config/packages/edlcdmc_generator.yaml:
    edlcdmc_generator:
        default_namespace: 'App\Generated'
        output_dir: '%kernel.project_dir%/src/Generated'
    
  • Testing Generators: Mock file system operations or use Symfony\Component\Filesystem\Filesystem in tests.

Gotchas and Tips

Pitfalls

  1. Undocumented Features

    • The package lacks a README, so assume minimal defaults. Inspect src/ for undocumented behaviors (e.g., hardcoded paths, missing events).
    • Workaround: Use php bin/console debug:container Edlcdmc to explore services.
  2. File Overwrites

    • Generators may overwrite existing files without confirmation. Add a --force flag or pre-checks:
      if (file_exists($outputPath) && !$this->option('force')) {
          throw new \RuntimeException("File exists. Use --force to overwrite.");
      }
      
  3. Namespace Collisions

    • Default namespaces may conflict with existing code. Validate in onPreGenerate events or via CLI args.
  4. Template Escaping

    • If using Twig, ensure dynamic variables are escaped to avoid injection risks:
      {{ className|e('html') }}  {# Escape for HTML context #}
      

Debugging

  • Command Debugging: Use var_dump($input->getArguments()) or dd($this->getContainer()->getParameter('kernel.project_dir')) to inspect inputs.
  • File Permissions: Verify output_dir is writable:
    chmod -R 775 %kernel.project_dir%/src/Generated
    
  • Symfony Debug Toolbar: Enable for event/container inspection:
    # config/packages/dev/debug.yaml
    framework:
        profiler: { only_exceptions: false }
    

Extension Points

  1. Custom Templates

    • Override default templates by placing them in templates/edlcdmc/ (Symfony’s template loader will prioritize these).
  2. Generator Metadata

    • Extend the bundle’s Generator class (if abstract) to add metadata like:
      class CustomGenerator extends AbstractGenerator {
          public function getDescription() {
              return 'Generates custom boilerplate.';
          }
      }
      
  3. Post-Generation Hooks

    • Use Symfony’s Process component to run scripts after generation:
      $process = new Process(['git', 'add', $outputPath]);
      $process->run();
      
  4. Database Integration

    • If generating entities, integrate with Doctrine’s SchemaManager:
      $schemaManager = $this->get('doctrine')->getManager()->getConnection()->getSchemaManager();
      
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.
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours