PHP Class Base

Afficher le fichier Open project: bcosca/fatfree Class Usage Examples

Méthodes publiques

Méthode 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

Méthodes protégées

Méthode Description
autoload ( $class ) : mixed Namespace-aware class autoloader

Private Methods

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

Method Details

__call() public méthode

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

__construct() public méthode

! Bootstrap
public __construct ( )

__get() public méthode

Alias for offsetget()
public __get ( $key ) : mixed
$key string
Résultat mixed

__isset() public méthode

Alias for offsetexists()
public __isset ( $key ) : mixed
$key string
Résultat mixed

__set() public méthode

Alias for offsetset()
public __set ( $key, $val ) : mixed
$key string
$val mixed
Résultat mixed

__unset() public méthode

Alias for offsetunset()
public __unset ( $key ) : mixed
$key string
Résultat mixed

abort() public méthode

Disconnect HTTP client
public abort ( )

agent() public méthode

Return HTTP user agent
public agent ( ) : string
Résultat string

ajax() public méthode

Return TRUE if XMLHttpRequest detected
public ajax ( ) : boolean
Résultat boolean

alias() public méthode

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

autoload() protected méthode

Namespace-aware class autoloader
protected autoload ( $class ) : mixed
$class string
Résultat mixed

base64() public méthode

Return Base64-encoded equivalent
public base64 ( $data, $mime ) : string
$data string
$mime string
Résultat string

blacklisted() public méthode

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

build() public méthode

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

call() public méthode

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

camelcase() public méthode

Convert snakecase string to camelcase
public camelcase ( $str ) : string
$str string
Résultat string

chain() public méthode

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

checked() public méthode

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

clean() public méthode

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
Résultat mixed

clear() public méthode

Unset hive key
public clear ( $key ) : null
$key string
Résultat null

compile() public méthode

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

concat() public méthode

Concatenate string to hive string variable
public concat ( $key, $val ) : string
$key string
$val string
Résultat string

config() public méthode

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
Résultat object

constants() public méthode

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

copy() public méthode

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

csv() public méthode

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

decode() public méthode

Convert HTML entities back to characters
public decode ( $str ) : string
$str string
Résultat string

devoid() public méthode

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

dump() public méthode

Dump expression with syntax highlighting
public dump ( $expr ) : null
$expr mixed
Résultat null

encode() public méthode

Convert special characters to HTML entities
public encode ( $str ) : string
$str string
Résultat string

error() public méthode

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
Résultat null

exists() public méthode

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

expire() public méthode

Send cache metadata to HTTP client
public expire ( $secs ) : null
$secs int
Résultat null

extend() public méthode

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

extract() public méthode

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

fixslashes() public méthode

Convert backslashes to slashes
public fixslashes ( $str ) : string
$str string
Résultat string

flip() public méthode

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

format() public méthode

Return locale-aware formatted string
public format ( ) : string
Résultat string

get() public méthode

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

grab() public méthode

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

hash() public méthode

Generate 64bit/base36 hash
public hash ( $str ) : string
$str
Résultat string

highlight() public méthode

Apply syntax highlighting
public highlight ( $text ) : string
$text string
Résultat string

hive() public méthode

Publish hive contents
public hive ( ) : array
Résultat array

ip() public méthode

Sniff IP address
public ip ( ) : string
Résultat string

language() public méthode

Assign/auto-detect language
public language ( $code ) : string
$code string
Résultat string

lexicon() public méthode

Return lexicon entries
public lexicon ( $path, $ttl ) : array
$path string
$ttl int
Résultat array

map() public méthode

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
Résultat null

mask() public méthode

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

merge() public méthode

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

mock() public méthode

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
Résultat mixed

mset() public méthode

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

mutex() public méthode

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

offsetexists() public méthode

Convenience method for checking hive key
public offsetexists ( $key ) : mixed
$key string
Résultat mixed

offsetget() public méthode

Convenience method for retrieving hive value
public offsetget ( $key ) : mixed
$key string
Résultat mixed

offsetset() public méthode

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

offsetunset() public méthode

Convenience method for removing hive key
public offsetunset ( $key ) : null
$key string
Résultat null

parse() public méthode

Parse string containing key-value pairs
public parse ( $str ) : array
$str string
Résultat array

pop() public méthode

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

push() public méthode

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

read() public méthode

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

recursive() public méthode

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

redirect() public méthode

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

ref() public méthode

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
Résultat mixed

rel() public méthode

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

relay() public méthode

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
Résultat array

reroute() public méthode

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

route() public méthode

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

run() public méthode

Match routes against incoming URI
public run ( ) : mixed
Résultat mixed

scrub() public méthode

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

serialize() public méthode

Return string representation of PHP value
public serialize ( $arg ) : string
$arg mixed
Résultat string

set() public méthode

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

shift() public méthode

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

sign() public méthode

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

snakecase() public méthode

Convert camelcase string to snakecase
public snakecase ( $str ) : string
$str string
Résultat string

split() public méthode

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

status() public méthode

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

stringify() public méthode

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

sync() public méthode

Sync PHP global with corresponding hive key
public sync ( $key ) : array
$key string
Résultat array

trace() public méthode

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
Résultat string | array

unload() public méthode

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

unserialize() public méthode

Return PHP value derived from string
public unserialize ( $arg ) : string
$arg mixed
Résultat string

unshift() public méthode

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

until() public méthode

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

visible() public méthode

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

write() public méthode

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