CompletionSuggestions.php 2.1 KB

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