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],
];
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.)
Where to Look First
src/Command/ for generator logic (e.g., GenerateBasicCommand.php).Resources/views/ or Resources/templates/ for Twig/Php templates.config/ or Resources/config/ for customizable settings.Command-Driven Workflows
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
}
}
services.yaml:
services:
App\Command\CustomGeneratorCommand:
tags: ['console.command']
Template Integration
{# Resources/templates/custom_class.php.twig #}
<?php
namespace App\Entity;
class {{ className }} {
// Auto-generated logic
}
$template = $this->get('twig')->createTemplate($templatePath);
$content = $template->render(['className' => $name]);
Event-Driven Extensions
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
}
}
Filesystem, Twig) into commands for reusable logic.config/packages/edlcdmc_generator.yaml:
edlcdmc_generator:
default_namespace: 'App\Generated'
output_dir: '%kernel.project_dir%/src/Generated'
Symfony\Component\Filesystem\Filesystem in tests.Undocumented Features
src/ for undocumented behaviors (e.g., hardcoded paths, missing events).php bin/console debug:container Edlcdmc to explore services.File Overwrites
--force flag or pre-checks:
if (file_exists($outputPath) && !$this->option('force')) {
throw new \RuntimeException("File exists. Use --force to overwrite.");
}
Namespace Collisions
onPreGenerate events or via CLI args.Template Escaping
{{ className|e('html') }} {# Escape for HTML context #}
var_dump($input->getArguments()) or dd($this->getContainer()->getParameter('kernel.project_dir')) to inspect inputs.output_dir is writable:
chmod -R 775 %kernel.project_dir%/src/Generated
# config/packages/dev/debug.yaml
framework:
profiler: { only_exceptions: false }
Custom Templates
templates/edlcdmc/ (Symfony’s template loader will prioritize these).Generator Metadata
Generator class (if abstract) to add metadata like:
class CustomGenerator extends AbstractGenerator {
public function getDescription() {
return 'Generates custom boilerplate.';
}
}
Post-Generation Hooks
Process component to run scripts after generation:
$process = new Process(['git', 'add', $outputPath]);
$process->run();
Database Integration
SchemaManager:
$schemaManager = $this->get('doctrine')->getManager()->getConnection()->getSchemaManager();
How can I help you explore Laravel packages today?