You are here

abstract class CommandBase in Apigee Edge 8

Class CommandBase for shared functionality.

Hierarchy

  • class \Drupal\apigee_edge\Command\CommandBase extends \Drupal\Console\Core\Command\Command uses \Drupal\Console\Core\Command\Shared\CommandTrait

Expanded class hierarchy of CommandBase

File

src/Command/CommandBase.php, line 36

Namespace

Drupal\apigee_edge\Command
View source
abstract class CommandBase extends Command {
  use CommandTrait;

  /**
   * The interoperability cli service.
   *
   * @var \Drupal\apigee_edge\CliServiceInterface
   */
  protected $cliService;

  /**
   * The IO interface composed of a commands input and output.
   *
   * @var \Symfony\Component\Console\Style\StyleInterface
   */
  protected $io;

  /**
   * The parser object.
   *
   * @var \Drupal\Core\Logger\LogMessageParserInterface
   */
  protected $logMessageParser;

  /**
   * The logger channel factory.
   *
   * @var \Drupal\Core\Logger\LoggerChannelFactoryInterface
   */
  protected $loggerChannelFactory;

  /**
   * Constructor with cli service injection.
   *
   * @param \Drupal\apigee_edge\CliServiceInterface $cli_service
   *   The cli service to delegate all actions to.
   * @param \Drupal\Core\Logger\LogMessageParserInterface $log_message_parser
   *   The parser to use when extracting message variables.
   * @param \Drupal\Core\Logger\LoggerChannelFactoryInterface $logger_channel_factory
   *   The logger channel factory.
   */
  public function __construct(CliServiceInterface $cli_service, LogMessageParserInterface $log_message_parser, LoggerChannelFactoryInterface $logger_channel_factory) {
    parent::__construct();
    $this->cliService = $cli_service;
    $this->logMessageParser = $log_message_parser;
    $this->loggerChannelFactory = $logger_channel_factory;
  }

  /**
   * Sets up the IO interface.
   *
   * @param \Symfony\Component\Console\Input\InputInterface $input
   *   The input interface.
   * @param \Symfony\Component\Console\Output\OutputInterface $output
   *   The output interface.
   */
  protected function setupIo(InputInterface $input, OutputInterface $output) {
    $this->io = new DrupalStyle($input, $output);
    $this
      ->setupLogger($output);
  }

  /**
   * Sets up the logger service.
   *
   * The service redirects Drupal logging messages to the console output.
   *
   * @param \Symfony\Component\Console\Output\OutputInterface $output
   *   The output interface.
   */
  protected function setupLogger(OutputInterface $output) {
    $drupal_console_logger = new ConsoleLogger($output);
    $logger = new DrupalConsoleLog($this->logMessageParser, $drupal_console_logger);
    $this->loggerChannelFactory
      ->addLogger($logger);
  }

  /**
   * Gets the IO interface.
   *
   * @return \Symfony\Component\Console\Style\StyleInterface
   *   The IO interface.
   */
  public function getIo() : StyleInterface {
    return $this->io;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CommandBase::$cliService protected property The interoperability cli service.
CommandBase::$io protected property The IO interface composed of a commands input and output.
CommandBase::$loggerChannelFactory protected property The logger channel factory.
CommandBase::$logMessageParser protected property The parser object.
CommandBase::getIo public function Gets the IO interface.
CommandBase::setupIo protected function Sets up the IO interface.
CommandBase::setupLogger protected function Sets up the logger service.
CommandBase::__construct public function Constructor with cli service injection.