SiteURI
        
        extends URI
    
    
            
            in package
            
        
    
    
    
URI for the application site
Tags
Table of Contents
Constants
- CHAR_SUB_DELIMS = '!\$&\'\(\)\*\+,;='
- Sub-delimiters used in query strings and fragments.
- CHAR_UNRESERVED = 'a-zA-Z0-9_\-\.~'
- Unreserved characters used in paths, query strings, and fragments.
Properties
- $defaultPorts : array{http: int, https: int, ftp: int, sftp: int}
- Default schemes/ports.
- $fragment : string
- The name of any fragment.
- $host : string|null
- URI Host
- $password : string|null
- URI User Password
- $path : string|null
- URI path.
- $port : int|null
- URI Port
- $query : array<string, string>
- The query string.
- $rawQueryString : bool
- If true, will use raw query string.
- $scheme : string
- The URI Scheme.
- $segments : array<int, string>
- List of URI segments after indexPage.
- $showPassword : bool
- Whether passwords should be shown in userInfo/authority calls.
- $silent : bool
- If true, will continue instead of throwing exceptions.
- $uriString : string
- Current URI string
- $user : string|null
- URI User Info
- $basePathWithoutIndexPage : string
- The path part of baseURL.
- $baseSegments : array<string|int, mixed>
- List of URI segments in baseURL and indexPage.
- $baseURL : URI
- The current baseURL.
- $indexPage : string
- The Index File.
- $routePath : string
- URI path relative to baseURL.
Methods
- __construct() : mixed
- Constructor.
- __toString() : string
- Formats the URI as a string.
- addQuery() : $this
- Adds a single new element to the query vars.
- baseUrl() : string
- For base_url() helper.
- createURIString() : string
- Builds a representation of the string from the component parts.
- getAuthority() : string
- Retrieve the authority component of the URI.
- getBaseURL() : string
- Returns the baseURL.
- getFragment() : string
- Retrieve a URI fragment
- getHost() : string
- Retrieve the host component of the URI.
- getPath() : string
- Retrieve the path component of the URI.
- getPort() : int|null
- Retrieve the port component of the URI.
- getQuery() : string
- Retrieve the query string
- getRoutePath() : string
- Returns the URI path relative to baseURL.
- getScheme() : string
- Retrieve the scheme component of the URI.
- getSegment() : string
- Returns the value of a specific segment of the URI path.
- getSegments() : array<int, string>
- Returns the segments of the path as an array.
- getTotalSegments() : int
- Returns the total number of segments.
- getUserInfo() : string|null
- Retrieve the user information component of the URI.
- keepQuery() : $this
- Filters the query variables so that only the keys passed in are kept. The rest are removed from the object.
- refreshPath() : $this
- Sets the path portion of the URI based on segments.
- resolveRelativeURI() : URI
- Combines one URI string with this one based on the rules set out in RFC 3986 Section 2
- setAuthority() : $this
- Parses the given string and saves the appropriate authority pieces.
- setBaseURL() : void
- Sets the current baseURL.
- setFragment() : $this
- Sets the fragment portion of the URI.
- setHost() : $this
- Sets the host name to use.
- setPath() : $this
- Sets the route path (and segments).
- setPort() : $this
- Sets the port portion of the URI.
- setQuery() : $this
- Sets the query portion of the URI, while attempting to clean the various parts of the query keys and values.
- setQueryArray() : URI
- A convenience method to pass an array of items in as the Query portion of the URI.
- setScheme() : $this
- Sets the scheme for this URI.
- setSegment() : $this
- Set the value of a specific segment of the URI path.
- setSilent() : URI
- If $silent == true, then will not throw exceptions and will attempt to continue gracefully.
- setURI() : URI
- Sets and overwrites any current URI information.
- setUserInfo() : $this
- Sets the userInfo/Authority portion of the URI.
- showPassword() : URI
- Temporarily sets the URI to show a password in userInfo. Will reset itself after the first call to authority().
- siteUrl() : string
- For site_url() helper.
- stripQuery() : $this
- Removes one or more query vars from the URI.
- useRawQueryString() : URI
- If $raw == true, then will use parseStr() method instead of native parse_str() function.
- withScheme() : static
- Return an instance with the specified scheme.
- applyParts() : void
- Saves our parts from a parse_url() call.
- filterPath() : string
- Encodes any dangerous characters, and removes dot segments.
- mergePaths() : string
- Given 2 paths, will merge them according to rules set out in RFC 2986, Section 5.2
- parseStr() : array<string, string>
- This is equivalent to the native PHP parse_str() function.
- convertToSegments() : array<string|int, mixed>
- Converts path to segments
- determineBaseURL() : URI
- getIndexPageRoutePath() : string
- normalizeBaseURL() : string
- parseRelativePath() : array<string|int, mixed>
- setBasePath() : void
- Sets basePathWithoutIndexPage and baseSegments.
- setRoutePath() : void
- Sets the route path (and segments).
- stringifyRelativePath() : string
Constants
CHAR_SUB_DELIMS
Sub-delimiters used in query strings and fragments.
    public
        mixed
    CHAR_SUB_DELIMS
    = '!\$&\'\(\)\*\+,;='
    
    
    
    
