File indexing completed on 2025-01-26 05:29:15

0001 <?php
0002 namespace Psr\Http\Message;
0003 
0004 /**
0005  * Value object representing a URI.
0006  *
0007  * This interface is meant to represent URIs according to RFC 3986 and to
0008  * provide methods for most common operations. Additional functionality for
0009  * working with URIs can be provided on top of the interface or externally.
0010  * Its primary use is for HTTP requests, but may also be used in other
0011  * contexts.
0012  *
0013  * Instances of this interface are considered immutable; all methods that
0014  * might change state MUST be implemented such that they retain the internal
0015  * state of the current instance and return an instance that contains the
0016  * changed state.
0017  *
0018  * Typically the Host header will be also be present in the request message.
0019  * For server-side requests, the scheme will typically be discoverable in the
0020  * server parameters.
0021  *
0022  * @link http://tools.ietf.org/html/rfc3986 (the URI specification)
0023  */
0024 interface UriInterface
0025 {
0026     /**
0027      * Retrieve the scheme component of the URI.
0028      *
0029      * If no scheme is present, this method MUST return an empty string.
0030      *
0031      * The value returned MUST be normalized to lowercase, per RFC 3986
0032      * Section 3.1.
0033      *
0034      * The trailing ":" character is not part of the scheme and MUST NOT be
0035      * added.
0036      *
0037      * @see https://tools.ietf.org/html/rfc3986#section-3.1
0038      * @return string The URI scheme.
0039      */
0040     public function getScheme();
0041 
0042     /**
0043      * Retrieve the authority component of the URI.
0044      *
0045      * If no authority information is present, this method MUST return an empty
0046      * string.
0047      *
0048      * The authority syntax of the URI is:
0049      *
0050      * <pre>
0051      * [user-info@]host[:port]
0052      * </pre>
0053      *
0054      * If the port component is not set or is the standard port for the current
0055      * scheme, it SHOULD NOT be included.
0056      *
0057      * @see https://tools.ietf.org/html/rfc3986#section-3.2
0058      * @return string The URI authority, in "[user-info@]host[:port]" format.
0059      */
0060     public function getAuthority();
0061 
0062     /**
0063      * Retrieve the user information component of the URI.
0064      *
0065      * If no user information is present, this method MUST return an empty
0066      * string.
0067      *
0068      * If a user is present in the URI, this will return that value;
0069      * additionally, if the password is also present, it will be appended to the
0070      * user value, with a colon (":") separating the values.
0071      *
0072      * The trailing "@" character is not part of the user information and MUST
0073      * NOT be added.
0074      *
0075      * @return string The URI user information, in "username[:password]" format.
0076      */
0077     public function getUserInfo();
0078 
0079     /**
0080      * Retrieve the host component of the URI.
0081      *
0082      * If no host is present, this method MUST return an empty string.
0083      *
0084      * The value returned MUST be normalized to lowercase, per RFC 3986
0085      * Section 3.2.2.
0086      *
0087      * @see http://tools.ietf.org/html/rfc3986#section-3.2.2
0088      * @return string The URI host.
0089      */
0090     public function getHost();
0091 
0092     /**
0093      * Retrieve the port component of the URI.
0094      *
0095      * If a port is present, and it is non-standard for the current scheme,
0096      * this method MUST return it as an integer. If the port is the standard port
0097      * used with the current scheme, this method SHOULD return null.
0098      *
0099      * If no port is present, and no scheme is present, this method MUST return
0100      * a null value.
0101      *
0102      * If no port is present, but a scheme is present, this method MAY return
0103      * the standard port for that scheme, but SHOULD return null.
0104      *
0105      * @return null|int The URI port.
0106      */
0107     public function getPort();
0108 
0109     /**
0110      * Retrieve the path component of the URI.
0111      *
0112      * The path can either be empty or absolute (starting with a slash) or
0113      * rootless (not starting with a slash). Implementations MUST support all
0114      * three syntaxes.
0115      *
0116      * Normally, the empty path "" and absolute path "/" are considered equal as
0117      * defined in RFC 7230 Section 2.7.3. But this method MUST NOT automatically
0118      * do this normalization because in contexts with a trimmed base path, e.g.
0119      * the front controller, this difference becomes significant. It's the task
0120      * of the user to handle both "" and "/".
0121      *
0122      * The value returned MUST be percent-encoded, but MUST NOT double-encode
0123      * any characters. To determine what characters to encode, please refer to
0124      * RFC 3986, Sections 2 and 3.3.
0125      *
0126      * As an example, if the value should include a slash ("/") not intended as
0127      * delimiter between path segments, that value MUST be passed in encoded
0128      * form (e.g., "%2F") to the instance.
0129      *
0130      * @see https://tools.ietf.org/html/rfc3986#section-2
0131      * @see https://tools.ietf.org/html/rfc3986#section-3.3
0132      * @return string The URI path.
0133      */
0134     public function getPath();
0135 
0136     /**
0137      * Retrieve the query string of the URI.
0138      *
0139      * If no query string is present, this method MUST return an empty string.
0140      *
0141      * The leading "?" character is not part of the query and MUST NOT be
0142      * added.
0143      *
0144      * The value returned MUST be percent-encoded, but MUST NOT double-encode
0145      * any characters. To determine what characters to encode, please refer to
0146      * RFC 3986, Sections 2 and 3.4.
0147      *
0148      * As an example, if a value in a key/value pair of the query string should
0149      * include an ampersand ("&") not intended as a delimiter between values,
0150      * that value MUST be passed in encoded form (e.g., "%26") to the instance.
0151      *
0152      * @see https://tools.ietf.org/html/rfc3986#section-2
0153      * @see https://tools.ietf.org/html/rfc3986#section-3.4
0154      * @return string The URI query string.
0155      */
0156     public function getQuery();
0157 
0158     /**
0159      * Retrieve the fragment component of the URI.
0160      *
0161      * If no fragment is present, this method MUST return an empty string.
0162      *
0163      * The leading "#" character is not part of the fragment and MUST NOT be
0164      * added.
0165      *
0166      * The value returned MUST be percent-encoded, but MUST NOT double-encode
0167      * any characters. To determine what characters to encode, please refer to
0168      * RFC 3986, Sections 2 and 3.5.
0169      *
0170      * @see https://tools.ietf.org/html/rfc3986#section-2
0171      * @see https://tools.ietf.org/html/rfc3986#section-3.5
0172      * @return string The URI fragment.
0173      */
0174     public function getFragment();
0175 
0176     /**
0177      * Return an instance with the specified scheme.
0178      *
0179      * This method MUST retain the state of the current instance, and return
0180      * an instance that contains the specified scheme.
0181      *
0182      * Implementations MUST support the schemes "http" and "https" case
0183      * insensitively, and MAY accommodate other schemes if required.
0184      *
0185      * An empty scheme is equivalent to removing the scheme.
0186      *
0187      * @param string $scheme The scheme to use with the new instance.
0188      * @return static A new instance with the specified scheme.
0189      * @throws \InvalidArgumentException for invalid or unsupported schemes.
0190      */
0191     public function withScheme($scheme);
0192 
0193     /**
0194      * Return an instance with the specified user information.
0195      *
0196      * This method MUST retain the state of the current instance, and return
0197      * an instance that contains the specified user information.
0198      *
0199      * Password is optional, but the user information MUST include the
0200      * user; an empty string for the user is equivalent to removing user
0201      * information.
0202      *
0203      * @param string $user The user name to use for authority.
0204      * @param null|string $password The password associated with $user.
0205      * @return static A new instance with the specified user information.
0206      */
0207     public function withUserInfo($user, $password = null);
0208 
0209     /**
0210      * Return an instance with the specified host.
0211      *
0212      * This method MUST retain the state of the current instance, and return
0213      * an instance that contains the specified host.
0214      *
0215      * An empty host value is equivalent to removing the host.
0216      *
0217      * @param string $host The hostname to use with the new instance.
0218      * @return static A new instance with the specified host.
0219      * @throws \InvalidArgumentException for invalid hostnames.
0220      */
0221     public function withHost($host);
0222 
0223     /**
0224      * Return an instance with the specified port.
0225      *
0226      * This method MUST retain the state of the current instance, and return
0227      * an instance that contains the specified port.
0228      *
0229      * Implementations MUST raise an exception for ports outside the
0230      * established TCP and UDP port ranges.
0231      *
0232      * A null value provided for the port is equivalent to removing the port
0233      * information.
0234      *
0235      * @param null|int $port The port to use with the new instance; a null value
0236      *     removes the port information.
0237      * @return static A new instance with the specified port.
0238      * @throws \InvalidArgumentException for invalid ports.
0239      */
0240     public function withPort($port);
0241 
0242     /**
0243      * Return an instance with the specified path.
0244      *
0245      * This method MUST retain the state of the current instance, and return
0246      * an instance that contains the specified path.
0247      *
0248      * The path can either be empty or absolute (starting with a slash) or
0249      * rootless (not starting with a slash). Implementations MUST support all
0250      * three syntaxes.
0251      *
0252      * If the path is intended to be domain-relative rather than path relative then
0253      * it must begin with a slash ("/"). Paths not starting with a slash ("/")
0254      * are assumed to be relative to some base path known to the application or
0255      * consumer.
0256      *
0257      * Users can provide both encoded and decoded path characters.
0258      * Implementations ensure the correct encoding as outlined in getPath().
0259      *
0260      * @param string $path The path to use with the new instance.
0261      * @return static A new instance with the specified path.
0262      * @throws \InvalidArgumentException for invalid paths.
0263      */
0264     public function withPath($path);
0265 
0266     /**
0267      * Return an instance with the specified query string.
0268      *
0269      * This method MUST retain the state of the current instance, and return
0270      * an instance that contains the specified query string.
0271      *
0272      * Users can provide both encoded and decoded query characters.
0273      * Implementations ensure the correct encoding as outlined in getQuery().
0274      *
0275      * An empty query string value is equivalent to removing the query string.
0276      *
0277      * @param string $query The query string to use with the new instance.
0278      * @return static A new instance with the specified query string.
0279      * @throws \InvalidArgumentException for invalid query strings.
0280      */
0281     public function withQuery($query);
0282 
0283     /**
0284      * Return an instance with the specified URI fragment.
0285      *
0286      * This method MUST retain the state of the current instance, and return
0287      * an instance that contains the specified URI fragment.
0288      *
0289      * Users can provide both encoded and decoded fragment characters.
0290      * Implementations ensure the correct encoding as outlined in getFragment().
0291      *
0292      * An empty fragment value is equivalent to removing the fragment.
0293      *
0294      * @param string $fragment The fragment to use with the new instance.
0295      * @return static A new instance with the specified fragment.
0296      */
0297     public function withFragment($fragment);
0298 
0299     /**
0300      * Return the string representation as a URI reference.
0301      *
0302      * Depending on which components of the URI are present, the resulting
0303      * string is either a full URI or relative reference according to RFC 3986,
0304      * Section 4.1. The method concatenates the various components of the URI,
0305      * using the appropriate delimiters:
0306      *
0307      * - If a scheme is present, it MUST be suffixed by ":".
0308      * - If an authority is present, it MUST be prefixed by "//".
0309      * - The path can be concatenated without delimiters. But there are two
0310      *   cases where the path has to be adjusted to make the URI reference
0311      *   valid as PHP does not allow to throw an exception in __toString():
0312      *     - If the path is rootless and an authority is present, the path MUST
0313      *       be prefixed by "/".
0314      *     - If the path is starting with more than one "/" and no authority is
0315      *       present, the starting slashes MUST be reduced to one.
0316      * - If a query is present, it MUST be prefixed by "?".
0317      * - If a fragment is present, it MUST be prefixed by "#".
0318      *
0319      * @see http://tools.ietf.org/html/rfc3986#section-4.1
0320      * @return string
0321      */
0322     public function __toString();
0323 }