class ConsoleExampleCommand

Same name and namespace in other branches
  1. main core/modules/system/tests/modules/console_test/src/Command/ConsoleExampleCommand.php \Drupal\console_test\Command\ConsoleExampleCommand

An example command.

@internal

Attributes

#[AsCommand(name: 'example:command', description: 'An example command.')]

Hierarchy

  • class \Drupal\console_test\Command\ConsoleExampleCommand extends \Symfony\Component\Console\Command\Command

Expanded class hierarchy of ConsoleExampleCommand

1 file declares its use of ConsoleExampleCommand
ConsoleTest.php in core/tests/Drupal/KernelTests/Core/Console/ConsoleTest.php

File

core/modules/system/tests/modules/console_test/src/Command/ConsoleExampleCommand.php, line 23

Namespace

Drupal\console_test\Command
View source
class ConsoleExampleCommand extends Command {
  
  /**
   * Constructs a command with autowiring.
   */
  public function __construct(protected readonly TestService $testService, #[Autowire(service: 'logger.channel.default')] protected LoggerInterface $logger) {
    parent::__construct();
  }
  
  /**
   * {@inheritdoc}
   */
  protected function configure() : void {
    $this->addArgument('argument-test', mode: InputArgument::OPTIONAL)
      ->addOption('option-test', mode: InputOption::VALUE_NONE);
  }
  
  /**
   * {@inheritdoc}
   */
  protected function execute(InputInterface $input, OutputInterface $output) : int {
    $io = new SymfonyStyle($input, $output);
    $this->logger
      ->notice('Option test: ' . ($input->getOption('option-test') ? 'Yes' : 'No'));
    $this->logger
      ->notice('Argument test: ' . ($input->getArgument('argument-test') ? 'Yes' : 'No'));
    $this->logger
      ->notice('Dependency injection test: ' . $this->testService
      ->getTestInjection()::class);
    $io->success('Done.');
    return Command::SUCCESS;
  }

}

Members

Title Sort descending Modifiers Object type Summary
ConsoleExampleCommand::configure protected function
ConsoleExampleCommand::execute protected function
ConsoleExampleCommand::__construct public function Constructs a command with autowiring.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.