PHP Class Piwik\UrlHelper

Datei anzeigen Open project: piwik/piwik Class Usage Examples

Public Methods

Method Description
getArrayFromQueryString ( string $urlQuery ) : array Returns a URL query string as an array.
getHostFromUrl ( $url )
getLossyUrl ( string $url ) : string Reduce URL to more minimal form. 2 letter country codes are replaced by '{}', while other parts are simply removed.
getParameterFromQueryString ( string $urlQuery, string $parameter ) : string | null Returns the value of a single query parameter from the supplied query string.
getParseUrlReverse ( array $parsed ) : false | string Returns a URL created from the result of the parse_url function.
getPathAndQueryFromUrl ( string $url ) : string Returns the path and query string of a URL.
getQueryFromUrl ( string $url, array $additionalParamsToAdd = [] ) : string Returns the query part from any valid url and adds additional parameters to the query part if needed.
getQueryStringWithExcludedParameters ( $queryParameters, $parametersToExclude ) : string Converts an array of query parameter name/value mappings into a query string.
isLookLikeUrl ( string $url ) : boolean Returns true if the string passed may be a URL ie. it starts with protocol://.

Protected Methods

Method Description
in_array_matches_regex ( $test, $patterns ) : true Checks if a string matches/is equal to one of the patterns/strings.

Method Details

getArrayFromQueryString() public static method

Returns a URL query string as an array.
public static getArrayFromQueryString ( string $urlQuery ) : array
$urlQuery string The query string, eg, `'?param1=value1¶m2=value2'`.
return array eg, `array('param1' => 'value1', 'param2' => 'value2')`

getHostFromUrl() public static method

public static getHostFromUrl ( $url )

getLossyUrl() public static method

Examples: www.example.com -> example.com search.example.com -> example.com m.example.com -> example.com de.example.com -> }.example.com example.de -> example.} example.co.uk -> example.}
public static getLossyUrl ( string $url ) : string
$url string
return string

getParameterFromQueryString() public static method

Returns the value of a single query parameter from the supplied query string.
public static getParameterFromQueryString ( string $urlQuery, string $parameter ) : string | null
$urlQuery string The query string.
$parameter string The query parameter name to return.
return string | null Parameter value if found (can be the empty string!), null if not found.

getParseUrlReverse() public static method

Copied from the PHP comments at http://php.net/parse_url.
public static getParseUrlReverse ( array $parsed ) : false | string
$parsed array Result of [parse_url](http://php.net/manual/en/function.parse-url.php).
return false | string The URL or `false` if `$parsed` isn't an array.

getPathAndQueryFromUrl() public static method

Returns the path and query string of a URL.
public static getPathAndQueryFromUrl ( string $url ) : string
$url string The URL.
return string eg, `/test/index.php?module=CoreHome` if `$url` is `http://piwik.org/test/index.php?module=CoreHome`.

getQueryFromUrl() public static method

Returns the query part from any valid url and adds additional parameters to the query part if needed.
public static getQueryFromUrl ( string $url, array $additionalParamsToAdd = [] ) : string
$url string Any url eg `"http://example.com/piwik/?foo=bar"`
$additionalParamsToAdd array If not empty the given parameters will be added to the query.
return string eg. `"foo=bar&foo2=bar2"`

getQueryStringWithExcludedParameters() public static method

Parameters that are in $parametersToExclude will not appear in the result.
public static getQueryStringWithExcludedParameters ( $queryParameters, $parametersToExclude ) : string
$queryParameters Array of query parameters, eg, `array('site' => '0', 'date' => '2012-01-01')`.
$parametersToExclude Array of query parameter names that shouldn't be in the result query string, eg, `array('date', 'period')`.
return string A query string, eg, `"?site=0"`.

in_array_matches_regex() protected static method

Checks if a string matches/is equal to one of the patterns/strings.
protected static in_array_matches_regex ( $test, $patterns ) : true
$test String to test.
$patterns Array of strings or regexs.
return true if $test matches or is equal to one of the regex/string in $patterns, false otherwise.

isLookLikeUrl() public static method

We don't need a precise test here because the value comes from the website tracked source code and the URLs may look very strange.
public static isLookLikeUrl ( string $url ) : boolean
$url string
return boolean