Skip to content

Commit

Permalink
Make "abstract" command and remove entity namespace from config
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Rabochiy committed May 7, 2018
1 parent 51d7138 commit d4139d4
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
use Symfony\Bundle\MakerBundle\Command\MakerCommand;
use Symfony\Bundle\MakerBundle\MakerInterface;
use Symfony\Bundle\MakerBundle\Str;
use Symfony\Component\DependencyInjection\ChildDefinition;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
use Symfony\Component\DependencyInjection\Parameter;
use Symfony\Component\DependencyInjection\Reference;

class MakeCommandRegistrationPass implements CompilerPassInterface
Expand All @@ -33,14 +33,12 @@ public function process(ContainerBuilder $container)
throw new InvalidArgumentException(sprintf('Service "%s" must implement interface "%s".', $id, MakerInterface::class));
}

$container->register(
sprintf('maker.auto_command.%s', Str::asTwigVariable($class::getCommandName())),
MakerCommand::class
)->setArguments([
new Reference($id),
new Reference('maker.file_manager'),
new Parameter('maker.root_namespace'),
])->addTag('console.command', ['command' => $class::getCommandName()]);
$commandDefinition = new ChildDefinition('maker.auto_command.abstract');
$commandDefinition->setClass(MakerCommand::class);
$commandDefinition->replaceArgument(0, new Reference($id));
$commandDefinition->addTag('console.command', ['command' => $class::getCommandName()]);

$container->setDefinition(sprintf('maker.auto_command.%s', Str::asTwigVariable($class::getCommandName())), $commandDefinition);
}
}
}
3 changes: 1 addition & 2 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ public function getConfigTreeBuilder()

$rootNode
->children()
->scalarNode('root_namespace')->defaultValue('App')->end()
->scalarNode('entity_namespace')->defaultNull()->end()
->scalarNode('root_namespace')->defaultValue('App')->end()
->end()
;

Expand Down
1 change: 0 additions & 1 deletion src/DependencyInjection/MakerExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public function load(array $configs, ContainerBuilder $container)
$config = $this->processConfiguration($configuration, $configs);

$container->setParameter('maker.root_namespace', $config['root_namespace']);
$container->setParameter('maker.entity_namespace', $config['entity_namespace'] ?: '%maker.root_namespace%\\Entity');

$container->registerForAutoconfiguration(MakerInterface::class)
->addTag(MakeCommandRegistrationPass::MAKER_TAG);
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/config/makers.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<argument type="service" id="maker.file_manager" />
<argument type="service" id="maker.doctrine_helper" />
<argument>%kernel.project_dir%</argument>
<argument>%maker.entity_namespace%</argument>
<argument>%maker.root_namespace%\Entity</argument>
<tag name="maker.command" />
</service>

Expand Down
10 changes: 8 additions & 2 deletions src/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,14 @@
</service>

<service id="maker.doctrine_helper" class="Symfony\Bundle\MakerBundle\Doctrine\DoctrineHelper">
<argument>%maker.entity_namespace%</argument>
<argument type="service" id="doctrine" on-invalid="ignore"/>
<argument>%maker.root_namespace%\Entity</argument>
<argument type="service" id="doctrine" on-invalid="ignore" />
</service>

<service id="maker.auto_command.abstract" class="Symfony\Bundle\MakerBundle\Command\MakerCommand" abstract="true">
<argument /> <!-- maker -->
<argument type="service" id="maker.file_manager" />
<argument>%maker.root_namespace%</argument>
</service>
</services>
</container>

0 comments on commit d4139d4

Please sign in to comment.