You are here

class StaticExportPathCommand in Tome 8

Contains the tome:static-export-path command.

@internal

Hierarchy

Expanded class hierarchy of StaticExportPathCommand

1 string reference to 'StaticExportPathCommand'
tome_static.services.yml in modules/tome_static/tome_static.services.yml
modules/tome_static/tome_static.services.yml
1 service uses StaticExportPathCommand
tome_static.static_export_path_command in modules/tome_static/tome_static.services.yml
Drupal\tome_static\Commands\StaticExportPathCommand

File

modules/tome_static/src/Commands/StaticExportPathCommand.php, line 18

Namespace

Drupal\tome_static\Commands
View source
class StaticExportPathCommand extends StaticCommand {

  /**
   * The default number of retry per failed process.
   */
  const RETRY_COUNT = 1;

  /**
   * The request preparer.
   *
   * @var \Drupal\tome_static\RequestPreparer
   */
  protected $requestPreparer;

  /**
   * Constructs a StaticCommand instance.
   *
   * @param \Drupal\tome_static\StaticGeneratorInterface $static
   *   The static service.
   * @param \Drupal\Core\State\StateInterface $state
   *   The state system.
   * @param \Drupal\tome_static\RequestPreparer $request_preparer
   *   The request preparer.
   */
  public function __construct(StaticGeneratorInterface $static, StateInterface $state, RequestPreparer $request_preparer) {
    parent::__construct($static, $state);
    $this->requestPreparer = $request_preparer;
  }

  /**
   * {@inheritdoc}
   */
  protected function configure() {
    $this
      ->setName('tome:static-export-path')
      ->setDescription('Exports static HTML for a specific path.')
      ->addArgument('chunk', InputArgument::REQUIRED, 'A comma separated list of paths.')
      ->addOption('process-count', NULL, InputOption::VALUE_OPTIONAL, 'Limits the number of processes to run concurrently.', static::PROCESS_COUNT)
      ->addOption('path-count', NULL, InputOption::VALUE_OPTIONAL, 'The number of paths to export per process.', static::PATH_COUNT)
      ->addOption('return-json', NULL, InputOption::VALUE_NONE, 'Whether or not paths that need invoking should be returned as JSON.')
      ->addOption('retry-count', NULL, InputOption::VALUE_OPTIONAL, 'The number of retry per failed process', static::RETRY_COUNT);
  }

  /**
   * {@inheritdoc}
   */
  protected function execute(InputInterface $input, OutputInterface $output) {
    $chunk = $input
      ->getArgument('chunk');
    $paths = explode(',', $chunk);
    $invoke_paths = [];
    foreach ($paths as $path) {
      $this->requestPreparer
        ->prepareForRequest();
      try {
        $invoke_paths = array_merge($this->static
          ->requestPath($path), $invoke_paths);
      } catch (\Exception $e) {
        $this->io
          ->getErrorStyle()
          ->error($this
          ->formatPathException($path, $e));
      }
    }
    $options = $input
      ->getOptions();
    if ($options['return-json']) {
      $this->io
        ->write(json_encode($invoke_paths, JSON_PRETTY_PRINT));
    }
    else {
      $this
        ->exportPaths($invoke_paths, $paths, $options['process-count'], $options['path-count'], FALSE, $options['retry-count'], $options['uri']);
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CommandBase::$executable protected property The current executable path.
CommandBase::$io protected property The IO decorator.
CommandBase::initialize protected function
CommandBase::io protected function Returns the IO decorator, for reporting errors. Overrides ProcessTrait::io
ExecutableFinderTrait::findExecutable protected function Finds an executable string for the current process.
ProcessTrait::displayErrors protected function Displays errors using the IO component.
ProcessTrait::runCommand protected function Runs a single command and outputs errors if encountered.
ProcessTrait::runCommands protected function Runs commands with concurrency.
StaticCommand::$state protected property The state system.
StaticCommand::$static protected property The static service.
StaticCommand::exportPaths protected function Exports the given paths to the static directory.
StaticCommand::PATH_COUNT constant The default number of paths to export per process.
StaticCommand::PROCESS_COUNT constant The default number of processes to invoke.
StaticExportPathCommand::$requestPreparer protected property The request preparer.
StaticExportPathCommand::configure protected function Overrides StaticCommand::configure
StaticExportPathCommand::execute protected function Overrides StaticCommand::execute
StaticExportPathCommand::RETRY_COUNT constant The default number of retry per failed process. Overrides StaticCommand::RETRY_COUNT
StaticExportPathCommand::__construct public function Constructs a StaticCommand instance. Overrides StaticCommand::__construct
StaticUITrait::formatPathException protected function Formats an exception caught when requesting a path.
StaticUITrait::getWarnings protected function Collects warnings to help users correct issues in rendered HTML.
StaticUITrait::t abstract protected function Translates a string to the current language or to a given language.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2