PHP Class Base

Mostra file Open project: bcosca/fatfree Class Usage Examples

Public Methods

Method Description
__call ( $key, $args ) : mixed Call function identified by hive key
__construct ( ) ! Bootstrap
__get ( $key ) : mixed Alias for offsetget()
__isset ( $key ) : mixed Alias for offsetexists()
__set ( $key, $val ) : mixed Alias for offsetset()
__unset ( $key ) : mixed Alias for offsetunset()
abort ( ) Disconnect HTTP client
agent ( ) : string Return HTTP user agent
ajax ( ) : boolean Return TRUE if XMLHttpRequest detected
alias ( $name, $params = [], $query = NULL ) : string Assemble url from alias name
base64 ( $data, $mime ) : string Return Base64-encoded equivalent
blacklisted ( $ip ) : boolean Return TRUE if IPv4 address exists in DNSBL
build ( $url, $args = [] ) : string Replace tokenized URL with available token values
call ( $func, $args = NULL, $hooks = '' ) : mixed | FALSE Execute callback/hooks (supports 'class->method' format)
camelcase ( $str ) : string Convert snakecase string to camelcase
chain ( $funcs, $args = NULL ) : array Execute specified callbacks in succession; Apply same arguments to all callbacks
checked ( $key ) : boolean Return TRUE if hive variable is 'on'
clean ( $arg, $tags = NULL ) : mixed Remove HTML tags (except those enumerated) and non-printable characters to mitigate XSS/code injection attacks
clear ( $key ) : null Unset hive key
compile ( $str ) : string Convert JS-style token to PHP expression
concat ( $key, $val ) : string Concatenate string to hive string variable
config ( $file, $allow = FALSE ) : object Configure framework according to .ini-style file settings; If optional 2nd arg is provided, template strings are interpreted
constants ( $class, $prefix = '' ) : array Convert class constants to array
copy ( $src, $dst ) : mixed Copy contents of hive variable to another
csv ( array $args ) : string Flatten array values and return as CSV string
decode ( $str ) : string Convert HTML entities back to characters
devoid ( $key, &$val = NULL ) : boolean Return TRUE if hive key is empty and not cached
dump ( $expr ) : null Dump expression with syntax highlighting
encode ( $str ) : string Convert special characters to HTML entities
error ( $code, $text = '', array $trace = NULL, $level ) : null Log error; Execute ONERROR handler if defined, else display default error page (HTML for synchronous requests, JSON string for AJAX requests)
exists ( $key, &$val = NULL ) : boolean Return TRUE if hive key is set (or return timestamp and TTL if cached)
expire ( $secs ) : null Send cache metadata to HTTP client
extend ( $key, $src, $keep = FALSE ) : array Extend hive array variable with default values from $src
extract ( $arr, $prefix ) : array Extract values of array whose keys start with the given prefix
fixslashes ( $str ) : string Convert backslashes to slashes
flip ( $key ) : array Swap keys and values of hive array variable
format ( ) : string Return locale-aware formatted string
get ( $key, $args = NULL ) : mixed Retrieve contents of hive key
grab ( $func, $args = NULL ) : string | array Grab the real route handler behind the string expression
hash ( $str ) : string Generate 64bit/base36 hash
highlight ( $text ) : string Apply syntax highlighting
hive ( ) : array Publish hive contents
ip ( ) : string Sniff IP address
language ( $code ) : string Assign/auto-detect language
lexicon ( $path, $ttl ) : array Return lexicon entries
map ( $url, $class, $ttl, $kbps ) : null Provide ReST interface by mapping HTTP verb to class method
mask ( $pattern, $url = NULL ) Applies the specified URL mask and returns parameterized matches
merge ( $key, $src, $keep = FALSE ) : array Merge array with hive array variable
mock ( $pattern, array $args = NULL, array $headers = NULL, $body = NULL ) : mixed Mock HTTP request
mset ( array $vars, $prefix = '', $ttl ) : null Multi-variable assignment using associative array
mutex ( $id, $func, $args = NULL ) : mixed Create mutex, invoke callback then drop ownership when done
offsetexists ( $key ) : mixed Convenience method for checking hive key
offsetget ( $key ) : mixed Convenience method for retrieving hive value
offsetset ( $key, $val ) : mixed Convenience method for assigning hive value
offsetunset ( $key ) : null Convenience method for removing hive key
parse ( $str ) : array Parse string containing key-value pairs
pop ( $key ) : mixed Remove last element of hive array variable
push ( $key, $val ) : mixed Add element to the end of hive array variable
read ( $file, $lf = FALSE ) : string Read file (with option to apply Unix LF as standard line ending)
recursive ( $arg, $func, $stack = [] ) : mixed Invoke callback recursively for all data types
redirect ( $pattern, $url, $permanent = TRUE ) : null Redirect a route to another URL
ref ( $key, $add = TRUE, &$var = NULL ) : mixed Get hive key reference/contents; Add non-existent hive keys, array elements, and object properties by default
rel ( $url ) : string Return path (and query parameters) relative to the base directory
relay ( $funcs, $args = NULL ) : array Execute specified callbacks in succession; Relay result of previous callback as argument to the next callback
reroute ( $url = NULL, $permanent = FALSE ) : null Reroute to specified URI
route ( $pattern, $handler, $ttl, $kbps ) : null Bind handler to route pattern
run ( ) : mixed Match routes against incoming URI
scrub ( &$var, $tags = NULL ) : mixed Similar to clean(), except that variable is passed by reference
serialize ( $arg ) : string Return string representation of PHP value
set ( $key, $val, $ttl ) : mixed Bind value to hive key
shift ( $key ) : mixed Remove first element of hive array variable
sign ( $num ) : integer Return -1 if specified number is negative, 0 if zero, or 1 if the number is positive
snakecase ( $str ) : string Convert camelcase string to snakecase
split ( $str, $noempty = TRUE ) : array Split comma-, semi-colon, or pipe-separated string
status ( $code ) : string Send HTTP status header; Return text equivalent of status code
stringify ( $arg, array $stack = NULL ) : string Convert PHP expression/value to compressed exportable string
sync ( $key ) : array Sync PHP global with corresponding hive key
trace ( array $trace = NULL, $format = TRUE ) : string | array Return filtered stack trace as a formatted string (or array)
unload ( $cwd ) Execute framework/application shutdown sequence
unserialize ( $arg ) : string Return PHP value derived from string
unshift ( $key, $val ) : mixed Add element to the beginning of hive array variable
until ( $func, $args = NULL, $timeout = 60 ) : mixed Loop until callback returns TRUE (for long polling)
visible ( $obj, $key ) : boolean Return TRUE if property has public visibility
write ( $file, $data, $append = FALSE ) : integer | FALSE Exclusive file write

