|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- <?php
-
- namespace Lc\SovBundle\Maker;
-
- use Doctrine\Common\Annotations\Annotation;
- use Symfony\Bundle\MakerBundle\ConsoleStyle;
- use Symfony\Bundle\MakerBundle\DependencyBuilder;
- use Symfony\Bundle\MakerBundle\Generator;
- use Symfony\Bundle\MakerBundle\InputConfiguration;
- use Symfony\Bundle\MakerBundle\Maker\AbstractMaker;
- use Symfony\Component\Console\Command\Command;
- use Symfony\Component\Console\Input\InputArgument;
- use Symfony\Component\Console\Input\InputInterface;
-
- use function Symfony\Component\String\u;
-
- class FactoryMaker extends AbstractMaker
- {
- public static function getCommandName(): string
- {
- return 'make:factory';
- }
-
- public static function getCommandDescription(): string
- {
- return 'Creates a factory';
- }
-
- public function configureCommand(Command $command, InputConfiguration $inputConf)
- {
- $command
- /*->addArgument(
- 'factory-class',
- InputArgument::OPTIONAL,
- 'Choose a name for your factory (e.g. <fg=yellow>MyEntityFactory</>)'
- )*/
- ->addArgument(
- 'namespace',
- InputArgument::OPTIONAL,
- 'Namespace (e.g. <fg=yellow>Lc\SovBundle\Factory</>)'
- )
- ->addArgument(
- 'domain',
- InputArgument::OPTIONAL,
- 'Domain (e.g. <fg=yellow>Order</>)'
- )
- ->addArgument(
- 'entity-class',
- InputArgument::OPTIONAL,
- 'Define the entity (e.g. <fg=yellow>MyEntity</>)'
- )
- ->setHelp('');
- }
-
- public function generate(InputInterface $input, ConsoleStyle $io, Generator $generator)
- {
- $entityDetails = $generator->createClassNameDetails(
- $input->getArgument('entity-class'),
- 'Entity\\',
- ''
- );
-
- $factoryClass = $input->getArgument('entity-class') . 'Factory';
- $factoryDetails = $generator->createClassNameDetails(
- $factoryClass,
- 'Factory\\',
- ''
- );
-
- $options = [
- 'namespace_path' => $input->getArgument('namespace'),
- 'domain' => $input->getArgument('domain'),
- 'entity_class' => $input->getArgument('entity-class'),
- 'entity' => $entityDetails->getFullName(),
- 'entity_variable' => '$' . u($input->getArgument('entity-class'))->camel()
- ];
-
- $generator->generateController(
- $factoryDetails->getFullName(),
- __DIR__ . '/../Resources/maker/factory/factory.tpl.php',
- $options
- );
-
- $interfaceName = $factoryClass . 'Interface';
- $generator->generateFile(
- $generator->getRootDirectory() . '/src/Factory/' . $interfaceName . '.php',
- __DIR__ . '/../Resources/maker/factory/factory_interface.tpl.php',
- [
- 'namespace_path' => $input->getArgument('namespace'),
- 'domain' => $input->getArgument('domain'),
- 'interface_name' => $interfaceName,
- ]
- );
-
- $generator->writeChanges();
-
- $this->writeSuccessMessage($io);
- $io->text('Next: Open your new factory class and configure it!');
- }
-
- public function configureDependencies(DependencyBuilder $dependencies)
- {
- $dependencies->addClassDependency(
- Annotation::class,
- 'doctrine/annotations'
- );
- }
- }
|