irequest.php 6.9 KB

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