Protected Methods

Method Description
autoload ( $class ) : mixed Namespace-aware class autoloader

Private Methods

Method Description
__clone ( ) ! Prohibit cloning
cut ( $key ) : array Return the parts of specified hive key

Method Details

__call() public method

Call function identified by hive key
public __call ( $key, $args ) : mixed
$key string
$args array
return mixed

__construct() public method

! Bootstrap
public __construct ( )

__get() public method

Alias for offsetget()
public __get ( $key ) : mixed
$key string
return mixed

__isset() public method

Alias for offsetexists()
public __isset ( $key ) : mixed
$key string
return mixed

__set() public method

Alias for offsetset()
public __set ( $key, $val ) : mixed
$key string
$val mixed
return mixed

__unset() public method

Alias for offsetunset()
public __unset ( $key ) : mixed
$key string
return mixed

abort() public method

Disconnect HTTP client
public abort ( )

agent() public method

Return HTTP user agent
public agent ( ) : string
return string

ajax() public method

Return TRUE if XMLHttpRequest detected
public ajax ( ) : boolean
return boolean

alias() public method

Assemble url from alias name
public alias ( $name, $params = [], $query = NULL ) : string
$name string
$params array|string
$query string|array
return string

autoload() protected method

Namespace-aware class autoloader
protected autoload ( $class ) : mixed
$class string
return mixed

base64() public method

Return Base64-encoded equivalent
public base64 ( $data, $mime ) : string
$data string
$mime string
return string

blacklisted() public method

Return TRUE if IPv4 address exists in DNSBL
public blacklisted ( $ip ) : boolean
$ip string
return boolean

build() public method

Replace tokenized URL with available token values
public build ( $url, $args = [] ) : string
$url array|string
$args array
return string

call() public method

Execute callback/hooks (supports 'class->method' format)
public call ( $func, $args = NULL, $hooks = '' ) : mixed | FALSE
$func callback
$args mixed
$hooks string
return mixed | FALSE

camelcase() public method

Convert snakecase string to camelcase
public camelcase ( $str ) : string
$str string
return string

chain() public method

Execute specified callbacks in succession; Apply same arguments to all callbacks
public chain ( $funcs, $args = NULL ) : array
$funcs array|string
$args mixed
return array

checked() public method

