InputInterface.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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();
  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($values, $onlyParams = false);
  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($values, $default = false, $onlyParams = false);
  54. /**
  55. * Binds the current Input instance with the given arguments and options.
  56. *
  57. * @return void
  58. *
  59. * @throws RuntimeException
  60. * @param \Symfony\Component\Console\Input\InputDefinition $definition
  61. */
  62. public function bind($definition);
  63. /**
  64. * Validates the input.
  65. *
  66. * @return void
  67. *
  68. * @throws RuntimeException When not enough arguments are given
  69. */
  70. public function validate();
  71. /**
  72. * Returns all the given arguments merged with the default values.
  73. *
  74. * @return array<string|bool|int|float|array|null>
  75. */
  76. public function getArguments();
  77. /**
  78. * Returns the argument value for a given argument name.
  79. *
  80. * @return mixed
  81. *
  82. * @throws InvalidArgumentException When argument given doesn't exist
  83. * @param string $name
  84. */
  85. public function getArgument($name);
  86. /**
  87. * Sets an argument value by name.
  88. *
  89. * @return void
  90. *
  91. * @throws InvalidArgumentException When argument given doesn't exist
  92. * @param mixed $value
  93. * @param string $name
  94. */
  95. public function setArgument($name, $value);
  96. /**
  97. * Returns true if an InputArgument object exists by name or position.
  98. * @param string $name
  99. */
  100. public function hasArgument($name);
  101. /**
  102. * Returns all the given options merged with the default values.
  103. *
  104. * @return array<string|bool|int|float|array|null>
  105. */
  106. public function getOptions();
  107. /**
  108. * Returns the option value for a given option name.
  109. *
  110. * @return mixed
  111. *
  112. * @throws InvalidArgumentException When option given doesn't exist
  113. * @param string $name
  114. */
  115. public function getOption($name);
  116. /**
  117. * Sets an option value by name.
  118. *
  119. * @return void
  120. *
  121. * @throws InvalidArgumentException When option given doesn't exist
  122. * @param mixed $value
  123. * @param string $name
  124. */
  125. public function setOption($name, $value);
  126. /**
  127. * Returns true if an InputOption object exists by name.
  128. * @param string $name
  129. */
  130. public function hasOption($name);
  131. /**
  132. * Is this input means interactive?
  133. */
  134. public function isInteractive();
  135. /**
  136. * Sets the input interactivity.
  137. *
  138. * @return void
  139. * @param bool $interactive
  140. */
  141. public function setInteractive($interactive);
  142. }