InputInterface.php 4.8KB

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