Return TRUE if hive variable is 'on'
public checked ( $key ) : boolean
$key string
return boolean

clean() public method

Remove HTML tags (except those enumerated) and non-printable characters to mitigate XSS/code injection attacks
public clean ( $arg, $tags = NULL ) : mixed
$arg mixed
$tags string
return mixed

clear() public method

Unset hive key
public clear ( $key ) : null
$key string
return null

compile() public method

Convert JS-style token to PHP expression
public compile ( $str ) : string
$str string
return string

concat() public method

Concatenate string to hive string variable
public concat ( $key, $val ) : string
$key string
$val string
return string

config() public method

Configure framework according to .ini-style file settings; If optional 2nd arg is provided, template strings are interpreted
public config ( $file, $allow = FALSE ) : object
$file string
$allow bool
return object

constants() public method

Convert class constants to array
public constants ( $class, $prefix = '' ) : array
$class object|string
$prefix string
return array

copy() public method

Copy contents of hive variable to another
public copy ( $src, $dst ) : mixed
$src string
$dst string
return mixed

csv() public method

Flatten array values and return as CSV string
public csv ( array $args ) : string
$args array array
return string

decode() public method

Convert HTML entities back to characters
public decode ( $str ) : string
$str string
return string

devoid() public method

Return TRUE if hive key is empty and not cached
public devoid ( $key, &$val = NULL ) : boolean
$key string
$val mixed
return boolean

dump() public method

Dump expression with syntax highlighting
public dump ( $expr ) : null
$expr mixed
return null

encode() public method

Convert special characters to HTML entities
public encode ( $str ) : string
$str string
return string

error() public method

Log error; Execute ONERROR handler if defined, else display default error page (HTML for synchronous requests, JSON string for AJAX requests)
public error ( $code, $text = '', array $trace = NULL, $level ) : null
$code int
$text string
$trace array array
$level int
return null

exists() public method

Return TRUE if hive key is set (or return timestamp and TTL if cached)
public exists ( $key, &$val = NULL ) : boolean
$key string
$val mixed
return boolean

expire() public method

Send cache metadata to HTTP client
public expire ( $secs ) : null
$secs int
return null

extend() public method

Extend hive array variable with default values from $src
public extend ( $key, $src, $keep = FALSE ) : array
$key string
$src string|array
$keep bool
return array

extract() public method

Extract values of array whose keys start with the given prefix
public extract ( $arr, $prefix ) : array
$arr array
$prefix string
return array

fixslashes() public method

Convert backslashes to slashes
public fixslashes ( $str ) : string
$str string
return string

flip() public method

Swap keys and values of hive array variable
public flip ( $key ) : array
$key string
return array

format() public method

Return locale-aware formatted string
public format ( ) : string
return string

get() public method

Retrieve contents of hive key
public get ( $key, $args = NULL ) : mixed
$key string
$args string|array
return mixed

grab() public method

Grab the real route handler behind the string expression
public grab ( $func, $args = NULL ) : string | array
$func string
$args array
return string | array

hash() public method

Generate 64bit/base36 hash
public hash ( $str ) : string
$str
return string

highlight() public method

Apply syntax highlighting
public highlight ( $text ) : string
$text string
return string

hive() public method

Publish hive contents
public hive ( ) : array
return array

ip() public method

Sniff IP address
public ip ( ) : string
return string

language() public method

Assign/auto-detect language
public language ( $code ) : string
$code string
return string

lexicon() public method

Return lexicon entries
public lexicon ( $path, $ttl ) : array
$path string
$ttl int
return array

map() public method

Provide ReST interface by mapping HTTP verb to class method
public map ( $url, $class, $ttl, $kbps ) : null
$url string
$class string|object
$ttl int
$kbps int
return null

mask() public method

Applies the specified URL mask and returns parameterized matches
public mask ( $pattern, $url = NULL )
$pattern string
$url string|NULL

merge() public method

Merge array with hive array variable
public merge ( $key, $src, $keep = FALSE ) : array
$key string
$src string|array
$keep bool
return array

mock() public method

Mock HTTP request
public mock ( $pattern, array $args = NULL, array $headers = NULL, $body = NULL ) : mixed
$pattern string
$args array array
$headers array array
$body string
return mixed

mset() public method

Multi-variable assignment using associative array
public mset ( array $vars, $prefix = '', $ttl ) : null
$vars array array
$prefix string
$ttl int
return null

mutex() public method

Create mutex, invoke callback then drop ownership when done
public mutex ( $id, $func, $args = NULL ) : mixed
$id string
$func callback
$args mixed
return mixed

