RequestInterface.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * This file is part of Hyperf.
  5. *
  6. * @link https://www.hyperf.io
  7. * @document https://hyperf.wiki
  8. * @contact group@hyperf.io
  9. * @license https://github.com/hyperf/hyperf/blob/master/LICENSE
  10. */
  11. namespace Hyperf\HttpServer\Contract;
  12. use Hyperf\HttpMessage\Upload\UploadedFile;
  13. use Psr\Http\Message\ServerRequestInterface;
  14. interface RequestInterface extends ServerRequestInterface
  15. {
  16. /**
  17. * Retrieve all input data from request, include query parameters, parsed body and json body.
  18. */
  19. public function all(): array;
  20. /**
  21. * Retrieve the data from query parameters, if $key is null, will return all query parameters.
  22. */
  23. public function query(?string $key = null, mixed $default = null): mixed;
  24. /**
  25. * Retrieve the data from parsed body, if $key is null, will return all parsed body.
  26. */
  27. public function post(?string $key = null, mixed $default = null): mixed;
  28. /**
  29. * Retrieve the input data from request, include query parameters, parsed body and json body.
  30. */
  31. public function input(string $key, mixed $default = null): mixed;
  32. /**
  33. * Retrieve the input data from request via multi keys, include query parameters, parsed body and json body.
  34. */
  35. public function inputs(array $keys, ?array $default = null): array;
  36. /**
  37. * Determine if the $keys is existed in parameters.
  38. * @return array [found, not-found]
  39. */
  40. public function hasInput(array $keys): array;
  41. /**
  42. * Determine if the $keys is existed in parameters.
  43. */
  44. public function has(array|string $keys): bool;
  45. /**
  46. * Retrieve the data from request headers.
  47. */
  48. public function header(string $key, ?string $default = null): ?string;
  49. /**
  50. * Retrieve the data from route parameters.
  51. */
  52. public function route(string $key, mixed $default = null): mixed;
  53. /**
  54. * Returns the path being requested relative to the executed script.
  55. * The path info always starts with a /.
  56. * Suppose this request is instantiated from /mysite on localhost:
  57. * * http://localhost/mysite returns an empty string
  58. * * http://localhost/mysite/about returns '/about'
  59. * * http://localhost/mysite/enco%20ded returns '/enco%20ded'
  60. * * http://localhost/mysite/about?var=1 returns '/about'.
  61. *
  62. * @return string The raw path (i.e. not urldecoded)
  63. */
  64. public function getPathInfo(): string;
  65. /**
  66. * Determine if the current request URI matches a pattern.
  67. *
  68. * @param mixed ...$patterns
  69. */
  70. public function is(...$patterns): bool;
  71. /**
  72. * Get the current decoded path info for the request.
  73. */
  74. public function decodedPath(): string;
  75. /**
  76. * Returns the requested URI (path and query string).
  77. *
  78. * @return string The raw URI (i.e. not URI decoded)
  79. */
  80. public function getRequestUri(): string;
  81. /**
  82. * Get the URL (no query string) for the request.
  83. */
  84. public function url(): string;
  85. /**
  86. * Get the full URL for the request.
  87. */
  88. public function fullUrl(): string;
  89. /**
  90. * Generates the normalized query string for the Request.
  91. *
  92. * It builds a normalized query string, where keys/value pairs are alphabetized
  93. * and have consistent escaping.
  94. *
  95. * @return null|string A normalized query string for the Request
  96. */
  97. public function getQueryString(): ?string;
  98. /**
  99. * Normalizes a query string.
  100. *
  101. * It builds a normalized query string, where keys/value pairs are alphabetized,
  102. * have consistent escaping and unneeded delimiters are removed.
  103. *
  104. * @param string $qs Query string
  105. * @return string A normalized query string for the Request
  106. */
  107. public function normalizeQueryString(string $qs): string;
  108. /**
  109. * Retrieve a cookie from the request.
  110. */
  111. public function cookie(string $key, mixed $default = null);
  112. /**
  113. * Determine if a cookie is set on the request.
  114. */
  115. public function hasCookie(string $key): bool;
  116. /**
  117. * Retrieve a server variable from the request.
  118. *
  119. * @return null|array|string
  120. */
  121. public function server(string $key, mixed $default = null): mixed;
  122. /**
  123. * Checks if the request method is of specified type.
  124. *
  125. * @param string $method Uppercase request method (GET, POST etc)
  126. */
  127. public function isMethod(string $method): bool;
  128. /**
  129. * Retrieve a file from the request.
  130. *
  131. * @return null|UploadedFile|UploadedFile[]
  132. */
  133. public function file(string $key, mixed $default = null);
  134. /**
  135. * Determine if the uploaded data contains a file.
  136. */
  137. public function hasFile(string $key): bool;
  138. }