CommandList.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\SampleData\Console;
  7. use Magento\Framework\ObjectManagerInterface;
  8. /**
  9. * Class CommandList
  10. */
  11. class CommandList implements \Magento\Framework\Console\CommandListInterface
  12. {
  13. /**
  14. * Object Manager
  15. *
  16. * @var ObjectManagerInterface
  17. */
  18. private $objectManager;
  19. /**
  20. * @param ObjectManagerInterface $objectManager
  21. */
  22. public function __construct(ObjectManagerInterface $objectManager)
  23. {
  24. $this->objectManager = $objectManager;
  25. }
  26. /**
  27. * Gets list of command classes
  28. *
  29. * @return string[]
  30. */
  31. protected function getCommandsClasses()
  32. {
  33. return [
  34. \Magento\SampleData\Console\Command\SampleDataDeployCommand::class,
  35. \Magento\SampleData\Console\Command\SampleDataRemoveCommand::class
  36. ];
  37. }
  38. /**
  39. * {@inheritdoc}
  40. */
  41. public function getCommands()
  42. {
  43. $commands = [];
  44. foreach ($this->getCommandsClasses() as $class) {
  45. if (class_exists($class)) {
  46. $commands[] = $this->objectManager->get($class);
  47. } else {
  48. throw new \Exception('Class ' . $class . ' does not exist');
  49. }
  50. }
  51. return $commands;
  52. }
  53. }