CHAR_UNRESERVED
Unreserved characters used in paths, query strings, and fragments.
    public
        mixed
    CHAR_UNRESERVED
    = 'a-zA-Z0-9_\-\.~'
    
    
    
    
Properties
$defaultPorts
Default schemes/ports.
        protected
            array{http: int, https: int, ftp: int, sftp: int}
    $defaultPorts
     = ['http' => 80, 'https' => 443, 'ftp' => 21, 'sftp' => 22]
    
    
    
    
    
$fragment
The name of any fragment.
        protected
            string
    $fragment
     = ''
    
    
    
    
    
$host
URI Host
        protected
            string|null
    $host
    
    
    
    
    
    
$password
URI User Password
        protected
            string|null
    $password
    
    
    
    
    
    
$path
URI path.
        protected
            string|null
    $path
    
    
    
    
    
    
$port
URI Port
        protected
            int|null
    $port
    
    
    
    
    
    
$query
The query string.
        protected
            array<string, string>
    $query
     = []
    
    
    
    
    
$rawQueryString
If true, will use raw query string.
        protected
            bool
    $rawQueryString
     = false
    
    
    
    
    
$scheme
The URI Scheme.
        protected
            string
    $scheme
     = 'http'
    
    
    
    
    
$segments
List of URI segments after indexPage.
This property will be private.
        protected
            array<int, string>
    $segments
    
        The word "URI Segments" originally means only the URI path part relative to the baseURL.
If the URI is "http://localhost:8888/ci431/public/index.php/test?a=b", and the baseURL is "http://localhost:8888/ci431/public/", then: $segments = [ 0 => 'test', ];
$showPassword
Whether passwords should be shown in userInfo/authority calls.
        protected
            bool
    $showPassword
     = false
        Default to false because URIs often show up in logs
$silent
If true, will continue instead of throwing exceptions.
        protected
            bool
    $silent
     = false
    
    
    
    
    
$uriString
Current URI string
Not used.
        protected
            string
    $uriString
    
    
    
    
    
    
$user
URI User Info
        protected
            string|null
    $user
    
    
    
    
    
    
$basePathWithoutIndexPage
The path part of baseURL.
        private
            string
    $basePathWithoutIndexPage
    
        The baseURL "http://example.com/" → '/' The baseURL "http://localhost:8888/ci431/public/" → '/ci431/public/'
$baseSegments
List of URI segments in baseURL and indexPage.
        private
            array<string|int, mixed>
    $baseSegments
    
        If the URI is "http://localhost:8888/ci431/public/index.php/test?a=b", and the baseURL is "http://localhost:8888/ci431/public/", then: $baseSegments = [ 0 => 'ci431', 1 => 'public', 2 => 'index.php', ];
$baseURL read-only
The current baseURL.
        private
            URI
    $baseURL
    
    
    
    
    
    
$indexPage read-only
The Index File.
        private
            string
    $indexPage
    
    
    
    
    
    
$routePath
URI path relative to baseURL.
        private
            string
    $routePath
    
        If the baseURL contains sub folders, this value will be different from the current URI path.
This value never starts with '/'.
Methods
__construct()
Constructor.
    public
                    __construct(App $configApp[, string $relativePath = '' ][, string|null $host = null ][, "http"|"https"|null $scheme = null ]) : mixed
    Parameters
- $configApp : App
- $relativePath : string = ''
- 
                    URI path relative to baseURL. May include queries or fragments. 
