CompletionSuggestions.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 array $valueSuggestions = [];
  20. private array $optionSuggestions = [];
  21. /**
  22. * Add a suggested value for an input option or argument.
  23. *
  24. * @return $this
  25. */
  26. public function suggestValue(string|Suggestion $value): static
  27. {
  28. $this->valueSuggestions[] = !$value instanceof Suggestion ? new Suggestion($value) : $value;
  29. return $this;
  30. }
  31. /**
  32. * Add multiple suggested values at once for an input option or argument.
  33. *
  34. * @param list<string|Suggestion> $values
  35. *
  36. * @return $this
  37. */
  38. public function suggestValues(array $values): static
  39. {
  40. foreach ($values as $value) {
  41. $this->suggestValue($value);
  42. }
  43. return $this;
  44. }
  45. /**
  46. * Add a suggestion for an input option name.
  47. *
  48. * @return $this
  49. */
  50. public function suggestOption(InputOption $option): static
  51. {
  52. $this->optionSuggestions[] = $option;
  53. return $this;
  54. }
  55. /**
  56. * Add multiple suggestions for input option names at once.
  57. *
  58. * @param InputOption[] $options
  59. *
  60. * @return $this
  61. */
  62. public function suggestOptions(array $options): static
  63. {
  64. foreach ($options as $option) {
  65. $this->suggestOption($option);
  66. }
  67. return $this;
  68. }
  69. /**
  70. * @return InputOption[]
  71. */
  72. public function getOptionSuggestions(): array
  73. {
  74. return $this->optionSuggestions;
  75. }
  76. /**
  77. * @return Suggestion[]
  78. */
  79. public function getValueSuggestions(): array
  80. {
  81. return $this->valueSuggestions;
  82. }
  83. }