RequestUrl

This class implements a part the "IRequest" for getting info about the request URLs and paths, thought separated from the "Request" class to make maintenance easier.
Source
RequestUrl.php

Static Methods

joinUrl

string RequestUrl::joinUrl(array url)

Join parts of a URL into a string.

Arguments

    url (array)
    Url parts
    {
        string       protocol : URL protocol e.g. "http" or "https",
        string       scheme :   URL protocol e.g. "http" or "https",
        string       user :     user-name,
        string       pass :     user-password,
        string       host :     URL host,
        string       port :     port,
        string|array path :     URL path or paths or list of paths,
        string|array query :    query-string or params as {key: value},
        string       fragment : URL fragment part,
    }
    

Returns

string
URL

queryString

string|array RequestUrl::queryString(string key=null)

Get query string parameter(s) of current URL.

Arguments

    key=null (string)
    string=return the value for the key, null=return an array of all parameters

Returns

string|array
Query string parameters(s), null if key not exists

queryStringCount

int RequestUrl::queryStringCount()

Get number of the query string parameters in current URL.

Returns

int
Number of the query string parameters in current URL

queryStrings

string RequestUrl::queryStrings(string glue='&')

Get the query string parameters as a string.

Arguments

    glue='&' (string)
    Glue between the "key=value"s

Returns

string
A string of the query string parameters

toQueryString

string RequestUrl::toQueryString(string glue='&')

Turn an array into a URL encoded query string.

Arguments

    glue='&' (string)
    Glue between the "key=value"s

Returns

string
A string of the query string parameters

Methods

__construct

RequestUrl $obj = new RequestUrl(string pathKey=null)

Identifies the URL paths, this paths are crucial for the URL to factory mappings.

Arguments

    pathKey=null (string)
    The $_GET key which contains URL path when set in the web-server rewrite rules. e.g. Apache: "RewriteRule ^(.*)$ start.php?q=$1 [L,QSA]" pathKey="q". null=use the real URL for getting paths

Returns

void

baseUrl

string $obj->baseUrl()

Get base URL. In an Artaengine App the base URL can be obtained from the "BASE_URL" too.

Returns

string
Base URL (without query string)

currentUrl

string $obj->currentUrl()

Get current URL.

Returns

string
Current URL (without query string)

getRealPaths

string $obj->getRealPaths()

This is normally the same as paths, unless on local. e.g. if "test" is a real directory then for URL "http://localhost/test/path1/path2" the real path is "test/path1/path2" but the path is "path1/path2".

Returns

string
Server URL

getServerUrl

string $obj->getServerUrl()

This is normally the same as base URL, unless on local. e.g. if "test" is a real directory then for URL "http://localhost/test" the server URL is "http://localhost/" but the base URL is "http://localhost/test".

Returns

string
Server URL

isRoot

void $obj->isRoot()

Is current URL root (has no path) or in other words is current URL = base URL.

Returns

void

makeRelativeUrl

string $obj->makeRelativeUrl(string newPath=null, string path='base')

Create URLs relative to the base URL or current URL (query string not included). The new path can be glued to "base"(base URL) or "current"(current URL).

Arguments

    newPath=null (string)
    The new relative path
    path='base' (string)
    Can be either "base" or "current"

Returns

string
The new URL

path

string|array $obj->path(int i=null)

Get path(s) of current URL.

Arguments

    i=null (int)
    int=return the i'th path (zero based), null=return an array of all paths

Returns

string|array
URL path(s), null if index not exists

pathCount

int $obj->pathCount()

Get the number of paths inside current URL.

Returns

int
Number of paths

paths

string $obj->paths()

Get all paths of current URL as string.

Returns

string
URL paths