IOInterface.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <?php
  2. /*
  3. * This file is part of Composer.
  4. *
  5. * (c) Nils Adermann <naderman@naderman.de>
  6. * Jordi Boggiano <j.boggiano@seld.be>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Composer\IO;
  12. use Composer\Config;
  13. /**
  14. * The Input/Output helper interface.
  15. *
  16. * @author François Pluchino <francois.pluchino@opendisplay.com>
  17. */
  18. interface IOInterface
  19. {
  20. const QUIET = 1;
  21. const NORMAL = 2;
  22. const VERBOSE = 4;
  23. const VERY_VERBOSE = 8;
  24. const DEBUG = 16;
  25. /**
  26. * Is this input means interactive?
  27. *
  28. * @return bool
  29. */
  30. public function isInteractive();
  31. /**
  32. * Is this output verbose?
  33. *
  34. * @return bool
  35. */
  36. public function isVerbose();
  37. /**
  38. * Is the output very verbose?
  39. *
  40. * @return bool
  41. */
  42. public function isVeryVerbose();
  43. /**
  44. * Is the output in debug verbosity?
  45. *
  46. * @return bool
  47. */
  48. public function isDebug();
  49. /**
  50. * Is this output decorated?
  51. *
  52. * @return bool
  53. */
  54. public function isDecorated();
  55. /**
  56. * Writes a message to the output.
  57. *
  58. * @param string|array $messages The message as an array of lines or a single string
  59. * @param bool $newline Whether to add a newline or not
  60. * @param int $verbosity Verbosity level from the VERBOSITY_* constants
  61. */
  62. public function write($messages, $newline = true, $verbosity = self::NORMAL);
  63. /**
  64. * Writes a message to the error output.
  65. *
  66. * @param string|array $messages The message as an array of lines or a single string
  67. * @param bool $newline Whether to add a newline or not
  68. * @param int $verbosity Verbosity level from the VERBOSITY_* constants
  69. */
  70. public function writeError($messages, $newline = true, $verbosity = self::NORMAL);
  71. /**
  72. * Overwrites a previous message to the output.
  73. *
  74. * @param string|array $messages The message as an array of lines or a single string
  75. * @param bool $newline Whether to add a newline or not
  76. * @param int $size The size of line
  77. * @param int $verbosity Verbosity level from the VERBOSITY_* constants
  78. */
  79. public function overwrite($messages, $newline = true, $size = null, $verbosity = self::NORMAL);
  80. /**
  81. * Overwrites a previous message to the error output.
  82. *
  83. * @param string|array $messages The message as an array of lines or a single string
  84. * @param bool $newline Whether to add a newline or not
  85. * @param int $size The size of line
  86. * @param int $verbosity Verbosity level from the VERBOSITY_* constants
  87. */
  88. public function overwriteError($messages, $newline = true, $size = null, $verbosity = self::NORMAL);
  89. /**
  90. * Asks a question to the user.
  91. *
  92. * @param string|array $question The question to ask
  93. * @param string $default The default answer if none is given by the user
  94. *
  95. * @throws \RuntimeException If there is no data to read in the input stream
  96. * @return string The user answer
  97. */
  98. public function ask($question, $default = null);
  99. /**
  100. * Asks a confirmation to the user.
  101. *
  102. * The question will be asked until the user answers by nothing, yes, or no.
  103. *
  104. * @param string|array $question The question to ask
  105. * @param bool $default The default answer if the user enters nothing
  106. *
  107. * @return bool true if the user has confirmed, false otherwise
  108. */
  109. public function askConfirmation($question, $default = true);
  110. /**
  111. * Asks for a value and validates the response.
  112. *
  113. * The validator receives the data to validate. It must return the
  114. * validated data when the data is valid and throw an exception
  115. * otherwise.
  116. *
  117. * @param string|array $question The question to ask
  118. * @param callback $validator A PHP callback
  119. * @param null|int $attempts Max number of times to ask before giving up (default of null means infinite)
  120. * @param mixed $default The default answer if none is given by the user
  121. *
  122. * @throws \Exception When any of the validators return an error
  123. * @return mixed
  124. */
  125. public function askAndValidate($question, $validator, $attempts = null, $default = null);
  126. /**
  127. * Asks a question to the user and hide the answer.
  128. *
  129. * @param string $question The question to ask
  130. *
  131. * @return string The answer
  132. */
  133. public function askAndHideAnswer($question);
  134. /**
  135. * Asks the user to select a value.
  136. *
  137. * @param string|array $question The question to ask
  138. * @param array $choices List of choices to pick from
  139. * @param bool|string $default The default answer if the user enters nothing
  140. * @param bool|int $attempts Max number of times to ask before giving up (false by default, which means infinite)
  141. * @param string $errorMessage Message which will be shown if invalid value from choice list would be picked
  142. * @param bool $multiselect Select more than one value separated by comma
  143. *
  144. * @throws \InvalidArgumentException
  145. * @return int|string|array The selected value or values (the key of the choices array)
  146. */
  147. public function select($question, $choices, $default, $attempts = false, $errorMessage = 'Value "%s" is invalid', $multiselect = false);
  148. /**
  149. * Get all authentication information entered.
  150. *
  151. * @return array The map of authentication data
  152. */
  153. public function getAuthentications();
  154. /**
  155. * Verify if the repository has a authentication information.
  156. *
  157. * @param string $repositoryName The unique name of repository
  158. *
  159. * @return bool
  160. */
  161. public function hasAuthentication($repositoryName);
  162. /**
  163. * Get the username and password of repository.
  164. *
  165. * @param string $repositoryName The unique name of repository
  166. *
  167. * @return array The 'username' and 'password'
  168. */
  169. public function getAuthentication($repositoryName);
  170. /**
  171. * Set the authentication information for the repository.
  172. *
  173. * @param string $repositoryName The unique name of repository
  174. * @param string $username The username
  175. * @param string $password The password
  176. */
  177. public function setAuthentication($repositoryName, $username, $password = null);
  178. /**
  179. * Loads authentications from a config instance
  180. *
  181. * @param Config $config
  182. */
  183. public function loadConfiguration(Config $config);
  184. }