You are here

class BaseCommand in Automatic Updates 8

Base command class.

Hierarchy

  • class \Drupal\automatic_updates\Command\BaseCommand extends \Symfony\Component\Console\Command\Command

Expanded class hierarchy of BaseCommand

File

src/Command/BaseCommand.php, line 15

Namespace

Drupal\automatic_updates\Command
View source
class BaseCommand extends Command {

  /**
   * The class loader.
   *
   * @var object
   */
  protected $classLoader;

  /**
   * Constructs a new InstallCommand command.
   *
   * @param object $class_loader
   *   The class loader.
   */
  public function __construct($class_loader) {
    $this->classLoader = $class_loader;
    parent::__construct();
  }

  /**
   * {@inheritdoc}
   */
  protected function configure() {
    parent::configure();
    $this
      ->addOption('script-filename', NULL, InputOption::VALUE_REQUIRED, 'The script filename')
      ->addOption('base-url', NULL, InputOption::VALUE_REQUIRED, 'The base URL, i.e. http://example.com/index.php')
      ->addOption('base-path', NULL, InputOption::VALUE_REQUIRED, 'The base path, i.e. http://example.com');
  }

  /**
   * {@inheritdoc}
   */
  protected function execute(InputInterface $input, OutputInterface $output) {
    $this
      ->bootstrapDrupal($input);
  }

  /**
   * Bootstrap Drupal.
   *
   * @param \Symfony\Component\Console\Input\InputInterface $input
   *   The input.
   */
  protected function bootstrapDrupal(InputInterface $input) {
    $kernel = new DrupalKernel('prod', $this->classLoader);
    $script_filename = $input
      ->getOption('script-filename');
    $base_url = $input
      ->getOption('base-url');
    $base_path = $input
      ->getOption('base-path');
    $server = [
      'SCRIPT_FILENAME' => $script_filename,
      'SCRIPT_NAME' => $base_url,
    ];
    $request = Request::create($base_path, 'GET', [], [], [], $server);
    $kernel
      ->handle($request);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
BaseCommand::$classLoader protected property The class loader.
BaseCommand::bootstrapDrupal protected function Bootstrap Drupal.
BaseCommand::configure protected function Configures the current command. 3
BaseCommand::execute protected function Executes the current command. 3
BaseCommand::__construct public function Constructs a new InstallCommand command.