Library
Class

Library\Helper\Url

class Url

URL common methods

For convenience, the best practice is to use:

use Library\Helper\Url as UrlHelper;

Methods

static string getRequestUrl(bool $entities = false, bool $base = false, bool $no_file = false, bool $no_rewrite = false)

Get the current browser/server URL

static string getHttpProtocol()

Get the current 'http' or 'https' protocol

static array parse(string $url)

Parse an URL and returns its composition as an array, with the URI query if so

static string resolvePath(string $url = null, boolean $realpath = false)

Returns the URL with paths cleaned (./ and ../ are resolved)

static string resolveHttp(string $url = null)

Returns an URL with leading 'http://' if it was absent Inspired by SPIP http://spip.net

static string getAbsoluteUrl(string $url = null)

Returns if possible an absolute URL in the current system

static string url(string/array/null $param = null, string/null $value = null, string/null $url = null)

Global URL builder

static string/array getParameter(string/bool $param = false, string/null $url = false)

Get the value of an URL parameter

static string/array setParameter(string/bool $var = '', string/false $val = false, string/false $url = false, bool $rebuild = true)

Set the value of an URL parameter

static string build(array $url_components = null, string/array/boolean $not_toput = null)

Rebuild a full URL string from an array of elements

static bool isUrl(string $url = null, array $protocols = array('http', 'https', 'ftp'), bool/string $localhost = false)

Validate an URL (without a hash content)

static bool isEmail(string $email = null)

Validate an email address

Details

at line 48
static public string getRequestUrl(bool $entities = false, bool $base = false, bool $no_file = false, bool $no_rewrite = false)

Get the current browser/server URL

Parameters

bool $entities Protect '&' entities parsing them in '&' ? (default is FALSE)
bool $base Do you want just the base URL, without any URI (default is FALSE)
bool $no_file Do you want just the base URL path, without the input file and any URI (default is FALSE)
bool $no_rewrite Do you want the real file pointed by the URL in case of URL rewriting (default is FALSE)

Return Value

string

at line 89
static public string getHttpProtocol()

Get the current 'http' or 'https' protocol

Return Value

string The current protocol

at line 103
static public array parse(string $url)

Parse an URL and returns its composition as an array, with the URI query if so

Parameters

string $url The URL to parse (required)

Return Value

array An array of the URL components

at line 124
static public string resolvePath(string $url = null, boolean $realpath = false)

Returns the URL with paths cleaned (./ and ../ are resolved)

Inspired by SPIP http://spip.net

Parameters

string $url The URL to resolve
boolean $realpath Returns the real path of the path (default is false)

Return Value

string The resolved path, or real path if so

at line 151
static public string resolveHttp(string $url = null)

Returns an URL with leading 'http://' if it was absent Inspired by SPIP http://spip.net

Parameters

string $url The URL to resolve

Return Value

string The resolved URL

at line 169
static public string getAbsoluteUrl(string $url = null)

Returns if possible an absolute URL in the current system

Parameters

string $url The URL to resolve

Return Value

string The resolved URL

at line 191
static public string url(string/array/null $param = null, string/null $value = null, string/null $url = null)

Global URL builder

Parameters

string/array/null $param A parameter to set, or an array like param => value to set in URL
string/null $value The value of the $param argument (if it is a string)
string/null $url The URL to work on (self::getRequestUrl() by default)

Return Value

string The final rebuilt URL

at line 226
static public string/array getParameter(string/bool $param = false, string/null $url = false)

Get the value of an URL parameter

Parameters

string/bool $param A parameter to get, or false to get the global parameters array
string/null $url The URL to work on (self::getRequestUrl() by default)

Return Value

string/array The parameter value or the global array of parameters

at line 259
static public string/array setParameter(string/bool $var = '', string/false $val = false, string/false $url = false, bool $rebuild = true)

Set the value of an URL parameter

Parameters

string/bool $var A parameter to get, or false to get the global parameters array
string/false $val The value of the $param argument (if null, the argument is stripped)
string/false $url The URL to work on (self::getRequestUrl() by default)
bool $rebuild Return a rebuilt URL (true by dfault - if false, the URL components array is returned)

Return Value

string/array The final URL

at line 281
static public string build(array $url_components = null, string/array/boolean $not_toput = null)

Rebuild a full URL string from an array of elements

Parameters

array $url_components The array of the URL components:: scheme, user, pass, host, port, path, params, hash
string/array/boolean $not_toput The name of an array of elements to not include

Return Value

string The final URL as a string

at line 314
static public bool isUrl(string $url = null, array $protocols = array('http', 'https', 'ftp'), bool/string $localhost = false)

Validate an URL (without a hash content)

Parameters

string $url The string to validate
array $protocols Table of Internet protocols to verify (by default : 'http', 'https', 'ftp')
bool/string $localhost Is it locally (useful for validating 'http://localhost ...') (FALSE by default) - You can specify a string to check

Return Value

bool Returns true if this is a URL in one of the specified protocols

at line 336
static public bool isEmail(string $email = null)

Validate an email address

Parameters

string $email The string to validate

Return Value

bool Returns true if this is an email