TIP
Index
- Introduction
- Methods
- getOS {{() : 'unix'|'windows'|'os2'}}
- arrayDefault {{(&$array, $key, $value)}}
- getOption {{($type, $option, [$required]) : mixed|null}}
- requiredOption {{(&$options, $option, [$fallback])}}
- setLocaleId {{($locale) : boolean}}
- getLocaleId {{([$separator]) : string}}
- getLocale {{($id, $prefix, [$context], [$cached]) : string|null}}
- startSession {{()}}
- extendedTrim {{($str) : The}}
- deepAddSlashes {{($value) : array|string}}
- deepStripSlashes {{($value) : array|string}}
- deepImplode {{($pieces, [$glue]) : string}}
- doubleExplode {{($item_separator, $pair_separator, $buffer) : array|null}}
- pickElement {{($keys, &$source, [$glue]) : string|null}}
- getGet {{($id, $type) : mixed|null}}
- getPost {{($id, $type) : mixed|null}}
- getGetOrPost {{($id, $type) : mixed|null}}
- getCookie {{($id, $type) : mixed|null}}
- getTimestamp {{($date, $format) : int|null}}
- formatDate {{($format, [$input], [$input_format]) : mixed|null}}
- log {{($severity, $message)}}
- warning {{($message)}}
- error {{($message)}}
- fatal {{($message)}}
- notifyError {{([$id]) : bool}}
- notifyWarning {{([$id]) : bool}}
- notifyInfo {{([$id]) : bool}}
- removeDir {{($dir, [$self_remove])}}
- buildPath {{(}} … {{) : string}}
- buildLogicPath {{(}} … {{) : string}}
- buildTemplatePath {{(}} … {{) : string}}
- buildFallbackPath {{(}} … {{) : string}}
- buildDataPath {{(}} … {{) : string}}
- buildCachePath {{(}} … {{) : string}}
- getRoot {{() : string}}
- getHome {{() : string}}
- buildUri {{(}} … {{) : string}}
- buildDataUri {{(}} … {{) : string}}
- buildTemplateUri {{(}} … {{) : string}}
- buildFallbackUri {{(}} … {{) : string}}
- buildActionUri {{($module, $action, [$id], [$args]) : string}}
- buildActionUriFromTag {{($tag, $default_module) : string}}
- modifyActionUri {{($module, $action, [$id], [$args]) : string}}
- getRefererUri {{() : string}}
- getRequestUri {{() : string}}
- toHtml {{($value) : string}}
- toRaw {{($value) : string}}
- echo_wrapper {{($buffer)}}
- stripTipPrefix {{($id) : string}}
- getUserId {{([$refresh]) : mixed|false|null}}
- getPrivilege {{($module, [$user]) : TIP_PRIVILEGE...}}
- getDefaultPrivilege {{($module, $user) : TIP_PRIVILEGE...}}
Introduction
A collection of global functions
- Source file
- /TIP.php
A static class root of all the TIP hierarchy. It provides some global useful functions.
Methods
getOS () : 'unix'|'windows'|'os2'
Get the operating system descriptor
- lines
- 138 - 151
- static
- yes
- access
- public
Checks the PHP_OS constant to get on which operating system the PHP is running. If the PHP_OS constant is not defined, the function fallbacks to 'unix'. The idea was picked from phpMyAdmin.
arrayDefault (&$array, $key, $value)
Convenience function to set a default array value
- &$array
- array
An array
- $key
- string
The item key on $array
- $value
- mixed
The value to use if $array[$key] is not set
- lines
- 160 - 165
- static
- yes
- access
- public
getOption ($type, $option, [$required]) : mixed|null
Get an option
- $type
- string
Descriptor of the type
- $option
- string
The option to retrieve
- $required
- [ = false ]
- lines
- 177 - 184
- static
- yes
- access
- public
Gets a configuration option for a specified type. All the option values are defined in the config file.
requiredOption (&$options, $option, [$fallback])
Define a required option
- &$options
- array
Array of options
- $option
- string
The option to set
- $fallback
- mixed [ = null ]
The fallback value
- lines
- 199 - 226
- static
- yes
- access
- public
If $option is not defined in the $options array, try to guess the default value by inspecting the configuration options of the first 'application' module found in the global $cfg array.
If yet not found, the $fallback value is used.
setLocaleId ($locale) : boolean
Set locale in a platform-independent way
- $locale
- string
The locale name (such as 'en_US' or 'it_IT')
- lines
- 236 - 256
- uses
- exception
getLocaleId ([$separator]) : string
Get the current locale, such as 'en_US' or 'it_IT'
- $separator
- string [ = '_' ]
The optional glue to use between language and territory parts
- lines
- 265 - 277
- static
- yes
- access
- public
getLocale ($id, $prefix, [$context], [$cached]) : string|null
Get a localized text
- $id
- string
The identifier
- $prefix
- string
The prefix
- $context
- array [ = null ]
A context associative array
- $cached
- bool [ = true ]
Whether to perform or not a cached read
- lines
- 294 - 304
- static
- yes
- access
- public
Gets the localized text for the specified id and prefix. The parameters are passed throught: this is merely a shortcut.
See the TIP_Locale::get() method for technical details on how the text is localized.
startSession ()
Start the session
- lines
- 309 - 330
- static
- yes
- access
- public
extendedTrim ($str) : The
Extended trim function
- $str
- string
The string to trim
- lines
- 341 - 344
- static
- yes
- access
- public
The same as trim(), but converts ' ' and ' ' to spaces before trimming the string.
deepAddSlashes ($value) : array|string
Deep addslashes()
- $value
- array|string
Array or string to add slashes
- lines
- 355 - 358
- static
- yes
- access
- public
Wrappes addslashes() in a deeper form, allowing to add slashes also to embedded arrays.
deepStripSlashes ($value) : array|string
Deep stripslashes()
- $value
- array|string
Array or string to strip slashes
- lines
- 369 - 372
- static
- yes
- access
- public
Wrappes stripslashes() in a deeper form, allowing to strip slashes also to embedded arrays.
deepImplode ($pieces, [$glue]) : string
Deep implode()
- $pieces
- array
The array to implode
- $glue
- string [ = null ]
The glue to use while imploding
- lines
- 386 - 393
- static
- yes
- access
- public
Wrappes implode() in a deeper form, allowing to implode also embedded arrays. Be careful the order of the arguments is not the same of the original implode() function. This because the array_map() recursive calls pass the array as the first argument.
doubleExplode ($item_separator, $pair_separator, $buffer) : array|null
Double explode a string
- $item_separator
- string
The item separator character
- $pair_separator
- string
The key-value separator character
- $buffer
- string
The buffer to parse
- lines
- 414 - 423
- static
- yes
- access
- public
Given an item separator and a pair separator, performs the explode() operation twice and return the result as an associative array.
The $buffer must have the following format:
key1{$pair_separator}value1{$item_separator}key2{$pair_separator}value2{$item_separator}...
If, for instance, $item_separator is ',' and $pair_separator is '=', this function will properly parse the following string:
key1=value1,key2=value2,key_n=value_n
The spaces are no stripped, so be aware to keep $buffer compact.
pickElement ($keys, &$source, [$glue]) : string|null
Pick one or more elements from an array
- $keys
- string|array
A key or an array of keys
- &$source
- array
The source array
- $glue
- string [ = ' ' ]
The optional glue
- lines
- 441 - 456
- static
- yes
- access
- public
In the simplest case, this is equivalent to $source[$keys] but if $keys is an array, the result is an implode() of $source values having the keys specified in the $keys array. The $glue is used to join these values.
This function also adds some checking on $source so return null if $source is not an array or $keys is not found.
getGet ($id, $type) : mixed|null
Gets a $_GET in a typesafe manner
- $id
- string
The get identifier
- $type
- string
The expected type
- lines
- 480 - 483
- see
- getPost(),getCookie()
- static
- yes
- access
- public
Gets a value from the superglobal $_GET array, forcing the result to $type. Also, if the current PHP installation has the "magic quote" feature turned on, the result is unslashized throught deepStripSlashes() to provide a consistent method on different PHP installations.
$type can be any value accepted by settype(), that is:
- 'bool' to force a boolean value
- 'int' to force an integer number
- 'float' to force a floating point number
- 'string' to force a string
- 'array' to force an array
- 'object' to force an object
getPost ($id, $type) : mixed|null
Get a $_POST in a typesafe manner
- $id
- string
The post identifier
- $type
- string
The expected type
- lines
- 496 - 499
- see
- getGet(),getCookie()
- static
- yes
- access
- public
Performs the same job as getGet(), but using the superglobal $_POST array.
getGetOrPost ($id, $type) : mixed|null
Get a $_GET or $_POST in a typesafe manner
- $id
- string
The get/post identifier
- $type
- string
The expected type
- lines
- 512 - 517
- see
- getGet(),getPost()
- static
- yes
- access
- public
Calls getGet() to retrieve the specified item and fallback to getPost() on no item found in $_GET.
getCookie ($id, $type) : mixed|null
Get a $_COOKIE in a typesafe manner
- $id
- string
The cookie identifier
- $type
- string
The expected type
- lines
- 530 - 533
- see
- getGet(),getPost()
- static
- yes
- access
- public
Performs the same job as getGet(), but using the superglobal $_COOKIE array.
getTimestamp ($date, $format) : int|null
Get the timestamp from a special date
- $date
- mixed
The input date
- $format
- string
A supported date format
- lines
- 546 - 557
- static
- yes
- access
- public
Parses $date, specified in $format format, and return the timestamp. The currently supported formats are: * 'sql' for SQL date or datetime (YYYY-MM-DD hh:mm:ss)
formatDate ($format, [$input], [$input_format]) : mixed|null
Date/time formatter
- $format
- string
The format of the resulting date
- $input
- mixed [ = null ]
The source date to format
- $input_format
- string [ = 'timestamp' ]
The format of the source date
- lines
- 586 - 596
- static
- yes
- access
- public
- usedby
- The date formatter
Converts a date, specified in $input_format format, in the $format format and returns the result. If $input is not defined, the current time is used as input.
The $format parameter can be one of the following values: * 'date' for a string with a date description (current locale)
- 'date_sql' for date in common SQL format ('%Y-%m-%d')
- 'date_iso8601' same as 'date_sql'
- 'datetime' for a string with date and time description (current locale)
- 'datetime_sql' for a string with a time description as '%Y-%m-%d %H:%M:%S'
- 'datetime_iso8601' for a string with time description in ISO 8601 format
- 'datetime_rfc3339' for a string as described in RFC3339 (atom format)
Any other value will be passed directly to strftime().
The $input_format parameter can be one of the following values: * 'timestamp' for UNIX timestamps
- 'sql' for common SQL date/datetime
log ($severity, $message)
Log a generic message
- $severity
- string
The text of the log
- $message
- string
A custom message
- lines
- 609 - 617
- static
- yes
- access
- public
Calls the TIP_Logger::log() function, if present, to log a custom message.
The parameters are passed throught: this is merely a shortcut.
warning ($message)
Application warnings
- $message
- string
A custom message
- lines
- 630 - 633
- static
- yes
- access
- public
Logs the specified warning message (for developement purpose only) using the TIP_Logger instance, if present.
The difference between warnings and errors is that errors generate a notifyError() call while warnings don't.
error ($message)
Application errors
- $message
- string
A custom message
- lines
- 646 - 650
- static
- yes
- access
- public
Logs the specified warning message (for developement purpose only) using the TIP_Logger instance, if present.
The difference between warnings and errors is that errors generate a notifyError() call while warnings don't.
fatal ($message)
Application fatal errors
- $message
- string
A custom message
- lines
- 660 - 674
- static
- yes
- access
- public
Log an error message and quits the application. This is done by redirecting the user agent to a special page.
notifyError ([$id]) : bool
Error notification to the user
- $id
- string [ = 'fallback' ]
The notification id
- lines
- 681 - 684
- static
- yes
- access
- public
notifyWarning ([$id]) : bool
Warning notification to the user
- $id
- string [ = 'fallback' ]
The notification id
- lines
- 691 - 694
- static
- yes
- access
- public
notifyInfo ([$id]) : bool
Notification to the user
- $id
- string [ = 'fallback' ]
The notification id
- lines
- 701 - 704
- static
- yes
- access
- public
removeDir ($dir, [$self_remove])
Recursively remove a directory
- $dir
- string
The directory to delete
- $self_remove
- boolean [ = true ]
Whether to remove $dir itsself
- lines
- 711 - 727
- static
- yes
- access
- public
buildPath ( … ) : string
Build a path
- …
- string|array
A list of partial paths
- lines
- 738 - 747
- static
- yes
- access
- public
Constructs a path from the argument list and prepending the application base path.
buildLogicPath ( … ) : string
Build a logic path
- …
- string|array
A list of partial paths
- lines
- 757 - 765
- static
- yes
- access
- public
Shortcut for building a path prepending the application 'logic_root'.
buildTemplatePath ( … ) : string
Build a template path
- …
- string|array
A list of partial paths
- lines
- 775 - 783
- static
- yes
- access
- public
Shortcut for building a path prepending the application 'template_root'.
buildFallbackPath ( … ) : string
Build a template fallback path
- …
- string|array
A list of partial paths
- lines
- 793 - 801
- static
- yes
- access
- public
Shortcut for building a path prepending the application 'fallback_root'.
buildDataPath ( … ) : string
Build a data path
- …
- string|array
A list of partial paths
- lines
- 811 - 818
- static
- yes
- access
- public
Shortcut for building a path prepending the application 'data_root'.
buildCachePath ( … ) : string
Build a cached path
- …
- string|array
A list of partial paths
- lines
- 828 - 835
- static
- yes
- access
- public
Shortcut for building a path prepending the application 'cache_root'.
getRoot () : string
Get the absolute root of the URIs in this server
- lines
- 841 - 848
- static
- yes
- access
- public
getHome () : string
Get the (relative) URI to the home page
- lines
- 854 - 867
- static
- yes
- access
- public
buildUri ( … ) : string
Build a relative URI
- …
- string|array
A list of partial URIs
- lines
- 874 - 884
- static
- yes
- access
- public
buildDataUri ( … ) : string
Build a data (relative) URI
- …
- string|array
A list of partial URIs
- lines
- 891 - 898
- static
- yes
- access
- public
buildTemplateUri ( … ) : string
Build a template (relative) URI
- …
- string|array
A list of partial URIs
- lines
- 905 - 913
- static
- yes
- access
- public
buildFallbackUri ( … ) : string
Build a template fallback (relative) URI
- …
- string|array
A list of partial URIs
- lines
- 920 - 928
- static
- yes
- access
- public
buildActionUri ($module, $action, [$id], [$args]) : string
Build an action (relative) URI
- $module
- string
The module name
- $action
- string
The action to perform
- $id
- string [ = null ]
The subject of the action
- $args
- array [ = null ]
Optional additional query arguments
- lines
- 938 - 966
- static
- yes
- access
- public
buildActionUriFromTag ($tag, $default_module) : string
Build an action (relative) URI
- $tag
- string
A string in the format 'action[,id[,arg1=value1,...]]'
- $default_module
- string
The module to use if not specified as arg
- lines
- 975 - 998
- static
- yes
- access
- public
modifyActionUri ($module, $action, [$id], [$args]) : string
Build an action URI by modify the current action
- $module
- string
The module name
- $action
- string
The action to perform
- $id
- string [ = null ]
The subject of the action
- $args
- array [ = null ]
Optional additional query arguments
- lines
- 1012 - 1033
- static
- yes
- access
- public
In this case, anything different from null will be applied to the current action. The $args array will be merged to the current one.
getRefererUri () : string
Get the referer URI
- lines
- 1044 - 1052
- static
- yes
- access
- public
The returned string is not the raw referer, but a logic referer. This means page swapping on the same action or refreshing it does not change the old referer.
getRequestUri () : string
Get the request URI
- lines
- 1059 - 1067
- static
- yes
- access
- public
toHtml ($value) : string
Convert to HTML a value
- $value
- mixed
The value to convert
- lines
- 1077 - 1091
- static
- yes
- access
- public
Converts the $value content in HTML safe manner, accordling to its type.
toRaw ($value) : string
Stringify a value to its raw representation
- $value
- mixed
The value to convert
- lines
- 1105 - 1119
- static
- yes
- access
- public
Converts the given $value to its raw representation. This is different from a simple (string) cast: booleans, for instance, are converted to 'true' or 'false', not to '1' or ''.
Useful on expanding values for eval()ued code.
echo_wrapper ($buffer)
Function wrapper of the 'echo' construct
- $buffer
- mixed
The buffer to echo
- lines
- 1126 - 1129
- access
- public
- static
- yes
stripTipPrefix ($id) : string
Strip the TIP prefix
- $id
- string
A TIP prefixed identifier
- lines
- 1141 - 1144
- static
- yes
- access
- public
Removes the TIP prefix, defined in the TIP_PREFIX constant, from a string.
getUserId ([$refresh]) : mixed|false|null
Gets the current user id
- $refresh
- bool [ = false ]
Forces the update of the internal cache
- lines
- 1156 - 1168
- static
- yes
- access
- public
Returns the id of the logged in user.
getPrivilege ($module, [$user]) : TIP_PRIVILEGE...
Get the privilege for the specified module
- $module
- string
The requesting module identifier
- $user
- mixed [ = null ]
A user id
- lines
- 1181 - 1193
- static
- yes
- access
- public
Returns the privilege for a module and the specified user. If $user is omitted, the current user id is used. Check TIP_Privilege to see how the privileges are used.
getDefaultPrivilege ($module, $user) : TIP_PRIVILEGE...
Get the default fallback privilege for the specified module
- $module
- string
The requesting module identifier
- $user
- mixed
A user id
- lines
- 1204 - 1213
- static
- yes
- access
- public
Returns the default privilege for a module and a specified user.
TIP
was last modified by
TiP
on
Mon 25 May 2009 06:22:25 PM CEST