irequest.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. <?php
  2. /**
  3. * @author Bart Visscher <bartv@thisnet.nl>
  4. * @author Jörn Friedrich Dreyer <jfd@butonic.de>
  5. * @author Lukas Reschke <lukas@owncloud.com>
  6. * @author Morris Jobke <hey@morrisjobke.de>
  7. * @author Thomas Müller <thomas.mueller@tmit.eu>
  8. * @author Thomas Tanghus <thomas@tanghus.net>
  9. *
  10. * @copyright Copyright (c) 2015, ownCloud, Inc.
  11. * @license AGPL-3.0
  12. *
  13. * This code is free software: you can redistribute it and/or modify
  14. * it under the terms of the GNU Affero General Public License, version 3,
  15. * as published by the Free Software Foundation.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License, version 3,
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>
  24. *
  25. */
  26. /**
  27. * Public interface of ownCloud for apps to use.
  28. * Request interface
  29. *
  30. */
  31. // use OCP namespace for all classes that are considered public.
  32. // This means that they should be used by apps instead of the internal ownCloud classes
  33. namespace OCP;
  34. /**
  35. * This interface provides an immutable object with with accessors to
  36. * request variables and headers.
  37. *
  38. * Access request variables by method and name.
  39. *
  40. * Examples:
  41. *
  42. * $request->post['myvar']; // Only look for POST variables
  43. * $request->myvar; or $request->{'myvar'}; or $request->{$myvar}
  44. * Looks in the combined GET, POST and urlParams array.
  45. *
  46. * If you access e.g. ->post but the current HTTP request method
  47. * is GET a \LogicException will be thrown.
  48. *
  49. * NOTE:
  50. * - When accessing ->put a stream resource is returned and the accessor
  51. * will return false on subsequent access to ->put or ->patch.
  52. * - When accessing ->patch and the Content-Type is either application/json
  53. * or application/x-www-form-urlencoded (most cases) it will act like ->get
  54. * and ->post and return an array. Otherwise the raw data will be returned.
  55. *
  56. * @property-read string[] $server
  57. * @property-read string[] $urlParams
  58. */
  59. interface IRequest {
  60. /**
  61. * @param string $name
  62. *
  63. * @return string
  64. */
  65. function getHeader($name);
  66. /**
  67. * Lets you access post and get parameters by the index
  68. * In case of json requests the encoded json body is accessed
  69. *
  70. * @param string $key the key which you want to access in the URL Parameter
  71. * placeholder, $_POST or $_GET array.
  72. * The priority how they're returned is the following:
  73. * 1. URL parameters
  74. * 2. POST parameters
  75. * 3. GET parameters
  76. * @param mixed $default If the key is not found, this value will be returned
  77. * @return mixed the content of the array
  78. */
  79. public function getParam($key, $default = null);
  80. /**
  81. * Returns all params that were received, be it from the request
  82. *
  83. * (as GET or POST) or through the URL by the route
  84. * @return array the array with all parameters
  85. */
  86. public function getParams();
  87. /**
  88. * Returns the method of the request
  89. *
  90. * @return string the method of the request (POST, GET, etc)
  91. */
  92. public function getMethod();
  93. /**
  94. * Shortcut for accessing an uploaded file through the $_FILES array
  95. *
  96. * @param string $key the key that will be taken from the $_FILES array
  97. * @return array the file in the $_FILES element
  98. */
  99. public function getUploadedFile($key);
  100. /**
  101. * Shortcut for getting env variables
  102. *
  103. * @param string $key the key that will be taken from the $_ENV array
  104. * @return array the value in the $_ENV element
  105. */
  106. public function getEnv($key);
  107. /**
  108. * Shortcut for getting cookie variables
  109. *
  110. * @param string $key the key that will be taken from the $_COOKIE array
  111. * @return array the value in the $_COOKIE element
  112. */
  113. function getCookie($key);
  114. /**
  115. * Checks if the CSRF check was correct
  116. * @return bool true if CSRF check passed
  117. */
  118. public function passesCSRFCheck();
  119. /**
  120. * Returns an ID for the request, value is not guaranteed to be unique and is mostly meant for logging
  121. * If `mod_unique_id` is installed this value will be taken.
  122. * @return string
  123. */
  124. public function getId();
  125. /**
  126. * Returns the remote address, if the connection came from a trusted proxy
  127. * and `forwarded_for_headers` has been configured then the IP address
  128. * specified in this header will be returned instead.
  129. * Do always use this instead of $_SERVER['REMOTE_ADDR']
  130. * @return string IP address
  131. */
  132. public function getRemoteAddress();
  133. /**
  134. * Returns the server protocol. It respects reverse proxy servers and load
  135. * balancers.
  136. * @return string Server protocol (http or https)
  137. */
  138. public function getServerProtocol();
  139. /**
  140. * Returns the request uri, even if the website uses one or more
  141. * reverse proxies
  142. * @return string
  143. */
  144. public function getRequestUri();
  145. /**
  146. * Get raw PathInfo from request (not urldecoded)
  147. * @throws \Exception
  148. * @return string Path info
  149. */
  150. public function getRawPathInfo();
  151. /**
  152. * Get PathInfo from request
  153. * @throws \Exception
  154. * @return string|false Path info or false when not found
  155. */
  156. public function getPathInfo();
  157. /**
  158. * Returns the script name, even if the website uses one or more
  159. * reverse proxies
  160. * @return string the script name
  161. */
  162. public function getScriptName();
  163. /**
  164. * Checks whether the user agent matches a given regex
  165. * @param array $agent array of agent names
  166. * @return bool true if at least one of the given agent matches, false otherwise
  167. */
  168. public function isUserAgent(array $agent);
  169. /**
  170. * Returns the unverified server host from the headers without checking
  171. * whether it is a trusted domain
  172. * @return string Server host
  173. */
  174. public function getInsecureServerHost();
  175. /**
  176. * Returns the server host from the headers, or the first configured
  177. * trusted domain if the host isn't in the trusted list
  178. * @return string Server host
  179. */
  180. public function getServerHost();
  181. }