In PSR-7 URI is reprecented by an implementation of
Psr\Http\Message\UriInterface. we implement this as
according to PSR7 a uri is of the format
scheme://authority/path?query#fragment or in more detail
scheme:[//[user:password@]host[:port]][/]path[?query][#fragment]. but what we need in most cases is regular url like
You can get the Uri object of current request from
request inside the container.
from here onwards assume that:
$this->request = $this->container->get('request'); $uri = $this->request->getUri();
Uri schemes supported by Briz are
HTTPS or it can be blank as a placeholder. Other uri schemes will result in an
getScheme() will return the scheme
$scheme = $uri->getScheme();
withScheme($scheme) method will return an instance of the Uri object with the given scheme.
$uri = $uri->withScheme($scheme);
A host can be an IP address or an address like
example.com or long address like
getHost() method will return a string host name.
$host = $uri->getHost();
withHost($host) method will return an instance of the Uri object with the new Host.
$host = $uri->withHost($host);
a port number must be between 1 and 65535. the default port number of http is 80 and that of https is 443. If you are using
a port number other than default one then you must specify it.
http://example.com is actually
80 is the default port of http it is nor given. the briz quick start tutorial will start php development server at port 8000.
so you have to specify it as
http://localhost:8000 since 8000 is not the default port.
getPort() method will return the port number as integer.
$port = $uri->getPort();
withPort($port) method will return an instance of the uri object with the given port number.
$uri = $uri->withPort($port);
gets the current uri path.
$path = $uri->getPath();
return an instance of current uri with given path.
$uri = $uri->withPath($path);
The Query String is separated from the preceding part by a question mark.
getQuery() method will return the query string
$query = $uri->getQuery();
withQuery($query) will return an instance of the Uri object with given query string.
$uri = $uri->withQuery($query);
the part of the Uri after
# is called Uri Fragment. it is usually used as identifiers for sections in html page.
getFragment() method will return the Uri fragment as string.
$fragment = $uri->getFragment();
withFragment($fragment) method will return a clone of the Uri object with given fragment.
$uri = $uri->withFragment($fragment);
Uri as defined by
PSR-7 can contain user information. user information is usename and password. empty passwords
are also valid.
this method will retrieve
username:password format string. if there is no password it will return
username. if there is no
usename or password it will return a blank string.
$user = $uri->getUserInfo();
withUserInfo($user, $password) returns an instance of the Uri with the given user info. the password is optional.
$uri = $uri->withUserInfo($user, $password);