\Nano4\PluginsURL

Summary

Methods
Properties
Constants
redirect()
site_url()
request_uri()
current_url()
script_name()
download()
encodeArray()
decodeArray()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
No private properties found
N/A

Methods

redirect()

redirect(String  $url, Array  $opts = array()) 

Redirect to another page. This ends the current PHP process.

Parameters

String $url

The URL to redirect to.

Array $opts

Options:

'relative' If True, the passed URL is actually a path. 'full' If True, the passed URL is a full URL.

The above two options are mutually exclusive and do the exact opposite. If neither option is set, the URL will be checked for the existence of a colon (':') character, which will determine if it is assumed to be a full URL or a relative URL.

If relative is determiend to be true, the following options are added:

'ssl' If True, force the use of SSL on the site URL. 'port' If set, use this port on the site URL.

See the site_url() function for details on how 'ssl' and 'port' work.

site_url()

site_url(Mixed  $ssl = Null, Mixed  $port = Null) 

Return our website's base URL.

Parameters

Mixed $ssl

Force the use of SSL?

Mixed $port

Force a specific port?

If $ssl is True, we force SSL, if it is False, we force regular HTTP. If it is Null (default) we auto-detect the current protocol and use that.

If $port is set to an integer, we force that as the port. If it is Null (default) we determine the appropriate port to use.

request_uri()

request_uri() 

Return our current request URI.

current_url()

current_url() 

Return the current URL (full URL path)

script_name()

script_name(Bool  $full = False) 

Return the name of the current script.

Parameters

Bool $full

If set to True, return the full path.

download()

download(Mixed  $file, Array  $opts = array()) 

Send a file download to the client browser.

This ends the current PHP process.

Parameters

Mixed $file

See below for possibly values.

Array $opts

See below for a list of options.

The $file variable will be one of two values, depending on options. If the 'content' option exists, the $file variable will be used as the filename for the download. Otherwise, the $file variable is the path name on the server to the file we are sending the client.

Options:

'type' If specified, will be used as the MIME type, see below. 'content' Use this as the file content, see below. 'filename' If not using content, this sets the filename, see below.

The 'type' option if set determines the MIME type. If there is a slash character, it is assumed to be a full MIME type declaration. If there isn't, we assume it's a query for Nano4\Utils\File\Types, and look up the MIME type from there. If it isn't specified at all, we use finfo to look up the MIME type based on the file content.

If the 'content' option is set, then it will be used as the content of the file. It alters the meaning of the $file parameter as mentioned above. If it is not set, then the $file parameter must point to a valid file on the server.

If the 'filename' option is set (only valid if 'content' is not set), then its value will be used as the name of the file being sent to the client. If it is not set, then the basename of the existing file on the server will be used (as specified in the $file parameter.)

encodeArray()

encodeArray(  $object, Bool  $serialize = False) 

Transform a PHP array/object into a URL-safe string.

Parameters

$object
Bool $serialize

If set to True, we use serialize().

The format of the string is simple:

We encode the input, then we Base64 encode the data string. Finally we perform the following character substitutions:

'+' becomes '-' '/' becomes '_' '=' becomes '~'

The data encoding scheme depends on the $serialize parameter:

If $serialize is False (default) then we use JSON encoding, in which case the input MUST be a PHP Array, and all members of the PHP array MUST be able to be handled by the json_encode() function.

If $serialize is True, we use the serialize() function. This allows for more types of objects to be encoded, but also means that you will only be able to use the URL string with PHP.

decodeArray()

decodeArray(  $string, Bool  $serialize = False, Bool  $assoc = True) 

Decode a string in encodeArray() format.

Parameters

$string
Bool $serialize

Did the input string use serialize?

Bool $assoc

JSON objects will become PHP arrays (True)

The $serialize parameter MUST reflect the same value as was used in the encodeArray() call that generated the original string. It defaults to False (the same default as encodeArray().)

The $assoc parameter (default True) is only used by the JSON decoder, and is passed along to the json_decode() function to determine if JSON Objects will be decoded as PHP Objects or PHP Arrays.