[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/php-ai-client/third-party/Psr/Http/Message/ -> ServerRequestInterface.php (source)

   1  <?php
   2  
   3  namespace WordPress\AiClientDependencies\Psr\Http\Message;
   4  
   5  /**
   6   * Representation of an incoming, server-side HTTP request.
   7   *
   8   * Per the HTTP specification, this interface includes properties for
   9   * each of the following:
  10   *
  11   * - Protocol version
  12   * - HTTP method
  13   * - URI
  14   * - Headers
  15   * - Message body
  16   *
  17   * Additionally, it encapsulates all data as it has arrived to the
  18   * application from the CGI and/or PHP environment, including:
  19   *
  20   * - The values represented in $_SERVER.
  21   * - Any cookies provided (generally via $_COOKIE)
  22   * - Query string arguments (generally via $_GET, or as parsed via parse_str())
  23   * - Upload files, if any (as represented by $_FILES)
  24   * - Deserialized body parameters (generally from $_POST)
  25   *
  26   * $_SERVER values MUST be treated as immutable, as they represent application
  27   * state at the time of request; as such, no methods are provided to allow
  28   * modification of those values. The other values provide such methods, as they
  29   * can be restored from $_SERVER or the request body, and may need treatment
  30   * during the application (e.g., body parameters may be deserialized based on
  31   * content type).
  32   *
  33   * Additionally, this interface recognizes the utility of introspecting a
  34   * request to derive and match additional parameters (e.g., via URI path
  35   * matching, decrypting cookie values, deserializing non-form-encoded body
  36   * content, matching authorization headers to users, etc). These parameters
  37   * are stored in an "attributes" property.
  38   *
  39   * Requests are considered immutable; all methods that might change state MUST
  40   * be implemented such that they retain the internal state of the current
  41   * message and return an instance that contains the changed state.
  42   */
  43  interface ServerRequestInterface extends RequestInterface
  44  {
  45      /**
  46       * Retrieve server parameters.
  47       *
  48       * Retrieves data related to the incoming request environment,
  49       * typically derived from PHP's $_SERVER superglobal. The data IS NOT
  50       * REQUIRED to originate from $_SERVER.
  51       *
  52       * @return array
  53       */
  54      public function getServerParams(): array;
  55      /**
  56       * Retrieve cookies.
  57       *
  58       * Retrieves cookies sent by the client to the server.
  59       *
  60       * The data MUST be compatible with the structure of the $_COOKIE
  61       * superglobal.
  62       *
  63       * @return array
  64       */
  65      public function getCookieParams(): array;
  66      /**
  67       * Return an instance with the specified cookies.
  68       *
  69       * The data IS NOT REQUIRED to come from the $_COOKIE superglobal, but MUST
  70       * be compatible with the structure of $_COOKIE. Typically, this data will
  71       * be injected at instantiation.
  72       *
  73       * This method MUST NOT update the related Cookie header of the request
  74       * instance, nor related values in the server params.
  75       *
  76       * This method MUST be implemented in such a way as to retain the
  77       * immutability of the message, and MUST return an instance that has the
  78       * updated cookie values.
  79       *
  80       * @param array $cookies Array of key/value pairs representing cookies.
  81       * @return static
  82       */
  83      public function withCookieParams(array $cookies): ServerRequestInterface;
  84      /**
  85       * Retrieve query string arguments.
  86       *
  87       * Retrieves the deserialized query string arguments, if any.
  88       *
  89       * Note: the query params might not be in sync with the URI or server
  90       * params. If you need to ensure you are only getting the original
  91       * values, you may need to parse the query string from `getUri()->getQuery()`
  92       * or from the `QUERY_STRING` server param.
  93       *
  94       * @return array
  95       */
  96      public function getQueryParams(): array;
  97      /**
  98       * Return an instance with the specified query string arguments.
  99       *
 100       * These values SHOULD remain immutable over the course of the incoming
 101       * request. They MAY be injected during instantiation, such as from PHP's
 102       * $_GET superglobal, or MAY be derived from some other value such as the
 103       * URI. In cases where the arguments are parsed from the URI, the data
 104       * MUST be compatible with what PHP's parse_str() would return for
 105       * purposes of how duplicate query parameters are handled, and how nested
 106       * sets are handled.
 107       *
 108       * Setting query string arguments MUST NOT change the URI stored by the
 109       * request, nor the values in the server params.
 110       *
 111       * This method MUST be implemented in such a way as to retain the
 112       * immutability of the message, and MUST return an instance that has the
 113       * updated query string arguments.
 114       *
 115       * @param array $query Array of query string arguments, typically from
 116       *     $_GET.
 117       * @return static
 118       */
 119      public function withQueryParams(array $query): ServerRequestInterface;
 120      /**
 121       * Retrieve normalized file upload data.
 122       *
 123       * This method returns upload metadata in a normalized tree, with each leaf
 124       * an instance of Psr\Http\Message\UploadedFileInterface.
 125       *
 126       * These values MAY be prepared from $_FILES or the message body during
 127       * instantiation, or MAY be injected via withUploadedFiles().
 128       *
 129       * @return array An array tree of UploadedFileInterface instances; an empty
 130       *     array MUST be returned if no data is present.
 131       */
 132      public function getUploadedFiles(): array;
 133      /**
 134       * Create a new instance with the specified uploaded files.
 135       *
 136       * This method MUST be implemented in such a way as to retain the
 137       * immutability of the message, and MUST return an instance that has the
 138       * updated body parameters.
 139       *
 140       * @param array $uploadedFiles An array tree of UploadedFileInterface instances.
 141       * @return static
 142       * @throws \InvalidArgumentException if an invalid structure is provided.
 143       */
 144      public function withUploadedFiles(array $uploadedFiles): ServerRequestInterface;
 145      /**
 146       * Retrieve any parameters provided in the request body.
 147       *
 148       * If the request Content-Type is either application/x-www-form-urlencoded
 149       * or multipart/form-data, and the request method is POST, this method MUST
 150       * return the contents of $_POST.
 151       *
 152       * Otherwise, this method may return any results of deserializing
 153       * the request body content; as parsing returns structured content, the
 154       * potential types MUST be arrays or objects only. A null value indicates
 155       * the absence of body content.
 156       *
 157       * @return null|array|object The deserialized body parameters, if any.
 158       *     These will typically be an array or object.
 159       */
 160      public function getParsedBody();
 161      /**
 162       * Return an instance with the specified body parameters.
 163       *
 164       * These MAY be injected during instantiation.
 165       *
 166       * If the request Content-Type is either application/x-www-form-urlencoded
 167       * or multipart/form-data, and the request method is POST, use this method
 168       * ONLY to inject the contents of $_POST.
 169       *
 170       * The data IS NOT REQUIRED to come from $_POST, but MUST be the results of
 171       * deserializing the request body content. Deserialization/parsing returns
 172       * structured data, and, as such, this method ONLY accepts arrays or objects,
 173       * or a null value if nothing was available to parse.
 174       *
 175       * As an example, if content negotiation determines that the request data
 176       * is a JSON payload, this method could be used to create a request
 177       * instance with the deserialized parameters.
 178       *
 179       * This method MUST be implemented in such a way as to retain the
 180       * immutability of the message, and MUST return an instance that has the
 181       * updated body parameters.
 182       *
 183       * @param null|array|object $data The deserialized body data. This will
 184       *     typically be in an array or object.
 185       * @return static
 186       * @throws \InvalidArgumentException if an unsupported argument type is
 187       *     provided.
 188       */
 189      public function withParsedBody($data): ServerRequestInterface;
 190      /**
 191       * Retrieve attributes derived from the request.
 192       *
 193       * The request "attributes" may be used to allow injection of any
 194       * parameters derived from the request: e.g., the results of path
 195       * match operations; the results of decrypting cookies; the results of
 196       * deserializing non-form-encoded message bodies; etc. Attributes
 197       * will be application and request specific, and CAN be mutable.
 198       *
 199       * @return array Attributes derived from the request.
 200       */
 201      public function getAttributes(): array;
 202      /**
 203       * Retrieve a single derived request attribute.
 204       *
 205       * Retrieves a single derived request attribute as described in
 206       * getAttributes(). If the attribute has not been previously set, returns
 207       * the default value as provided.
 208       *
 209       * This method obviates the need for a hasAttribute() method, as it allows
 210       * specifying a default value to return if the attribute is not found.
 211       *
 212       * @see getAttributes()
 213       * @param string $name The attribute name.
 214       * @param mixed $default Default value to return if the attribute does not exist.
 215       * @return mixed
 216       */
 217      public function getAttribute(string $name, $default = null);
 218      /**
 219       * Return an instance with the specified derived request attribute.
 220       *
 221       * This method allows setting a single derived request attribute as
 222       * described in getAttributes().
 223       *
 224       * This method MUST be implemented in such a way as to retain the
 225       * immutability of the message, and MUST return an instance that has the
 226       * updated attribute.
 227       *
 228       * @see getAttributes()
 229       * @param string $name The attribute name.
 230       * @param mixed $value The value of the attribute.
 231       * @return static
 232       */
 233      public function withAttribute(string $name, $value): ServerRequestInterface;
 234      /**
 235       * Return an instance that removes the specified derived request attribute.
 236       *
 237       * This method allows removing a single derived request attribute as
 238       * described in getAttributes().
 239       *
 240       * This method MUST be implemented in such a way as to retain the
 241       * immutability of the message, and MUST return an instance that removes
 242       * the attribute.
 243       *
 244       * @see getAttributes()
 245       * @param string $name The attribute name.
 246       * @return static
 247       */
 248      public function withoutAttribute(string $name): ServerRequestInterface;
 249  }


Generated : Sat Jun 13 09:38:55 2026 Cross-referenced by PHPXref