offsetexists() public method

Convenience method for checking hive key
public offsetexists ( $key ) : mixed
$key string
return mixed

offsetget() public method

Convenience method for retrieving hive value
public offsetget ( $key ) : mixed
$key string
return mixed

offsetset() public method

Convenience method for assigning hive value
public offsetset ( $key, $val ) : mixed
$key string
$val scalar
return mixed

offsetunset() public method

Convenience method for removing hive key
public offsetunset ( $key ) : null
$key string
return null

parse() public method

Parse string containing key-value pairs
public parse ( $str ) : array
$str string
return array

pop() public method

Remove last element of hive array variable
public pop ( $key ) : mixed
$key string
return mixed

push() public method

Add element to the end of hive array variable
public push ( $key, $val ) : mixed
$key string
$val mixed
return mixed

read() public method

Read file (with option to apply Unix LF as standard line ending)
public read ( $file, $lf = FALSE ) : string
$file string
$lf bool
return string

recursive() public method

Invoke callback recursively for all data types
public recursive ( $arg, $func, $stack = [] ) : mixed
$arg mixed
$func callback
$stack array
return mixed

redirect() public method

Redirect a route to another URL
public redirect ( $pattern, $url, $permanent = TRUE ) : null
$pattern string|array
$url string
$permanent bool
return null

ref() public method

Get hive key reference/contents; Add non-existent hive keys, array elements, and object properties by default
public ref ( $key, $add = TRUE, &$var = NULL ) : mixed
$key string
$add bool
$var mixed
return mixed

rel() public method

Return path (and query parameters) relative to the base directory
public rel ( $url ) : string
$url string
return string

relay() public method

Execute specified callbacks in succession; Relay result of previous callback as argument to the next callback
public relay ( $funcs, $args = NULL ) : array
$funcs array|string
$args mixed
return array

reroute() public method

Reroute to specified URI
public reroute ( $url = NULL, $permanent = FALSE ) : null
$url array|string
$permanent bool
return null

route() public method

Bind handler to route pattern
public route ( $pattern, $handler, $ttl, $kbps ) : null
$pattern string|array
$handler callback
$ttl int
$kbps int
return null

run() public method

Match routes against incoming URI
public run ( ) : mixed
return mixed

scrub() public method

Similar to clean(), except that variable is passed by reference
public scrub ( &$var, $tags = NULL ) : mixed
$var mixed
$tags string
return mixed

serialize() public method

Return string representation of PHP value
public serialize ( $arg ) : string
$arg mixed
return string

set() public method

Bind value to hive key
public set ( $key, $val, $ttl ) : mixed
$key string
$val mixed
$ttl int
return mixed

shift() public method

Remove first element of hive array variable
public shift ( $key ) : mixed
$key string
return mixed

sign() public method

Return -1 if specified number is negative, 0 if zero, or 1 if the number is positive
public sign ( $num ) : integer
$num mixed
return integer

snakecase() public method

Convert camelcase string to snakecase
public snakecase ( $str ) : string
$str string
return string

split() public method

Split comma-, semi-colon, or pipe-separated string
public split ( $str, $noempty = TRUE ) : array
$str string
$noempty bool
return array

status() public method

Send HTTP status header; Return text equivalent of status code
public status ( $code ) : string
$code int
return string

stringify() public method

Convert PHP expression/value to compressed exportable string
public stringify ( $arg, array $stack = NULL ) : string
$arg mixed
$stack array array
return string

sync() public method

Sync PHP global with corresponding hive key
public sync ( $key ) : array
$key string
return array

trace() public method

Return filtered stack trace as a formatted string (or array)
public trace ( array $trace = NULL, $format = TRUE ) : string | array
$trace array array|NULL
$format bool
return string | array

unload() public method

Execute framework/application shutdown sequence
public unload ( $cwd )
$cwd string

unserialize() public method

Return PHP value derived from string
public unserialize ( $arg ) : string
$arg mixed
return string

unshift() public method

Add element to the beginning of hive array variable
public unshift ( $key, $val ) : mixed
$key string
$val mixed
return mixed

until() public method

Loop until callback returns TRUE (for long polling)
public until ( $func, $args = NULL, $timeout = 60 ) : mixed
$func callback
$args array
$timeout int
return mixed

visible() public method

Return TRUE if property has public visibility
public visible ( $obj, $key ) : boolean
$obj object
$key string
return boolean

write() public method

Exclusive file write
public write ( $file, $data, $append = FALSE ) : integer | FALSE
$file string
$data mixed
$append bool
return integer | FALSE