- $host : string|null = null
- 
                    Optional current hostname. 
- $scheme : "http"|"https"|null = null
- 
                    Optional scheme. 'http' or 'https'. 
__toString()
Formats the URI as a string.
    public
                    __toString() : string
    Return values
stringaddQuery()
Adds a single new element to the query vars.
    public
                    addQuery(string $key[, int|string|null $value = null ]) : $this
    Note: Method not in PSR-7
Parameters
- $key : string
- $value : int|string|null = null
Return values
$thisbaseUrl()
For base_url() helper.
    public
                    baseUrl([array<string|int, mixed>|string $relativePath = '' ][, string|null $scheme = null ]) : string
    Parameters
- $relativePath : array<string|int, mixed>|string = ''
- 
                    URI string or array of URI segments. 
- $scheme : string|null = null
- 
                    URI scheme. E.g., http, ftp. If empty string '' is set, a protocol-relative link is returned. 
Return values
stringcreateURIString()
Builds a representation of the string from the component parts.
    public
            static        createURIString([string|null $scheme = null ][, string|null $authority = null ][, string|null $path = null ][, string|null $query = null ][, string|null $fragment = null ]) : string
    Parameters
- $scheme : string|null = null
- 
                    URI scheme. E.g., http, ftp 
- $authority : string|null = null
- $path : string|null = null
- $query : string|null = null
- $fragment : string|null = null
Return values
string —URI string with only passed parts. Maybe incomplete as a URI.
getAuthority()
Retrieve the authority component of the URI.
    public
                    getAuthority([bool $ignorePort = false ]) : string
    If no authority information is present, this method MUST return an empty string.
The authority syntax of the URI is:
[user-info@]host[:port]
If the port component is not set or is the standard port for the current scheme, it SHOULD NOT be included.
Parameters
- $ignorePort : bool = false
Tags
Return values
string —The URI authority, in "[user-info@]host[:port]" format.
getBaseURL()
Returns the baseURL.
    public
                    getBaseURL() : string
    Tags
Return values
stringgetFragment()
Retrieve a URI fragment
    public
                    getFragment() : string
    Return values
stringgetHost()
Retrieve the host component of the URI.
    public
                    getHost() : string
    If no host is present, this method MUST return an empty string.
The value returned MUST be normalized to lowercase, per RFC 3986 Section 3.2.2.
Tags
Return values
string —The URI host.
getPath()
Retrieve the path component of the URI.
    public
                    getPath() : string
    The path can either be empty or absolute (starting with a slash) or rootless (not starting with a slash). Implementations MUST support all three syntaxes.
Normally, the empty path "" and absolute path "/" are considered equal as defined in RFC 7230 Section 2.7.3. But this method MUST NOT automatically do this normalization because in contexts with a trimmed base path, e.g. the front controller, this difference becomes significant. It's the task of the user to handle both "" and "/".
The value returned MUST be percent-encoded, but MUST NOT double-encode any characters. To determine what characters to encode, please refer to RFC 3986, Sections 2 and 3.3.
As an example, if the value should include a slash ("/") not intended as delimiter between path segments, that value MUST be passed in encoded form (e.g., "%2F") to the instance.
Tags
Return values
string —The URI path.
getPort()
Retrieve the port component of the URI.
    public
                    getPort() : int|null
    If a port is present, and it is non-standard for the current scheme, this method MUST return it as an integer. If the port is the standard port used with the current scheme, this method SHOULD return null.
If no port is present, and no scheme is present, this method MUST return a null value.
If no port is present, but a scheme is present, this method MAY return the standard port for that scheme, but SHOULD return null.
Return values
int|null —The URI port.
getQuery()
Retrieve the query string
    public
                    getQuery([array{except?: list|string, only?: list|string}   $options = [] ]) : string
    Parameters
- 
                $options
                : array{except?: list|string, only?: list = []|string} 
Return values
stringgetRoutePath()
Returns the URI path relative to baseURL.
    public
                    getRoutePath() : string
    Return values
string —The Route path.
getScheme()
Retrieve the scheme component of the URI.
    public
                    getScheme() : string
    If no scheme is present, this method MUST return an empty string.
