InteractiveCollector.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Deploy\Console\Command\App\SensitiveConfigSet;
  7. use Symfony\Component\Console\Input\InputInterface;
  8. use Symfony\Component\Console\Output\OutputInterface;
  9. use Symfony\Component\Console\Question\QuestionFactory;
  10. use Symfony\Component\Console\Helper\QuestionHelper;
  11. /**
  12. * Class InteractiveCollector collects configuration values from user input
  13. */
  14. class InteractiveCollector implements CollectorInterface
  15. {
  16. /**
  17. * @var QuestionFactory
  18. */
  19. private $questionFactory;
  20. /**
  21. * @var QuestionHelper
  22. */
  23. private $questionHelper;
  24. /**
  25. * @param QuestionFactory $questionFactory
  26. * @param QuestionHelper $questionHelper
  27. */
  28. public function __construct(
  29. QuestionFactory $questionFactory,
  30. QuestionHelper $questionHelper
  31. ) {
  32. $this->questionFactory = $questionFactory;
  33. $this->questionHelper = $questionHelper;
  34. }
  35. /**
  36. * Collect list of configuration values from user input
  37. *
  38. * For example, this method will return
  39. *
  40. * ```php
  41. * [
  42. * 'some/configuration/path1' => 'someValue1',
  43. * 'some/configuration/path2' => 'someValue2',
  44. * 'some/configuration/path3' => 'someValue3',
  45. * ]
  46. * ```
  47. * {@inheritdoc}
  48. */
  49. public function getValues(InputInterface $input, OutputInterface $output, array $configPaths)
  50. {
  51. $output->writeln('<info>Please set configuration values or skip them by pressing [Enter]:</info>');
  52. $values = [];
  53. foreach ($configPaths as $configPath) {
  54. $question = $this->questionFactory->create([
  55. 'question' => $configPath . ': '
  56. ]);
  57. $values[$configPath] = $this->questionHelper->ask($input, $output, $question);
  58. }
  59. return $values;
  60. }
  61. }