Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AbstractIndexerManageCommand.php
Go to the documentation of this file.
1 <?php
7 
9 use Symfony\Component\Console\Input\InputInterface;
10 use Symfony\Component\Console\Input\InputArgument;
11 
16 {
20  const INPUT_KEY_INDEXERS = 'index';
21 
29  protected function getIndexers(InputInterface $input)
30  {
31  $requestedTypes = [];
32  if ($input->getArgument(self::INPUT_KEY_INDEXERS)) {
33  $requestedTypes = $input->getArgument(self::INPUT_KEY_INDEXERS);
34  $requestedTypes = array_filter(array_map('trim', $requestedTypes), 'strlen');
35  }
36 
37  if (empty($requestedTypes)) {
38  $indexers = $this->getAllIndexers();
39  } else {
40  $availableIndexers = $this->getAllIndexers();
41  $unsupportedTypes = array_diff($requestedTypes, array_keys($availableIndexers));
42  if ($unsupportedTypes) {
43  throw new \InvalidArgumentException(
44  "The following requested index types are not supported: '" . join("', '", $unsupportedTypes)
45  . "'." . PHP_EOL . 'Supported types: ' . join(", ", array_keys($availableIndexers))
46  );
47  }
48  $indexers = array_intersect_key($availableIndexers, array_flip($requestedTypes));
49  }
50 
51  return $indexers;
52  }
53 
59  public function getInputList()
60  {
61  return [
62  new InputArgument(
63  self::INPUT_KEY_INDEXERS,
64  InputArgument::OPTIONAL | InputArgument::IS_ARRAY,
65  'Space-separated list of index types or omit to apply to all indexes.'
66  ),
67  ];
68  }
69 }