irequest.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. /**
  3. * ownCloud
  4. *
  5. * @author Thomas Müller
  6. * @copyright 2013 Thomas Müller deepdiver@owncloud.com
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  10. * License as published by the Free Software Foundation; either
  11. * version 3 of the License, or any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public
  19. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. namespace OCP;
  23. /**
  24. * This interface provides an immutable object with with accessors to
  25. * request variables and headers.
  26. *
  27. * Access request variables by method and name.
  28. *
  29. * Examples:
  30. *
  31. * $request->post['myvar']; // Only look for POST variables
  32. * $request->myvar; or $request->{'myvar'}; or $request->{$myvar}
  33. * Looks in the combined GET, POST and urlParams array.
  34. *
  35. * If you access e.g. ->post but the current HTTP request method
  36. * is GET a \LogicException will be thrown.
  37. *
  38. * NOTE:
  39. * - When accessing ->put a stream resource is returned and the accessor
  40. * will return false on subsequent access to ->put or ->patch.
  41. * - When accessing ->patch and the Content-Type is either application/json
  42. * or application/x-www-form-urlencoded (most cases) it will act like ->get
  43. * and ->post and return an array. Otherwise the raw data will be returned.
  44. */
  45. interface IRequest {
  46. function getHeader($name);
  47. /**
  48. * Lets you access post and get parameters by the index
  49. * In case of json requests the encoded json body is accessed
  50. *
  51. * @param string $key the key which you want to access in the URL Parameter
  52. * placeholder, $_POST or $_GET array.
  53. * The priority how they're returned is the following:
  54. * 1. URL parameters
  55. * 2. POST parameters
  56. * 3. GET parameters
  57. * @param mixed $default If the key is not found, this value will be returned
  58. * @return mixed the content of the array
  59. */
  60. public function getParam($key, $default = null);
  61. /**
  62. * Returns all params that were received, be it from the request
  63. *
  64. * (as GET or POST) or through the URL by the route
  65. * @return array the array with all parameters
  66. */
  67. public function getParams();
  68. /**
  69. * Returns the method of the request
  70. *
  71. * @return string the method of the request (POST, GET, etc)
  72. */
  73. public function getMethod();
  74. /**
  75. * Shortcut for accessing an uploaded file through the $_FILES array
  76. *
  77. * @param string $key the key that will be taken from the $_FILES array
  78. * @return array the file in the $_FILES element
  79. */
  80. public function getUploadedFile($key);
  81. /**
  82. * Shortcut for getting env variables
  83. *
  84. * @param string $key the key that will be taken from the $_ENV array
  85. * @return array the value in the $_ENV element
  86. */
  87. public function getEnv($key);
  88. /**
  89. * Shortcut for getting cookie variables
  90. *
  91. * @param string $key the key that will be taken from the $_COOKIE array
  92. * @return array the value in the $_COOKIE element
  93. */
  94. function getCookie($key);
  95. /**
  96. * Checks if the CSRF check was correct
  97. * @return bool true if CSRF check passed
  98. */
  99. public function passesCSRFCheck();
  100. }