IOInterface.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. /**
  13. * The Input/Output helper interface.
  14. *
  15. * @author François Pluchino <francois.pluchino@opendisplay.com>
  16. */
  17. interface IOInterface
  18. {
  19. /**
  20. * Is this input means interactive?
  21. *
  22. * @return Boolean
  23. */
  24. function isInteractive();
  25. /**
  26. * Is this input verbose?
  27. *
  28. * @return Boolean
  29. */
  30. function isVerbose();
  31. /**
  32. * Writes a message to the output.
  33. *
  34. * @param string|array $messages The message as an array of lines or a single string
  35. * @param Boolean $newline Whether to add a newline or not
  36. */
  37. function write($messages, $newline = true);
  38. /**
  39. * Overwrites a previous message to the output.
  40. *
  41. * @param string|array $messages The message as an array of lines or a single string
  42. * @param Boolean $newline Whether to add a newline or not
  43. * @param integer $size The size of line
  44. */
  45. function overwrite($messages, $newline = true, $size = 80);
  46. /**
  47. * Asks a question to the user.
  48. *
  49. * @param string|array $question The question to ask
  50. * @param string $default The default answer if none is given by the user
  51. *
  52. * @return string The user answer
  53. *
  54. * @throws \RuntimeException If there is no data to read in the input stream
  55. */
  56. function ask($question, $default = null);
  57. /**
  58. * Asks a confirmation to the user.
  59. *
  60. * The question will be asked until the user answers by nothing, yes, or no.
  61. *
  62. * @param string|array $question The question to ask
  63. * @param Boolean $default The default answer if the user enters nothing
  64. *
  65. * @return Boolean true if the user has confirmed, false otherwise
  66. */
  67. function askConfirmation($question, $default = true);
  68. /**
  69. * Asks for a value and validates the response.
  70. *
  71. * The validator receives the data to validate. It must return the
  72. * validated data when the data is valid and throw an exception
  73. * otherwise.
  74. *
  75. * @param string|array $question The question to ask
  76. * @param callback $validator A PHP callback
  77. * @param integer $attempts Max number of times to ask before giving up (false by default, which means infinite)
  78. * @param string $default The default answer if none is given by the user
  79. *
  80. * @return mixed
  81. *
  82. * @throws \Exception When any of the validators return an error
  83. */
  84. function askAndValidate($question, $validator, $attempts = false, $default = null);
  85. /**
  86. * Asks a question to the user and hide the answer.
  87. *
  88. * @param string $question The question to ask
  89. *
  90. * @return string The answer
  91. */
  92. function askAndHideAnswer($question);
  93. /**
  94. * Get the last username entered.
  95. *
  96. * @return string The username
  97. */
  98. function getLastUsername();
  99. /**
  100. * Get the last password entered.
  101. *
  102. * @return string The password
  103. */
  104. function getLastPassword();
  105. /**
  106. * Get all authorization informations entered.
  107. *
  108. * @return array The map of authorization
  109. */
  110. function getAuthorizations();
  111. /**
  112. * Verify if the repository has a authorization informations.
  113. *
  114. * @param string $repositoryName The unique name of repository
  115. *
  116. * @return boolean
  117. */
  118. function hasAuthorization($repositoryName);
  119. /**
  120. * Get the username and password of repository.
  121. *
  122. * @param string $repositoryName The unique name of repository
  123. *
  124. * @return array The 'username' and 'password'
  125. */
  126. function getAuthorization($repositoryName);
  127. /**
  128. * Set the authorization informations for the repository.
  129. *
  130. * @param string $repositoryName The unique name of repository
  131. * @param string $username The username
  132. * @param string $password The password
  133. */
  134. function setAuthorization($repositoryName, $username, $password = null);
  135. }