Documentation

Uri
in package

Class Uri

Table of Contents

Constants

HOSTNAME_REGEX  = '/^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$/'

Properties

$url  : string
$base  : string
$basename  : string|null
$content_path  : string
$currentRoute  : Route|null
$currentUri  : Uri|null
$env  : string
$extension  : string|null
$fragment  : string|null
$host  : string|null
$params  : array<string|int, mixed>
$password  : string|null
$path  : string
$paths  : array<string|int, mixed>
$port  : int|null
$post  : array<string|int, mixed>
$queries  : array<string|int, mixed>
$query  : string
$root  : string
$root_path  : string
$scheme  : string|null
$setup_base  : string
$uri  : string
$user  : string|null

Methods

__construct()  : mixed
Uri constructor.
__toString()  : string
addNonce()  : string
Adds the nonce to a URL for a specific action
base()  : string
Return the base of the URI
baseIncludingLanguage()  : string
Return the base relative URL including the language prefix or the base relative url if multi-language is not enabled
basename()  : string
Return the basename of the URI
buildParams()  : string
buildUrl()  : string
The opposite of built-in PHP method parse_url()
cleanPath()  : string
Removes extra double slashes and fixes back-slashes
convertUrl()  : string|array<string|int, mixed>
Converts links from absolute '/' or relative (../..) to a Grav friendly format
convertUrlOld()  : string
Converts links from absolute '/' or relative (../..) to a Grav friendly format
currentPage()  : int
Return current page number.
environment()  : string
Gets the environment name
extension()  : string|null
Return the Extension of the URI
extractParams()  : array<string|int, mixed>
filterPath()  : string
Filter Uri path.
filterQuery()  : string
Filters the query string or fragment of a URI.
filterUserInfo()  : string
Filters the user info string.
fragment()  : string|null
Gets the Fragment portion of a URI (eg #target)
getAllHeaders()  : mixed
Compatibility in case getallheaders() is not available on platform
getContentType()  : null|string
Get content type from request
getCurrentRoute()  : Route
Returns current route.
getCurrentUri()  : Uri
Returns current Uri.
host()  : string|null
Return the host of the URI
init()  : void
Initializes the URI object based on the url set on the object
initializeWithUrl()  : $this
Initialize the URI class with a url passed via parameter.
initializeWithUrlAndRootPath()  : $this
Initialize the URI class by providing url and root_path arguments
ip()  : string
Return the IP address of the current user
isExternal()  : bool
Is this an external URL? if it starts with `http` then yes, else false
isValidExtension()  : bool
Check if this is a valid Grav extension
isValidUrl()  : bool
Is the passed in URL a valid URL?
method()  : string
param()  : string|false|null
Get URI parameter.
params()  : null|string|array<string|int, mixed>
Return all or a single query parameter as a URI compatible string.
paramsRegex()  : string
Calculate the parameter regex based on the param_sep setting
parseUrl()  : array<string|int, mixed>|false
password()  : string|null
Return password
path()  : string
Return the Path
paths()  : string|array<string|int, string>
Return URI path.
port()  : int|null
Return the port number if it can be figured out
post()  : array<string|int, mixed>|null
Get post from either $_POST or JSON response object By default returns all data, or can return a single item
query()  : string|array<string|int, mixed>
Return full query string or a single query attribute.
referrer()  : string
Return relative path to the referrer defaulting to current or given page.
rootUrl()  : string
Return root URL to the site.
route()  : string
Return route to the current URI. By default route doesn't include base path.
scheme()  : string
Return the scheme of the URI
setUriProperties()  : Uri
Allow overriding of any element (be careful!)
toArray()  : array<string|int, mixed>
toOriginalString()  : string
uri()  : string
Return the full uri
url()  : string
Return URL.
user()  : string|null
Return user
validateHostname()  : bool
Validate a hostname
createFromEnvironment()  : void
createFromString()  : mixed
hasStandardPort()  : bool
Does this Uri use a standard port?
reset()  : void
buildBaseUrl()  : string
Get the base URI with port if needed
buildEnvironment()  : string
buildRootPath()  : string
Get the Grav Root Path
processParams()  : string
Process any params based in this URL, supports any valid delimiter

Constants

HOSTNAME_REGEX

public mixed HOSTNAME_REGEX = '/^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$/'

Properties

$url

public string $url

$base

protected string $base

$basename

protected string|null $basename

$content_path

protected string $content_path

$currentRoute

protected static Route|null $currentRoute

$currentUri

protected static Uri|null $currentUri

$env

protected string $env

$extension

protected string|null $extension

$fragment

protected string|null $fragment

$host

protected string|null $host

$params

protected array<string|int, mixed> $params

$password

protected string|null $password

$path

protected string $path

$paths

protected array<string|int, mixed> $paths

$port

protected int|null $port

$post

protected array<string|int, mixed> $post

$queries

protected array<string|int, mixed> $queries

$query

protected string $query

$root

protected string $root

$root_path

protected string $root_path

$scheme

protected string|null $scheme

$setup_base

protected string $setup_base

$uri

protected string $uri

$user

protected string|null $user

Methods

__construct()

Uri constructor.

public __construct([string|array<string|int, mixed>|null $env = null ]) : mixed
Parameters
$env : string|array<string|int, mixed>|null = null

__toString()

public __toString() : string
Attributes
#[ReturnTypeWillChange]
Return values
string

addNonce()

Adds the nonce to a URL for a specific action

public static addNonce(string $url, string $action[, string $nonceParamName = 'nonce' ]) : string
Parameters
$url : string

the url

$action : string

the action

$nonceParamName : string = 'nonce'

the param name to use

Return values
string

the url with the nonce

base()

Return the base of the URI

public base() : string
Return values
string

The base of the URI

baseIncludingLanguage()

Return the base relative URL including the language prefix or the base relative url if multi-language is not enabled

public baseIncludingLanguage() : string
Return values
string

The base of the URI

basename()

Return the basename of the URI

public basename() : string
Return values
string

The basename of the URI

buildParams()

public static buildParams(array<string|int, mixed> $params) : string
Parameters
$params : array<string|int, mixed>
Return values
string

buildUrl()

The opposite of built-in PHP method parse_url()

public static buildUrl(array<string|int, mixed> $parsed_url) : string
Parameters
$parsed_url : array<string|int, mixed>
Return values
string

cleanPath()

Removes extra double slashes and fixes back-slashes

public static cleanPath(string $path) : string
Parameters
$path : string
Return values
string

convertUrl()

Converts links from absolute '/' or relative (../..) to a Grav friendly format

public static convertUrl(PageInterface $page, string|array<string|int, mixed> $url[, string $type = 'link' ][, bool $absolute = false ][, bool $route_only = false ]) : string|array<string|int, mixed>
Parameters
$page : PageInterface

the current page to use as reference

$url : string|array<string|int, mixed>

the URL as it was written in the markdown

$type : string = 'link'

the type of URL, image | link

$absolute : bool = false

if null, will use system default, if true will use absolute links internally

$route_only : bool = false

only return the route, not full URL path

Return values
string|array<string|int, mixed>

the more friendly formatted url

convertUrlOld()

Converts links from absolute '/' or relative (../..) to a Grav friendly format

public static convertUrlOld(PageInterface $page, string $markdown_url[, string $type = 'link' ][, bool|null $relative = null ]) : string
Parameters
$page : PageInterface

the current page to use as reference

$markdown_url : string

the URL as it was written in the markdown

$type : string = 'link'

the type of URL, image | link

$relative : bool|null = null

if null, will use system default, if true will use relative links internally

Return values
string

the more friendly formatted url

currentPage()

Return current page number.

public currentPage() : int
Return values
int

environment()

Gets the environment name

public environment() : string
Return values
string

extension()

Return the Extension of the URI

public extension([string|null $default = null ]) : string|null
Parameters
$default : string|null = null
Return values
string|null

The extension of the URI

extractParams()

public static extractParams(string $uri, string $delimiter) : array<string|int, mixed>
Parameters
$uri : string
$delimiter : string
Return values
array<string|int, mixed>

filterPath()

Filter Uri path.

public static filterPath(string|null $path) : string

This method percent-encodes all reserved characters in the provided path string. This method will NOT double-encode characters that are already percent-encoded.

Parameters
$path : string|null

The raw uri path.

Tags
link
http://www.faqs.org/rfcs/rfc3986.html
Return values
string

The RFC 3986 percent-encoded uri path.

filterQuery()

Filters the query string or fragment of a URI.

public static filterQuery(string|null $query) : string
Parameters
$query : string|null

The raw uri query string.

Return values
string

The percent-encoded query string.

filterUserInfo()

Filters the user info string.

public static filterUserInfo(string|null $info) : string
Parameters
$info : string|null

The raw user or password.

Return values
string

The percent-encoded user or password string.

fragment()

Gets the Fragment portion of a URI (eg #target)

public fragment([string|null $fragment = null ]) : string|null
Parameters
$fragment : string|null = null
Return values
string|null

getAllHeaders()

Compatibility in case getallheaders() is not available on platform

public static getAllHeaders() : mixed

getContentType()

Get content type from request

public getContentType([bool $short = true ]) : null|string
Parameters
$short : bool = true
Return values
null|string

getCurrentRoute()

Returns current route.

public static getCurrentRoute() : Route
Return values
Route

getCurrentUri()

Returns current Uri.

public static getCurrentUri() : Uri
Return values
Uri

host()

Return the host of the URI

public host() : string|null
Return values
string|null

The host of the URI

init()

Initializes the URI object based on the url set on the object

public init() : void

initializeWithUrl()

Initialize the URI class with a url passed via parameter.

public initializeWithUrl([string $url = '' ]) : $this

Used for testing purposes.

Parameters
$url : string = ''

the URL to use in the class

Return values
$this

initializeWithUrlAndRootPath()

Initialize the URI class by providing url and root_path arguments

public initializeWithUrlAndRootPath(string $url, string $root_path) : $this
Parameters
$url : string
$root_path : string
Return values
$this

ip()

Return the IP address of the current user

public static ip() : string
Return values
string

ip address

isExternal()

Is this an external URL? if it starts with `http` then yes, else false

public static isExternal(string $url) : bool
Parameters
$url : string

the URL in question

Return values
bool

is eternal state

isValidExtension()

Check if this is a valid Grav extension

public isValidExtension(string|null $extension) : bool
Parameters
$extension : string|null
Return values
bool

isValidUrl()

Is the passed in URL a valid URL?

public static isValidUrl(string $url) : bool
Parameters
$url : string
Return values
bool

method()

public method() : string
Return values
string

param()

Get URI parameter.

public param(string $id[, string|false|null $default = false ]) : string|false|null
Parameters
$id : string
$default : string|false|null = false
Return values
string|false|null

params()

Return all or a single query parameter as a URI compatible string.

public params([string|null $id = null ][, bool $array = false ]) : null|string|array<string|int, mixed>
Parameters
$id : string|null = null

Optional parameter name.

$array : bool = false

return the array format or not

Return values
null|string|array<string|int, mixed>

paramsRegex()

Calculate the parameter regex based on the param_sep setting

public static paramsRegex() : string
Return values
string

parseUrl()

public static parseUrl(string $url) : array<string|int, mixed>|false
Parameters
$url : string
Return values
array<string|int, mixed>|false

password()

Return password

public password() : string|null
Return values
string|null

path()

Return the Path

public path() : string
Return values
string

The path of the URI

paths()

Return URI path.

public paths([int|null $id = null ]) : string|array<string|int, string>
Parameters
$id : int|null = null
Return values
string|array<string|int, string>

port()

Return the port number if it can be figured out

public port([bool $raw = false ]) : int|null
Parameters
$raw : bool = false
Return values
int|null

post()

Get post from either $_POST or JSON response object By default returns all data, or can return a single item

public post([string|null $element = null ][, string|null $filter_type = null ]) : array<string|int, mixed>|null
Parameters
$element : string|null = null
$filter_type : string|null = null
Return values
array<string|int, mixed>|null

query()

Return full query string or a single query attribute.

public query([string|null $id = null ][, bool $raw = false ]) : string|array<string|int, mixed>
Parameters
$id : string|null = null

Optional attribute. Get a single query attribute if set

$raw : bool = false

If true and $id is not set, return the full query array. Otherwise return the query string

Return values
string|array<string|int, mixed>

Returns an array if $id = null and $raw = true

referrer()

Return relative path to the referrer defaulting to current or given page.

public referrer([string|null $default = null ][, string|null $attributes = null ][, bool $withoutBaseRoute = false ]) : string

You should set the third parameter to true for redirects as long as you came from the same sub-site and language.

Parameters
$default : string|null = null
$attributes : string|null = null
$withoutBaseRoute : bool = false
Return values
string

rootUrl()

Return root URL to the site.

public rootUrl([bool $include_host = false ]) : string
Parameters
$include_host : bool = false

Include hostname.

Return values
string

route()

Return route to the current URI. By default route doesn't include base path.

public route([bool $absolute = false ][, bool $domain = false ]) : string
Parameters
$absolute : bool = false

True to include full path.

$domain : bool = false

True to include domain. Works only if first parameter is also true.

Return values
string

scheme()

Return the scheme of the URI

public scheme([bool|null $raw = false ]) : string
Parameters
$raw : bool|null = false
Return values
string

The scheme of the URI

setUriProperties()

Allow overriding of any element (be careful!)

public setUriProperties(array<string|int, mixed> $data) : Uri
Parameters
$data : array<string|int, mixed>
Return values
Uri

toArray()

public toArray([bool $full = false ]) : array<string|int, mixed>
Parameters
$full : bool = false
Return values
array<string|int, mixed>

toOriginalString()

public toOriginalString() : string
Return values
string

uri()

Return the full uri

public uri([bool $include_root = true ]) : string
Parameters
$include_root : bool = true
Return values
string

url()

Return URL.

public url([bool $include_host = false ]) : string
Parameters
$include_host : bool = false

Include hostname.

Return values
string

user()

Return user

public user() : string|null
Return values
string|null

validateHostname()

Validate a hostname

public validateHostname(string $hostname) : bool
Parameters
$hostname : string

The hostname

Return values
bool

createFromEnvironment()

protected createFromEnvironment(array<string|int, mixed> $env) : void
Parameters
$env : array<string|int, mixed>

createFromString()

protected createFromString(string $url) : mixed
Parameters
$url : string

hasStandardPort()

Does this Uri use a standard port?

protected hasStandardPort() : bool
Return values
bool

reset()

protected reset() : void

buildBaseUrl()

Get the base URI with port if needed

private buildBaseUrl() : string
Return values
string

buildEnvironment()

private buildEnvironment() : string
Return values
string

buildRootPath()

Get the Grav Root Path

private buildRootPath() : string
Return values
string

processParams()

Process any params based in this URL, supports any valid delimiter

private processParams(string $uri[, string $delimiter = ':' ]) : string
Parameters
$uri : string
$delimiter : string = ':'
Return values
string

        
On this page

Search results