Skip to content

Instantly share code, notes, and snippets.

@thewilkybarkid
Last active December 21, 2020 12:05
Show Gist options
  • Save thewilkybarkid/4585809 to your computer and use it in GitHub Desktop.
Save thewilkybarkid/4585809 to your computer and use it in GitHub Desktop.
<?php
namespace Psr\Uri;
use Psr\Uri\Exception\InvalidArgumentException;
/**
* A hierarchical uniform resource identifier (URI) is either an absolute URI
* whose scheme-specific part begins with a slash ("/"), or a relative URI,
* that is, a URI that does not specify a scheme.
*
* <pre>
* foo://user:password@example.com:8042/over/there?name=ferret#teeth
* \_/ \___________/ \_________/ \__/\_________/ \_________/ \___/
* | | | | | | |
* | user info host port | | |
* | \____________________________/ | | |
* | | | | |
* | authority path query fragment
* | \_________________________________________/
* | |
* | hierarchical part
* | \___________________________________________________________/
* | |
* scheme scheme-specific part
* </pre>
*
* Some examples of hierarchical URIs are:
*
* - <samp>http://php.net/manual/en/</samp>
* - <samp>manual/en/language.oop5.interfaces.php</samp>
* - <samp>../../conferences/</samp>
* - <samp>file:///~/calendar</samp>
*/
interface HierarchicalUriInterface extends UriInterface
{
/**
* Gets the hierarchical part.
*
* The hierarchical part is in the format:
*
* <pre>
* [//authority/]path[?query][#fragment]
* </pre>
*
* Implementations MUST return the preceding double slash ("//") if the
* authority component is present. They MUST NOT return a succeeding
* question mark ("?") or number sign ("#") that delimits it from a path,
* query or fragment component respectively.
*
* @return string|null Hierarchical part, or `null` if not set.
*/
public function getHierarchicalPart();
/**
* Gets the authority component.
*
* The authority component is in the format:
*
* <pre>
* [user-info@]host[:port]
* </pre>
*
* If the port subcomponent has been set as the known default for the
* scheme component it SHOULD NOT be included.
*
* Implementations MUST NOT return the preceding double slash ("//") nor a
* subsequent slash ("/"), question mark ("?") or number sign ("#") that
* delimits it from a path, query or fragment component respectively.
*
* @return string Authority component, or `null` if not set.
*/
public function getAuthority();
/**
* Gets the user info subcomponent of the authority.
*
* Implementations MUST NOT return the succeeding at-sign ("@").
*
* @return string|null User info component, or `null` if not set.
*/
public function getUserInfo();
/**
* Sets the user info subcomponent of the authority.
*
* A `null` value will remove the existing user info subcomponent.
*
* @param string $userInfo User info subcomponent.
*
* @return self Reference to the URI.
*
* @throws InvalidArgumentException When the user subcomponent is not valid.
*/
public function setUserInfo($userInfo);
/**
* Gets the host subcomponent of the authority.
*
* It MUST be treated as case-insensitive.
*
* @return string|null Host subcomponent, or `null` if not set.
*/
public function getHost();
/**
* Set the host subcomponent of the authority.
*
* The host subcomponent MUST be one of:
*
* - A domain name.
* - An IPv4 address.
* - An IPv6 address.
*
* The host MUST be a string, or an object that implements the
* `__toString()` method.
*
* A `null` value will remove the existing host subcomponent.
*
* @param string $host Host subcomponent.
*
* @return self Reference to the URL.
*
* @throws InvalidArgumentException When the host subcomponent is not valid.
*/
public function setHost($host);
/**
* Gets the port subcomponent of the authority.
*
* If the port has not been explicitly set using `setPort()` this MAY
* return the default port for the scheme.
*
* @return int|null Port subcomponent, or `null` if not set.
*/
public function getPort();
/**
* Sets the port subcomponent of the authority.
*
* The port subcomponent MUST be a non-negative integer.
*
* A `null` value will remove the existing port subcomponent.
*
* @param int $port Port subcomponent.
*
* @return self Reference to the URI.
*
* @throws InvalidArgumentException When the port subcomponent is not valid.
*/
public function setPort($port);
}
<?php
namespace Psr\Uri;
/**
* An opaque uniform resource identifier (URI) is an absolute URI whose
* scheme-specific part does not begin with a slash character ("/").
*
* <pre>
* urn:example:animal?name=ferret#teeth
* \_/ \____________/ \_________/ \___/
* | | | |
* | path query fragment
* | \____________/
* | |
* | hierarchical part
* | \______________________________/
* | |
* scheme scheme-specific part
* </pre>
*
* Some examples of opaque URIs are:
*
* - <samp>mailto:example@example.com</samp>
* - <samp>news:comp.lang.php</samp>
* - <samp>urn:isbn:096139210x</samp>
*/
interface OpaqueUriInterface extends UriInterface
{
/**
* Gets the hierarchical part.
*
* The hierarchical part for opaque URIs is the path.
*
* @return string|null Hierarchical part, or `null` if not set.
*/
public function getHierarchicalPart();
}
<?php
namespace Psr\Uri;
use Psr\Uri\Exception\InvalidArgumentException;
/**
* Represents a uniform resource identifier (URI), which identifies an abstract
* or physical resource.
*
* <pre>
* scheme-specific part
* __________________|___________________
* / \
* foo://example.com:8080/bar?name=ferret#teeth
* \_/ \__________________/ \_________/ \___/
* | | | |
* scheme hierarchical part query fragment
* | __________|_________ ____|____ _|_
* / \ / \ / \ / \
* urn:example:example:animal?name=ferret#teeth
* \______________________________________/
* |
* scheme-specific part
* </pre>
*
* This interface is not to be implemented directly, instead implement
* `OpaqueUriInterface` or `HierarchicalUriInterface` as appropriate.
*/
interface UriInterface
{
/**
* Returns the URI as a string.
*
* @return string URI as a string.
*/
public function __toString();
/**
* Whether this URI is absolute or not.
*
* A URI is absolute if, and only if, it has a scheme component.
*
* @return bool `true` if the URI is absolute, otherwise `false`.
*/
public function isAbsolute();
/**
* Gets the scheme component.
*
* It MUST be treated as case-insensitive.
*
* Implementations MUST NOT return the succeeding colon (":").
*
* @return string|null Scheme component, or `null` if not set.
*/
public function getScheme();
/**
* Sets the scheme component
*
* A `null` value will remove the existing scheme component.
*
* @param string $scheme Scheme component.
*
* @return self Reference to the URI.
*
* @throws InvalidArgumentException When the scheme component is not valid.
*/
public function setScheme($scheme);
/**
* Gets the scheme-specific part.
*
* Implementations MUST NOT return the preceding colon (":").
*
* @return string|null Scheme-specific part, or `null` if not set.
*/
public function getSchemeSpecificPart();
/**
* Gets the hierarchical part.
*
* @return string|null Hierarchical part, or `null` if not set.
*/
public function getHierarchicalPart();
/**
* Gets the path.
*
* Implementations MUST return an empty string (as opposed to `null`) when
* no path is set.
*
* @return string Path.
*/
public function getPath();
/**
* Sets the path component.
*
* The query MUST be a string, or an object that implements the
* `__toString()` method. An implementation MAY also accept an array.
*
* Implementations MAY treat a `null` value as an empty string.
*
* @param string $path Path component.
*
* @return self Reference to the URI.
*
* @throws InvalidArgumentException When the path component is not valid.
*/
public function setPath($path);
/**
* Gets the query component.
*
* Implementations MUST NOT return the preceding question mark ("?") nor a
* succeeding number sign ("#").
*
* @return string|null Query component, or `null` if not set.
*/
public function getQuery();
/**
* Sets the query component.
*
* The query MUST be a string, or an object that implements the
* `__toString()` method. An implementation MAY also accept an associative
* array.
*
* A `null` value will remove the existing query component.
*
* @param mixed $query Query component.
*
* @return self Reference to the URI.
*
* @throws InvalidArgumentException When the query component is not valid.
*/
public function setQuery($query);
/**
* Gets the fragment component.
*
* Implementations MUST NOT return the preceding number sign ("#").
*
* @return string|null Fragment component, or `null` if not set.
*/
public function getFragment();
/**
* Sets the fragment component.
*
* The fragment component MUST be a string, or an object that implements the
* `__toString()` method.
*
* A `null` value will remove the existing fragment component.
*
* @param string $fragment Fragment component.
*
* @return self Reference to the URI.
*
* @throws InvalidArgumentException When the fragment component is not valid.
*/
public function setFragment($fragment);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment