irequest.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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. * @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. * @return array the array with all parameters
  88. * @since 6.0.0
  89. */
  90. public function getParams();
  91. /**
  92. * Returns the method of the request
  93. *
  94. * @return string the method of the request (POST, GET, etc)
  95. * @since 6.0.0
  96. */
  97. public function getMethod();
  98. /**
  99. * Shortcut for accessing an uploaded file through the $_FILES array
  100. *
  101. * @param string $key the key that will be taken from the $_FILES array
  102. * @return array the file in the $_FILES element
  103. * @since 6.0.0
  104. */
  105. public function getUploadedFile($key);
  106. /**
  107. * Shortcut for getting env variables
  108. *
  109. * @param string $key the key that will be taken from the $_ENV array
  110. * @return array the value in the $_ENV element
  111. * @since 6.0.0
  112. */
  113. public function getEnv($key);
  114. /**
  115. * Shortcut for getting cookie variables
  116. *
  117. * @param string $key the key that will be taken from the $_COOKIE array
  118. * @return array the value in the $_COOKIE element
  119. * @since 6.0.0
  120. */
  121. public function getCookie($key);
  122. /**
  123. * Checks if the CSRF check was correct
  124. * @return bool true if CSRF check passed
  125. * @since 6.0.0
  126. */
  127. public function passesCSRFCheck();
  128. /**
  129. * Returns an ID for the request, value is not guaranteed to be unique and is mostly meant for logging
  130. * If `mod_unique_id` is installed this value will be taken.
  131. * @return string
  132. * @since 8.1.0
  133. */
  134. public function getId();
  135. /**
  136. * Returns the remote address, if the connection came from a trusted proxy
  137. * and `forwarded_for_headers` has been configured then the IP address
  138. * specified in this header will be returned instead.
  139. * Do always use this instead of $_SERVER['REMOTE_ADDR']
  140. * @return string IP address
  141. * @since 8.1.0
  142. */
  143. public function getRemoteAddress();
  144. /**
  145. * Returns the server protocol. It respects reverse proxy servers and load
  146. * balancers.
  147. * @return string Server protocol (http or https)
  148. * @since 8.1.0
  149. */
  150. public function getServerProtocol();
  151. /**
  152. * Returns the request uri, even if the website uses one or more
  153. * reverse proxies
  154. * @return string
  155. * @since 8.1.0
  156. */
  157. public function getRequestUri();
  158. /**
  159. * Get raw PathInfo from request (not urldecoded)
  160. * @throws \Exception
  161. * @return string Path info
  162. * @since 8.1.0
  163. */
  164. public function getRawPathInfo();
  165. /**
  166. * Get PathInfo from request
  167. * @throws \Exception
  168. * @return string|false Path info or false when not found
  169. * @since 8.1.0
  170. */
  171. public function getPathInfo();
  172. /**
  173. * Returns the script name, even if the website uses one or more
  174. * reverse proxies
  175. * @return string the script name
  176. * @since 8.1.0
  177. */
  178. public function getScriptName();
  179. /**
  180. * Checks whether the user agent matches a given regex
  181. * @param array $agent array of agent names
  182. * @return bool true if at least one of the given agent matches, false otherwise
  183. * @since 8.1.0
  184. */
  185. public function isUserAgent(array $agent);
  186. /**
  187. * Returns the unverified server host from the headers without checking
  188. * whether it is a trusted domain
  189. * @return string Server host
  190. * @since 8.1.0
  191. */
  192. public function getInsecureServerHost();
  193. /**
  194. * Returns the server host from the headers, or the first configured
  195. * trusted domain if the host isn't in the trusted list
  196. * @return string Server host
  197. * @since 8.1.0
  198. */
  199. public function getServerHost();
  200. }