CompletionSuggestions.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Console\Completion;
  11. use Symfony\Component\Console\Input\InputOption;
  12. /**
  13. * Stores all completion suggestions for the current input.
  14. *
  15. * @author Wouter de Jong <wouter@wouterj.nl>
  16. */
  17. final class CompletionSuggestions
  18. {
  19. private $valueSuggestions = [];
  20. private $optionSuggestions = [];
  21. /**
  22. * Add a suggested value for an input option or argument.
  23. *
  24. * @param string|Suggestion $value
  25. *
  26. * @return $this
  27. */
  28. public function suggestValue($value): self
  29. {
  30. $this->valueSuggestions[] = !$value instanceof Suggestion ? new Suggestion($value) : $value;
  31. return $this;
  32. }
  33. /**
  34. * Add multiple suggested values at once for an input option or argument.
  35. *
  36. * @param list<string|Suggestion> $values
  37. *
  38. * @return $this
  39. */
  40. public function suggestValues(array $values): self
  41. {
  42. foreach ($values as $value) {
  43. $this->suggestValue($value);
  44. }
  45. return $this;
  46. }
  47. /**
  48. * Add a suggestion for an input option name.
  49. *
  50. * @return $this
  51. */
  52. public function suggestOption(InputOption $option): self
  53. {
  54. $this->optionSuggestions[] = $option;
  55. return $this;
  56. }
  57. /**
  58. * Add multiple suggestions for input option names at once.
  59. *
  60. * @param InputOption[] $options
  61. *
  62. * @return $this
  63. */
  64. public function suggestOptions(array $options): self
  65. {
  66. foreach ($options as $option) {
  67. $this->suggestOption($option);
  68. }
  69. return $this;
  70. }
  71. /**
  72. * @return InputOption[]
  73. */
  74. public function getOptionSuggestions(): array
  75. {
  76. return $this->optionSuggestions;
  77. }
  78. /**
  79. * @return Suggestion[]
  80. */
  81. public function getValueSuggestions(): array
  82. {
  83. return $this->valueSuggestions;
  84. }
  85. }