vendor/symfony/maker-bundle/src/DependencyInjection/CompilerPass/MakeCommandRegistrationPass.php line 37

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony MakerBundle package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Symfony\Bundle\MakerBundle\DependencyInjection\CompilerPass;
  11. use Symfony\Bundle\MakerBundle\Command\MakerCommand;
  12. use Symfony\Bundle\MakerBundle\MakerInterface;
  13. use Symfony\Bundle\MakerBundle\Str;
  14. use Symfony\Component\Console\Command\LazyCommand;
  15. use Symfony\Component\DependencyInjection\ChildDefinition;
  16. use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
  17. use Symfony\Component\DependencyInjection\ContainerBuilder;
  18. use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
  19. use Symfony\Component\DependencyInjection\Reference;
  20. class MakeCommandRegistrationPass implements CompilerPassInterface
  21. {
  22.     public const MAKER_TAG 'maker.command';
  23.     public function process(ContainerBuilder $container): void
  24.     {
  25.         foreach ($container->findTaggedServiceIds(self::MAKER_TAG) as $id => $tags) {
  26.             $def $container->getDefinition($id);
  27.             if ($def->isDeprecated()) {
  28.                 continue;
  29.             }
  30.             $class $container->getParameterBag()->resolveValue($def->getClass());
  31.             if (!is_subclass_of($classMakerInterface::class)) {
  32.                 throw new InvalidArgumentException(sprintf('Service "%s" must implement interface "%s".'$idMakerInterface::class));
  33.             }
  34.             $commandDefinition = new ChildDefinition('maker.auto_command.abstract');
  35.             $commandDefinition->setClass(MakerCommand::class);
  36.             $commandDefinition->replaceArgument(0, new Reference($id));
  37.             $tagAttributes = ['command' => $class::getCommandName()];
  38.             if (!method_exists($class'getCommandDescription')) {
  39.                 // no-op
  40.             } elseif (class_exists(LazyCommand::class)) {
  41.                 $tagAttributes['description'] = $class::getCommandDescription();
  42.             } else {
  43.                 $commandDefinition->addMethodCall('setDescription', [$class::getCommandDescription()]);
  44.             }
  45.             $commandDefinition->addTag('console.command'$tagAttributes);
  46.             /*
  47.              * @deprecated remove this block when removing make:unit-test and make:functional-test
  48.              */
  49.             if (method_exists($class'getCommandAliases')) {
  50.                 foreach ($class::getCommandAliases() as $alias) {
  51.                     $commandDefinition->addTag('console.command', ['command' => $alias'description' => 'Deprecated alias of "make:test"']);
  52.                 }
  53.             }
  54.             $container->setDefinition(sprintf('maker.auto_command.%s'Str::asTwigVariable($class::getCommandName())), $commandDefinition);
  55.         }
  56.     }
  57. }