IOInterface.php 4.1 KB

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