irequest.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. /**
  23. * Public interface of ownCloud for apps to use.
  24. * Request interface
  25. *
  26. */
  27. // use OCP namespace for all classes that are considered public.
  28. // This means that they should be used by apps instead of the internal ownCloud classes
  29. namespace OCP;
  30. /**
  31. * This interface provides an immutable object with with accessors to
  32. * request variables and headers.
  33. *
  34. * Access request variables by method and name.
  35. *
  36. * Examples:
  37. *
  38. * $request->post['myvar']; // Only look for POST variables
  39. * $request->myvar; or $request->{'myvar'}; or $request->{$myvar}
  40. * Looks in the combined GET, POST and urlParams array.
  41. *
  42. * If you access e.g. ->post but the current HTTP request method
  43. * is GET a \LogicException will be thrown.
  44. *
  45. * NOTE:
  46. * - When accessing ->put a stream resource is returned and the accessor
  47. * will return false on subsequent access to ->put or ->patch.
  48. * - When accessing ->patch and the Content-Type is either application/json
  49. * or application/x-www-form-urlencoded (most cases) it will act like ->get
  50. * and ->post and return an array. Otherwise the raw data will be returned.
  51. */
  52. interface IRequest {
  53. function getHeader($name);
  54. /**
  55. * Lets you access post and get parameters by the index
  56. * In case of json requests the encoded json body is accessed
  57. *
  58. * @param string $key the key which you want to access in the URL Parameter
  59. * placeholder, $_POST or $_GET array.
  60. * The priority how they're returned is the following:
  61. * 1. URL parameters
  62. * 2. POST parameters
  63. * 3. GET parameters
  64. * @param mixed $default If the key is not found, this value will be returned
  65. * @return mixed the content of the array
  66. */
  67. public function getParam($key, $default = null);
  68. /**
  69. * Returns all params that were received, be it from the request
  70. *
  71. * (as GET or POST) or through the URL by the route
  72. * @return array the array with all parameters
  73. */
  74. public function getParams();
  75. /**
  76. * Returns the method of the request
  77. *
  78. * @return string the method of the request (POST, GET, etc)
  79. */
  80. public function getMethod();
  81. /**
  82. * Shortcut for accessing an uploaded file through the $_FILES array
  83. *
  84. * @param string $key the key that will be taken from the $_FILES array
  85. * @return array the file in the $_FILES element
  86. */
  87. public function getUploadedFile($key);
  88. /**
  89. * Shortcut for getting env variables
  90. *
  91. * @param string $key the key that will be taken from the $_ENV array
  92. * @return array the value in the $_ENV element
  93. */
  94. public function getEnv($key);
  95. /**
  96. * Shortcut for getting cookie variables
  97. *
  98. * @param string $key the key that will be taken from the $_COOKIE array
  99. * @return array the value in the $_COOKIE element
  100. */
  101. function getCookie($key);
  102. /**
  103. * Checks if the CSRF check was correct
  104. * @return bool true if CSRF check passed
  105. */
  106. public function passesCSRFCheck();
  107. }