annotate vendor/psr/http-message/src/UriInterface.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 4c8ae668cc8c
children
rev   line source
Chris@0 1 <?php
Chris@0 2 namespace Psr\Http\Message;
Chris@0 3
Chris@0 4 /**
Chris@0 5 * Value object representing a URI.
Chris@0 6 *
Chris@0 7 * This interface is meant to represent URIs according to RFC 3986 and to
Chris@0 8 * provide methods for most common operations. Additional functionality for
Chris@0 9 * working with URIs can be provided on top of the interface or externally.
Chris@0 10 * Its primary use is for HTTP requests, but may also be used in other
Chris@0 11 * contexts.
Chris@0 12 *
Chris@0 13 * Instances of this interface are considered immutable; all methods that
Chris@0 14 * might change state MUST be implemented such that they retain the internal
Chris@0 15 * state of the current instance and return an instance that contains the
Chris@0 16 * changed state.
Chris@0 17 *
Chris@0 18 * Typically the Host header will be also be present in the request message.
Chris@0 19 * For server-side requests, the scheme will typically be discoverable in the
Chris@0 20 * server parameters.
Chris@0 21 *
Chris@0 22 * @link http://tools.ietf.org/html/rfc3986 (the URI specification)
Chris@0 23 */
Chris@0 24 interface UriInterface
Chris@0 25 {
Chris@0 26 /**
Chris@0 27 * Retrieve the scheme component of the URI.
Chris@0 28 *
Chris@0 29 * If no scheme is present, this method MUST return an empty string.
Chris@0 30 *
Chris@0 31 * The value returned MUST be normalized to lowercase, per RFC 3986
Chris@0 32 * Section 3.1.
Chris@0 33 *
Chris@0 34 * The trailing ":" character is not part of the scheme and MUST NOT be
Chris@0 35 * added.
Chris@0 36 *
Chris@0 37 * @see https://tools.ietf.org/html/rfc3986#section-3.1
Chris@0 38 * @return string The URI scheme.
Chris@0 39 */
Chris@0 40 public function getScheme();
Chris@0 41
Chris@0 42 /**
Chris@0 43 * Retrieve the authority component of the URI.
Chris@0 44 *
Chris@0 45 * If no authority information is present, this method MUST return an empty
Chris@0 46 * string.
Chris@0 47 *
Chris@0 48 * The authority syntax of the URI is:
Chris@0 49 *
Chris@0 50 * <pre>
Chris@0 51 * [user-info@]host[:port]
Chris@0 52 * </pre>
Chris@0 53 *
Chris@0 54 * If the port component is not set or is the standard port for the current
Chris@0 55 * scheme, it SHOULD NOT be included.
Chris@0 56 *
Chris@0 57 * @see https://tools.ietf.org/html/rfc3986#section-3.2
Chris@0 58 * @return string The URI authority, in "[user-info@]host[:port]" format.
Chris@0 59 */
Chris@0 60 public function getAuthority();
Chris@0 61
Chris@0 62 /**
Chris@0 63 * Retrieve the user information component of the URI.
Chris@0 64 *
Chris@0 65 * If no user information is present, this method MUST return an empty
Chris@0 66 * string.
Chris@0 67 *
Chris@0 68 * If a user is present in the URI, this will return that value;
Chris@0 69 * additionally, if the password is also present, it will be appended to the
Chris@0 70 * user value, with a colon (":") separating the values.
Chris@0 71 *
Chris@0 72 * The trailing "@" character is not part of the user information and MUST
Chris@0 73 * NOT be added.
Chris@0 74 *
Chris@0 75 * @return string The URI user information, in "username[:password]" format.
Chris@0 76 */
Chris@0 77 public function getUserInfo();
Chris@0 78
Chris@0 79 /**
Chris@0 80 * Retrieve the host component of the URI.
Chris@0 81 *
Chris@0 82 * If no host is present, this method MUST return an empty string.
Chris@0 83 *
Chris@0 84 * The value returned MUST be normalized to lowercase, per RFC 3986
Chris@0 85 * Section 3.2.2.
Chris@0 86 *
Chris@0 87 * @see http://tools.ietf.org/html/rfc3986#section-3.2.2
Chris@0 88 * @return string The URI host.
Chris@0 89 */
Chris@0 90 public function getHost();
Chris@0 91
Chris@0 92 /**
Chris@0 93 * Retrieve the port component of the URI.
Chris@0 94 *
Chris@0 95 * If a port is present, and it is non-standard for the current scheme,
Chris@0 96 * this method MUST return it as an integer. If the port is the standard port
Chris@0 97 * used with the current scheme, this method SHOULD return null.
Chris@0 98 *
Chris@0 99 * If no port is present, and no scheme is present, this method MUST return
Chris@0 100 * a null value.
Chris@0 101 *
Chris@0 102 * If no port is present, but a scheme is present, this method MAY return
Chris@0 103 * the standard port for that scheme, but SHOULD return null.
Chris@0 104 *
Chris@0 105 * @return null|int The URI port.
Chris@0 106 */
Chris@0 107 public function getPort();
Chris@0 108
Chris@0 109 /**
Chris@0 110 * Retrieve the path component of the URI.
Chris@0 111 *
Chris@0 112 * The path can either be empty or absolute (starting with a slash) or
Chris@0 113 * rootless (not starting with a slash). Implementations MUST support all
Chris@0 114 * three syntaxes.
Chris@0 115 *
Chris@0 116 * Normally, the empty path "" and absolute path "/" are considered equal as
Chris@0 117 * defined in RFC 7230 Section 2.7.3. But this method MUST NOT automatically
Chris@0 118 * do this normalization because in contexts with a trimmed base path, e.g.
Chris@0 119 * the front controller, this difference becomes significant. It's the task
Chris@0 120 * of the user to handle both "" and "/".
Chris@0 121 *
Chris@0 122 * The value returned MUST be percent-encoded, but MUST NOT double-encode
Chris@0 123 * any characters. To determine what characters to encode, please refer to
Chris@0 124 * RFC 3986, Sections 2 and 3.3.
Chris@0 125 *
Chris@0 126 * As an example, if the value should include a slash ("/") not intended as
Chris@0 127 * delimiter between path segments, that value MUST be passed in encoded
Chris@0 128 * form (e.g., "%2F") to the instance.
Chris@0 129 *
Chris@0 130 * @see https://tools.ietf.org/html/rfc3986#section-2
Chris@0 131 * @see https://tools.ietf.org/html/rfc3986#section-3.3
Chris@0 132 * @return string The URI path.
Chris@0 133 */
Chris@0 134 public function getPath();
Chris@0 135
Chris@0 136 /**
Chris@0 137 * Retrieve the query string of the URI.
Chris@0 138 *
Chris@0 139 * If no query string is present, this method MUST return an empty string.
Chris@0 140 *
Chris@0 141 * The leading "?" character is not part of the query and MUST NOT be
Chris@0 142 * added.
Chris@0 143 *
Chris@0 144 * The value returned MUST be percent-encoded, but MUST NOT double-encode
Chris@0 145 * any characters. To determine what characters to encode, please refer to
Chris@0 146 * RFC 3986, Sections 2 and 3.4.
Chris@0 147 *
Chris@0 148 * As an example, if a value in a key/value pair of the query string should
Chris@0 149 * include an ampersand ("&") not intended as a delimiter between values,
Chris@0 150 * that value MUST be passed in encoded form (e.g., "%26") to the instance.
Chris@0 151 *
Chris@0 152 * @see https://tools.ietf.org/html/rfc3986#section-2
Chris@0 153 * @see https://tools.ietf.org/html/rfc3986#section-3.4
Chris@0 154 * @return string The URI query string.
Chris@0 155 */
Chris@0 156 public function getQuery();
Chris@0 157
Chris@0 158 /**
Chris@0 159 * Retrieve the fragment component of the URI.
Chris@0 160 *
Chris@0 161 * If no fragment is present, this method MUST return an empty string.
Chris@0 162 *
Chris@0 163 * The leading "#" character is not part of the fragment and MUST NOT be
Chris@0 164 * added.
Chris@0 165 *
Chris@0 166 * The value returned MUST be percent-encoded, but MUST NOT double-encode
Chris@0 167 * any characters. To determine what characters to encode, please refer to
Chris@0 168 * RFC 3986, Sections 2 and 3.5.
Chris@0 169 *
Chris@0 170 * @see https://tools.ietf.org/html/rfc3986#section-2
Chris@0 171 * @see https://tools.ietf.org/html/rfc3986#section-3.5
Chris@0 172 * @return string The URI fragment.
Chris@0 173 */
Chris@0 174 public function getFragment();
Chris@0 175
Chris@0 176 /**
Chris@0 177 * Return an instance with the specified scheme.
Chris@0 178 *
Chris@0 179 * This method MUST retain the state of the current instance, and return
Chris@0 180 * an instance that contains the specified scheme.
Chris@0 181 *
Chris@0 182 * Implementations MUST support the schemes "http" and "https" case
Chris@0 183 * insensitively, and MAY accommodate other schemes if required.
Chris@0 184 *
Chris@0 185 * An empty scheme is equivalent to removing the scheme.
Chris@0 186 *
Chris@0 187 * @param string $scheme The scheme to use with the new instance.
Chris@0 188 * @return static A new instance with the specified scheme.
Chris@0 189 * @throws \InvalidArgumentException for invalid or unsupported schemes.
Chris@0 190 */
Chris@0 191 public function withScheme($scheme);
Chris@0 192
Chris@0 193 /**
Chris@0 194 * Return an instance with the specified user information.
Chris@0 195 *
Chris@0 196 * This method MUST retain the state of the current instance, and return
Chris@0 197 * an instance that contains the specified user information.
Chris@0 198 *
Chris@0 199 * Password is optional, but the user information MUST include the
Chris@0 200 * user; an empty string for the user is equivalent to removing user
Chris@0 201 * information.
Chris@0 202 *
Chris@0 203 * @param string $user The user name to use for authority.
Chris@0 204 * @param null|string $password The password associated with $user.
Chris@0 205 * @return static A new instance with the specified user information.
Chris@0 206 */
Chris@0 207 public function withUserInfo($user, $password = null);
Chris@0 208
Chris@0 209 /**
Chris@0 210 * Return an instance with the specified host.
Chris@0 211 *
Chris@0 212 * This method MUST retain the state of the current instance, and return
Chris@0 213 * an instance that contains the specified host.
Chris@0 214 *
Chris@0 215 * An empty host value is equivalent to removing the host.
Chris@0 216 *
Chris@0 217 * @param string $host The hostname to use with the new instance.
Chris@0 218 * @return static A new instance with the specified host.
Chris@0 219 * @throws \InvalidArgumentException for invalid hostnames.
Chris@0 220 */
Chris@0 221 public function withHost($host);
Chris@0 222
Chris@0 223 /**
Chris@0 224 * Return an instance with the specified port.
Chris@0 225 *
Chris@0 226 * This method MUST retain the state of the current instance, and return
Chris@0 227 * an instance that contains the specified port.
Chris@0 228 *
Chris@0 229 * Implementations MUST raise an exception for ports outside the
Chris@0 230 * established TCP and UDP port ranges.
Chris@0 231 *
Chris@0 232 * A null value provided for the port is equivalent to removing the port
Chris@0 233 * information.
Chris@0 234 *
Chris@0 235 * @param null|int $port The port to use with the new instance; a null value
Chris@0 236 * removes the port information.
Chris@0 237 * @return static A new instance with the specified port.
Chris@0 238 * @throws \InvalidArgumentException for invalid ports.
Chris@0 239 */
Chris@0 240 public function withPort($port);
Chris@0 241
Chris@0 242 /**
Chris@0 243 * Return an instance with the specified path.
Chris@0 244 *
Chris@0 245 * This method MUST retain the state of the current instance, and return
Chris@0 246 * an instance that contains the specified path.
Chris@0 247 *
Chris@0 248 * The path can either be empty or absolute (starting with a slash) or
Chris@0 249 * rootless (not starting with a slash). Implementations MUST support all
Chris@0 250 * three syntaxes.
Chris@0 251 *
Chris@0 252 * If the path is intended to be domain-relative rather than path relative then
Chris@0 253 * it must begin with a slash ("/"). Paths not starting with a slash ("/")
Chris@0 254 * are assumed to be relative to some base path known to the application or
Chris@0 255 * consumer.
Chris@0 256 *
Chris@0 257 * Users can provide both encoded and decoded path characters.
Chris@0 258 * Implementations ensure the correct encoding as outlined in getPath().
Chris@0 259 *
Chris@0 260 * @param string $path The path to use with the new instance.
Chris@0 261 * @return static A new instance with the specified path.
Chris@0 262 * @throws \InvalidArgumentException for invalid paths.
Chris@0 263 */
Chris@0 264 public function withPath($path);
Chris@0 265
Chris@0 266 /**
Chris@0 267 * Return an instance with the specified query string.
Chris@0 268 *
Chris@0 269 * This method MUST retain the state of the current instance, and return
Chris@0 270 * an instance that contains the specified query string.
Chris@0 271 *
Chris@0 272 * Users can provide both encoded and decoded query characters.
Chris@0 273 * Implementations ensure the correct encoding as outlined in getQuery().
Chris@0 274 *
Chris@0 275 * An empty query string value is equivalent to removing the query string.
Chris@0 276 *
Chris@0 277 * @param string $query The query string to use with the new instance.
Chris@0 278 * @return static A new instance with the specified query string.
Chris@0 279 * @throws \InvalidArgumentException for invalid query strings.
Chris@0 280 */
Chris@0 281 public function withQuery($query);
Chris@0 282
Chris@0 283 /**
Chris@0 284 * Return an instance with the specified URI fragment.
Chris@0 285 *
Chris@0 286 * This method MUST retain the state of the current instance, and return
Chris@0 287 * an instance that contains the specified URI fragment.
Chris@0 288 *
Chris@0 289 * Users can provide both encoded and decoded fragment characters.
Chris@0 290 * Implementations ensure the correct encoding as outlined in getFragment().
Chris@0 291 *
Chris@0 292 * An empty fragment value is equivalent to removing the fragment.
Chris@0 293 *
Chris@0 294 * @param string $fragment The fragment to use with the new instance.
Chris@0 295 * @return static A new instance with the specified fragment.
Chris@0 296 */
Chris@0 297 public function withFragment($fragment);
Chris@0 298
Chris@0 299 /**
Chris@0 300 * Return the string representation as a URI reference.
Chris@0 301 *
Chris@0 302 * Depending on which components of the URI are present, the resulting
Chris@0 303 * string is either a full URI or relative reference according to RFC 3986,
Chris@0 304 * Section 4.1. The method concatenates the various components of the URI,
Chris@0 305 * using the appropriate delimiters:
Chris@0 306 *
Chris@0 307 * - If a scheme is present, it MUST be suffixed by ":".
Chris@0 308 * - If an authority is present, it MUST be prefixed by "//".
Chris@0 309 * - The path can be concatenated without delimiters. But there are two
Chris@0 310 * cases where the path has to be adjusted to make the URI reference
Chris@0 311 * valid as PHP does not allow to throw an exception in __toString():
Chris@0 312 * - If the path is rootless and an authority is present, the path MUST
Chris@0 313 * be prefixed by "/".
Chris@0 314 * - If the path is starting with more than one "/" and no authority is
Chris@0 315 * present, the starting slashes MUST be reduced to one.
Chris@0 316 * - If a query is present, it MUST be prefixed by "?".
Chris@0 317 * - If a fragment is present, it MUST be prefixed by "#".
Chris@0 318 *
Chris@0 319 * @see http://tools.ietf.org/html/rfc3986#section-4.1
Chris@0 320 * @return string
Chris@0 321 */
Chris@0 322 public function __toString();
Chris@0 323 }