The value returned MUST be normalized to lowercase, per RFC 3986 Section 3.1.
The trailing ":" character is not part of the scheme and MUST NOT be added.
Tags
Return values
string —The URI scheme.
getSegment()
Returns the value of a specific segment of the URI path.
    public
                    getSegment(int $number[, string $default = '' ]) : string
    Allows to get only existing segments or the next one.
Parameters
- $number : int
- 
                    Segment number starting at 1 
- $default : string = ''
- 
                    Default value 
Return values
string —The value of the segment. If you specify the last +1 segment, the $default value. If you specify the last +2 or more throws HTTPException.
getSegments()
Returns the segments of the path as an array.
    public
                    getSegments() : array<int, string>
    Return values
array<int, string>getTotalSegments()
Returns the total number of segments.
    public
                    getTotalSegments() : int
    Note: Method not in PSR-7
Return values
intgetUserInfo()
Retrieve the user information component of the URI.
    public
                    getUserInfo() : string|null
    If no user information is present, this method MUST return an empty string.
If a user is present in the URI, this will return that value; additionally, if the password is also present, it will be appended to the user value, with a colon (":") separating the values.
NOTE that be default, the password, if available, will NOT be shown as a security measure as discussed in RFC 3986, Section 7.5. If you know the password is not a security issue, you can force it to be shown with $this->showPassword();
The trailing "@" character is not part of the user information and MUST NOT be added.
Return values
string|null —The URI user information, in "username[:password]" format.
keepQuery()
Filters the query variables so that only the keys passed in are kept. The rest are removed from the object.
    public
                    keepQuery(string ...$params) : $this
    Note: Method not in PSR-7
Parameters
- $params : string
Return values
$thisrefreshPath()
Sets the path portion of the URI based on segments.
    public
                    refreshPath() : $this
    This method will be private.
Return values
$thisresolveRelativeURI()
Combines one URI string with this one based on the rules set out in RFC 3986 Section 2
    public
                    resolveRelativeURI(string $uri) : URI
    Parameters
- $uri : string
Tags
Return values
URIsetAuthority()
Parses the given string and saves the appropriate authority pieces.
    public
                    setAuthority(string $str) : $this
    Note: Method not in PSR-7
Parameters
- $str : string
Return values
$thissetBaseURL()
Sets the current baseURL.
    public
                    setBaseURL(string $baseURL) : void
    Parameters
- $baseURL : string
setFragment()
Sets the fragment portion of the URI.
    public
                    setFragment(string $string) : $this
    Parameters
- $string : string
Tags
Return values
$thissetHost()
Sets the host name to use.
    public
                    setHost(string $str) : $this
    Parameters
- $str : string
Tags
Return values
$thissetPath()
Sets the route path (and segments).
    public
                    setPath(string $path) : $this
    Parameters
- $path : string
Return values
$thissetPort()
Sets the port portion of the URI.
    public
                    setPort([int|null $port = null ]) : $this
    Parameters
- $port : int|null = null
Tags
Return values
$thissetQuery()
Sets the query portion of the URI, while attempting to clean the various parts of the query keys and values.
    public
                    setQuery(string $query) : $this
    Parameters
- $query : string
Tags
Return values
$thissetQueryArray()
A convenience method to pass an array of items in as the Query portion of the URI.
    public
                    setQueryArray(array<string|int, mixed> $query) : URI
    Parameters
- $query : array<string|int, mixed>
Tags
Return values
URIsetScheme()
Sets the scheme for this URI.
    public
                    setScheme(string $str) : $this
    Use withScheme() instead.
Because of the large number of valid schemes we cannot limit this to only http or https.
Parameters
- $str : string
Tags
Return values
$thissetSegment()
Set the value of a specific segment of the URI path.
    public
                    setSegment(int $number, int|string $value) : $this
    Allows to set only existing segments or add new one.
Note: Method not in PSR-7
Parameters
- $number : int
- 
                    Segment number starting at 1 
- $value : int|string
Return values
$thissetSilent()
If $silent == true, then will not throw exceptions and will attempt to continue gracefully.
    public
                    setSilent([bool $silent = true ]) : URI
    Method not in PSR-7
Parameters
- $silent : bool = true
Return values
URIsetURI()
Sets and overwrites any current URI information.
    public
                    setURI([string|null $uri = null ]) : URI
    Parameters
- $uri : string|null = null
Return values
URIsetUserInfo()
Sets the userInfo/Authority portion of the URI.
    public
                    setUserInfo(string $user, string $pass) : $this
    Parameters
