InputInterface.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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\Input;
  11. use Symfony\Component\Console\Exception\InvalidArgumentException;
  12. use Symfony\Component\Console\Exception\RuntimeException;
  13. /**
  14. * InputInterface is the interface implemented by all input classes.
  15. *
  16. * @author Fabien Potencier <fabien@symfony.com>
  17. *
  18. * @method string __toString() Returns a stringified representation of the args passed to the command.
  19. * InputArguments MUST be escaped as well as the InputOption values passed to the command.
  20. */
  21. interface InputInterface
  22. {
  23. /**
  24. * Returns the first argument from the raw parameters (not parsed).
  25. */
  26. public function getFirstArgument(): ?string;
  27. /**
  28. * Returns true if the raw parameters (not parsed) contain a value.
  29. *
  30. * This method is to be used to introspect the input parameters
  31. * before they have been validated. It must be used carefully.
  32. * Does not necessarily return the correct result for short options
  33. * when multiple flags are combined in the same option.
  34. *
  35. * @param string|array $values The values to look for in the raw parameters (can be an array)
  36. * @param bool $onlyParams Only check real parameters, skip those following an end of options (--) signal
  37. */
  38. public function hasParameterOption(string|array $values, bool $onlyParams = false): bool;
  39. /**
  40. * Returns the value of a raw option (not parsed).
  41. *
  42. * This method is to be used to introspect the input parameters
  43. * before they have been validated. It must be used carefully.
  44. * Does not necessarily return the correct result for short options
  45. * when multiple flags are combined in the same option.
  46. *
  47. * @param string|array $values The value(s) to look for in the raw parameters (can be an array)
  48. * @param string|bool|int|float|array|null $default The default value to return if no result is found
  49. * @param bool $onlyParams Only check real parameters, skip those following an end of options (--) signal
  50. *
  51. * @return mixed
  52. */
  53. public function getParameterOption(string|array $values, string|bool|int|float|array|null $default = false, bool $onlyParams = false);
  54. /**
  55. * Binds the current Input instance with the given arguments and options.
  56. *
  57. * @return void
  58. *
  59. * @throws RuntimeException
  60. */
  61. public function bind(InputDefinition $definition);
  62. /**
  63. * Validates the input.
  64. *
  65. * @return void
  66. *
  67. * @throws RuntimeException When not enough arguments are given
  68. */
  69. public function validate();
  70. /**
  71. * Returns all the given arguments merged with the default values.
  72. *
  73. * @return array<string|bool|int|float|array|null>
  74. */
  75. public function getArguments(): array;
  76. /**
  77. * Returns the argument value for a given argument name.
  78. *
  79. * @return mixed
  80. *
  81. * @throws InvalidArgumentException When argument given doesn't exist
  82. */
  83. public function getArgument(string $name);
  84. /**
  85. * Sets an argument value by name.
  86. *
  87. * @return void
  88. *
  89. * @throws InvalidArgumentException When argument given doesn't exist
  90. */
  91. public function setArgument(string $name, mixed $value);
  92. /**
  93. * Returns true if an InputArgument object exists by name or position.
  94. */
  95. public function hasArgument(string $name): bool;
  96. /**
  97. * Returns all the given options merged with the default values.
  98. *
  99. * @return array<string|bool|int|float|array|null>
  100. */
  101. public function getOptions(): array;
  102. /**
  103. * Returns the option value for a given option name.
  104. *
  105. * @return mixed
  106. *
  107. * @throws InvalidArgumentException When option given doesn't exist
  108. */
  109. public function getOption(string $name);
  110. /**
  111. * Sets an option value by name.
  112. *
  113. * @return void
  114. *
  115. * @throws InvalidArgumentException When option given doesn't exist
  116. */
  117. public function setOption(string $name, mixed $value);
  118. /**
  119. * Returns true if an InputOption object exists by name.
  120. */
  121. public function hasOption(string $name): bool;
  122. /**
  123. * Is this input means interactive?
  124. */
  125. public function isInteractive(): bool;
  126. /**
  127. * Sets the input interactivity.
  128. *
  129. * @return void
  130. */
  131. public function setInteractive(bool $interactive);
  132. }