You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

irequest.php 6.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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) 2016, 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. * @since 6.0.0
  59. */
  60. interface IRequest {
  61. /**
  62. * @param string $name
  63. *
  64. * @return string
  65. * @since 6.0.0
  66. */
  67. public function getHeader($name);
  68. /**
  69. * Lets you access post and get parameters by the index
  70. * In case of json requests the encoded json body is accessed
  71. *
  72. * @param string $key the key which you want to access in the URL Parameter
  73. * placeholder, $_POST or $_GET array.
  74. * The priority how they're returned is the following:
  75. * 1. URL parameters
  76. * 2. POST parameters
  77. * 3. GET parameters
  78. * @param mixed $default If the key is not found, this value will be returned
  79. * @return mixed the content of the array
  80. * @since 6.0.0
  81. */
  82. public function getParam($key, $default = null);
  83. /**
  84. * Returns all params that were received, be it from the request
  85. *
  86. * (as GET or POST) or through the URL by the route
  87. *
  88. * @return array the array with all parameters
  89. * @since 6.0.0
  90. */
  91. public function getParams();
  92. /**
  93. * Returns the method of the request
  94. *
  95. * @return string the method of the request (POST, GET, etc)
  96. * @since 6.0.0
  97. */
  98. public function getMethod();
  99. /**
  100. * Shortcut for accessing an uploaded file through the $_FILES array
  101. *
  102. * @param string $key the key that will be taken from the $_FILES array
  103. * @return array the file in the $_FILES element
  104. * @since 6.0.0
  105. */
  106. public function getUploadedFile($key);
  107. /**
  108. * Shortcut for getting env variables
  109. *
  110. * @param string $key the key that will be taken from the $_ENV array
  111. * @return array the value in the $_ENV element
  112. * @since 6.0.0
  113. */
  114. public function getEnv($key);
  115. /**
  116. * Shortcut for getting cookie variables
  117. *
  118. * @param string $key the key that will be taken from the $_COOKIE array
  119. * @return array the value in the $_COOKIE element
  120. * @since 6.0.0
  121. */
  122. public function getCookie($key);
  123. /**
  124. * Checks if the CSRF check was correct
  125. *
  126. * @return bool true if CSRF check passed
  127. * @since 6.0.0
  128. */
  129. public function passesCSRFCheck();
  130. /**
  131. * Returns an ID for the request, value is not guaranteed to be unique and is mostly meant for logging
  132. * If `mod_unique_id` is installed this value will be taken.
  133. *
  134. * @return string
  135. * @since 8.1.0
  136. */
  137. public function getId();
  138. /**
  139. * Returns the remote address, if the connection came from a trusted proxy
  140. * and `forwarded_for_headers` has been configured then the IP address
  141. * specified in this header will be returned instead.
  142. * Do always use this instead of $_SERVER['REMOTE_ADDR']
  143. *
  144. * @return string IP address
  145. * @since 8.1.0
  146. */
  147. public function getRemoteAddress();
  148. /**
  149. * Returns the server protocol. It respects reverse proxy servers and load
  150. * balancers.
  151. *
  152. * @return string Server protocol (http or https)
  153. * @since 8.1.0
  154. */
  155. public function getServerProtocol();
  156. /**
  157. * Returns the used HTTP protocol.
  158. *
  159. * @return string HTTP protocol. HTTP/2, HTTP/1.1 or HTTP/1.0.
  160. * @since 8.2.0
  161. */
  162. public function getHttpProtocol();
  163. /**
  164. * Returns the request uri, even if the website uses one or more
  165. * reverse proxies
  166. *
  167. * @return string
  168. * @since 8.1.0
  169. */
  170. public function getRequestUri();
  171. /**
  172. * Get raw PathInfo from request (not urldecoded)
  173. *
  174. * @throws \Exception
  175. * @return string Path info
  176. * @since 8.1.0
  177. */
  178. public function getRawPathInfo();
  179. /**
  180. * Get PathInfo from request
  181. *
  182. * @throws \Exception
  183. * @return string|false Path info or false when not found
  184. * @since 8.1.0
  185. */
  186. public function getPathInfo();
  187. /**
  188. * Returns the script name, even if the website uses one or more
  189. * reverse proxies
  190. *
  191. * @return string the script name
  192. * @since 8.1.0
  193. */
  194. public function getScriptName();
  195. /**
  196. * Checks whether the user agent matches a given regex
  197. *
  198. * @param array $agent array of agent names
  199. * @return bool true if at least one of the given agent matches, false otherwise
  200. * @since 8.1.0
  201. */
  202. public function isUserAgent(array $agent);
  203. /**
  204. * Returns the unverified server host from the headers without checking
  205. * whether it is a trusted domain
  206. *
  207. * @return string Server host
  208. * @since 8.1.0
  209. */
  210. public function getInsecureServerHost();
  211. /**
  212. * Returns the server host from the headers, or the first configured
  213. * trusted domain if the host isn't in the trusted list
  214. *
  215. * @return string Server host
  216. * @since 8.1.0
  217. */
  218. public function getServerHost();
  219. }