- $user : string
- 
                    The user's username 
- $pass : string
- 
                    The user's password 
Tags
Return values
$thisshowPassword()
Temporarily sets the URI to show a password in userInfo. Will reset itself after the first call to authority().
    public
                    showPassword([bool $val = true ]) : URI
    Note: Method not in PSR-7
Parameters
- $val : bool = true
Return values
URIsiteUrl()
For site_url() helper.
    public
                    siteUrl([array<string|int, mixed>|string $relativePath = '' ][, string|null $scheme = null ][, App|null $config = null ]) : string
    Parameters
- $relativePath : array<string|int, mixed>|string = ''
- 
                    URI string or array of URI segments. 
- $scheme : string|null = null
- 
                    URI scheme. E.g., http, ftp. If empty string '' is set, a protocol-relative link is returned. 
- $config : App|null = null
- 
                    Alternate configuration to use. 
Return values
stringstripQuery()
Removes one or more query vars from the URI.
    public
                    stripQuery(string ...$params) : $this
    Note: Method not in PSR-7
Parameters
- $params : string
Return values
$thisuseRawQueryString()
If $raw == true, then will use parseStr() method instead of native parse_str() function.
    public
                    useRawQueryString([bool $raw = true ]) : URI
    Note: Method not in PSR-7
Parameters
- $raw : bool = true
Return values
URIwithScheme()
Return an instance with the specified scheme.
    public
                    withScheme(string $scheme) : static
    This method MUST retain the state of the current instance, and return an instance that contains the specified scheme.
Implementations MUST support the schemes "http" and "https" case insensitively, and MAY accommodate other schemes if required.
An empty scheme is equivalent to removing the scheme.
Parameters
- $scheme : string
- 
                    The scheme to use with the new instance. 
Tags
Return values
static —A new instance with the specified scheme.
applyParts()
Saves our parts from a parse_url() call.
    protected
                    applyParts(array{host?: string, user?: string, path?: string, query?: string, fragment?: string, scheme?: string, port?: int, pass?: string} $parts) : void
    Parameters
- $parts : array{host?: string, user?: string, path?: string, query?: string, fragment?: string, scheme?: string, port?: int, pass?: string}
filterPath()
Encodes any dangerous characters, and removes dot segments.
    protected
                    filterPath([string|null $path = null ]) : string
    While dot segments have valid uses according to the spec, this URI class does not allow them.
Parameters
- $path : string|null = null
Return values
stringmergePaths()
Given 2 paths, will merge them according to rules set out in RFC 2986, Section 5.2
    protected
                    mergePaths(self $base, self $reference) : string
    Parameters
- $base : self
- $reference : self
Tags
Return values
stringparseStr()
This is equivalent to the native PHP parse_str() function.
    protected
                    parseStr(string $query) : array<string, string>
    This version allows the dot to be used as a key of the query string.
Parameters
- $query : string
Return values
array<string, string>convertToSegments()
Converts path to segments
    private
                    convertToSegments(string $path) : array<string|int, mixed>
    Parameters
- $path : string
Return values
array<string|int, mixed>determineBaseURL()
    private
                    determineBaseURL(App $configApp, string|null $host, string|null $scheme) : URI
    Parameters
- $configApp : App
- $host : string|null
- $scheme : string|null
Return values
URIgetIndexPageRoutePath()
    private
                    getIndexPageRoutePath(string $routePath) : string
    Parameters
- $routePath : string
Return values
stringnormalizeBaseURL()
    private
                    normalizeBaseURL(App $configApp) : string
    Parameters
- $configApp : App
Return values
stringparseRelativePath()
    private
                    parseRelativePath(string $relativePath) : array<string|int, mixed>
    Parameters
- $relativePath : string
Return values
array<string|int, mixed>setBasePath()
Sets basePathWithoutIndexPage and baseSegments.
    private
                    setBasePath() : void
    setRoutePath()
Sets the route path (and segments).
    private
                    setRoutePath(string $routePath) : void
    Parameters
- $routePath : string
stringifyRelativePath()
    private
                    stringifyRelativePath(array<string|int, mixed>|string $relativePath) : string
    Parameters
- $relativePath : array<string|int, mixed>|string
- 
                    URI string or array of URI segments