Common

Classes

class  utyResult
 Execution result. More...

Modules

 enum UTY_ERR
 enum UTY_DIRTYPE
 enum UTY_SORT
 enum UTY_RC

Functions

 uty_set_error_handler ($debug=FALSE)
 uty_set_log ($log_path="./log", $log_level=UTY_ERR_USR)
 uty_log ($level, $message)
 uty_error_handler ($php_level, $message, $file, $line)
 uty_fullurl ()
 uty_exit ($status_code, $status_text="OK", $content="", $content_type="text/plain; charset:utf-8")
 uty_check_file_ext ($basename, $whitelist=NULL, $blacklist=NULL)
 uty_normalize_path ($path, $dir=FALSE)
 uty_check_path ($path, $root="/")
 uty_dir ($path, $sortkey=NULL, $sortorder=UTY_SORT_ASC)
 uty_remove ($path, $whitelist=NULL, $blacklist=NULL)
 uty_copy ($source, $dest, $overwrite=FALSE, $whitelist=NULL, $blacklist=NULL)
 uty_include_js ($basename, $path=NULL)
 uty_postval ($name)
 uty_check_md5 ($value)

Variables

 $_UTY_JS = array()
 $_UTY_CSS = array()
 $_UTY_ERRORS = array()
 $_UTY_LOG = ""
 $_UTY_LOG_LEVEL = 0
 $_UTY_DEBUG = FALSE

Function Documentation

uty_check_file_ext ( basename,
whitelist = NULL,
blacklist = NULL 
)

Performs multiple file extensions check.

Parameters:
basename (string) the basename of the file to check
[whitelist] (array) case sensitive list of allowed extension, default=NULL
[blacklist] (array) case insensitive list of forbidden extension, default=NULL
Returns:
TRUE if OK, FALSE otherwise
uty_check_md5 ( value  ) 
Returns:
true if value is a valid 32 chars hexadecimal string, false otherwise
Parameters:
value (string) the 32 hex digit string to check
uty_check_path ( path,
root = "/" 
)

Takes two (absolute or relative) paths and determines if one is a subdirectory of the other it doesn't care if it is an immediate child or 10 subdirectories deep... use absolute paths for both for best results NB: path MUST exist!

Parameters:
path (string) the absolute or relative path to check
[root] (string) the folder path must belong to, default="/"
Returns:
TRUE if path exists under root, FALSE otherwise
uty_copy ( source,
dest,
overwrite = FALSE,
whitelist = NULL,
blacklist = NULL 
)

Copy file/folder $source to $dest. If $source is a folder use recursion

Parameters:
$source (string) the path (absolute or relative) to the source file/folder
$dest (string) the path (absolute or relative) to the source file/folder
[$overwrite] [bool] if TRUE overwrite existing files, if FALSE and a file exists stops and return error, default=FALSE
[whitelist] (array) case sensitive list of allowed extension, default=NULL
[blacklist] (array) case insensitive list of forbidden extension, default=NULL
Returns:
NULL if OK, utyResult otherwise
uty_dir ( path,
sortkey = NULL,
sortorder = UTY_SORT_ASC 
)

list all files/directories in path as an array of "stat" where stat is the associative array returned by the stat function PLUS this xtra information: stat['basename'] = basename stat['fullname'] = path.'/'.basename stat['dirtype'] = UTY_DIRTYPE_FOLDER or UTY_DIRTYPE_FILE

Parameters:
path (string) the path to get list of
[sortkey] (string) 'basename', 'size' or 'ctime', if NULL the filesystem decide the order, default=NULL
[sortorder] (int) sort order(*), default=UTY_SORT_ASC
Returns:
array(stat) if OK, NULL if error. NB: always test ===NULL (an array with 0 elements evaluats to false!)

NB: basename sort is case insensitive

See also:
(*) DOC_COMMON_SORT
uty_error_handler ( php_level,
message,
file,
line 
)

THIS IS NOT AN APY, THIS IS PHP ERROR HANDLER CALLBACK. After you called uty_error_reporting, ALL php error are sent here!

If (level & error_reporting(setted in uty_set_error_handler)) append to $_UTY_ERRORS a new utyResult with:

  • level = UTY_ERR_WARN
  • code = UTY_RC_PHPERROR
  • description = UTY_LANG_RC_PHPERROR
  • details = message

NOTABENE:

  • backtrace will be settede in utyResult depending on the UTY_DEBUG value
  • if $_UTY_LOG and UTY_LOG_LEVEL<=UTY_ERR_WARNING (setted by uty_log_init) the error will be logged (see utyResult).
    Parameters:
    php_level php error level. NB don't mismatch this with UTY_ERR_* error level
    message php error message
    file php error file
    line php error line
    Returns:
    TRUE always, so php error_reporting is never used!
    See also:
    uty_set_error_handler()
uty_exit ( status_code,
status_text = "OK",
content = "",
content_type = "text/plain; charset:utf-8" 
)

Set http status line, prints content and die.

NB: MUST be called BEFORE any content has been print to output (useful for ajax responses)

Parameters:
status_code (int) http status code (200=OK, 1xx information, 2xx success, 3xx redirection, 4xx client error, 5xx server error
[status_text] (string) http status text, default = "OK" (*)
[content] (string) response content, default = ""
[content_type] (string) Content-Type header value, default="text/plain; charset:utf-8"

NOTABENE:

  • This function must be used BEFORE any html output as it sets http headers.
  • (*) It seems that when the status-code = 200, the status-text is overwritten with a constant 'OK'. So don't use status-text to put infos if ok.
  • DON'T USE STATUS-TEXT FOR international error MESSAGES as only ASCII is supported in http headers: USE $content instead!
uty_fullurl (  ) 
Returns:
the full request url i.e. http(s)://(subdomains).servername/request-uri(including get args)
uty_include_js ( basename,
path = NULL 
)

Outuputs the $path/$basename script tag once. (resamble include_once) Automatically resolves javascript dependancies for utillyty scripts

Parameters:
basename (string) the basename of the javascript file, i.e: 'uty.js'
[path] (string) the path (WITHOUT trailing '/') to the script. NULL for utilliyty's js, default=NULL

NOTABENE:

  • for utillyty scripts path MUST be null (files are looked for in the UTILLYTY folder)
  • path must NOT end with trailing '/'
uty_log ( level,
message 
)

Write message to the log if level>=_UTY_LOG_LEVEL

Parameters:
level (int) the message log level, one of the UTY_ERR_* const.
message (mixed) any string or object to be logged (print_r is used)
Returns:
TRUE if OK, false if error
See also:
utyResult
uty_normalize_path ( path,
dir = FALSE 
)

Replace any '\' with '/'

Parameters:
$path (string) the path to normalize
[$dir] (bool) if TRUE append a trailing '/' (if not present), default=FALSE
Returns:
the server fixed path
uty_postval ( name  ) 
Returns:
$_POST['$name'] or NULL if not set NB: if get_magic_quotes_gpc() => stripslashes
Parameters:
name (string) the post variable name
uty_remove ( path,
whitelist = NULL,
blacklist = NULL 
)

Removes a file or a folder using recursion.

Parameters:
$path (string) the path (absolute or relative) of the file/folder to remove
[whitelist] (array) case sensitive list of allowed extension, default=NULL
[blacklist] (array) case insensitive list of forbidden extension, default=NULL
Returns:
NULL if OK, utyResult otherwise
uty_set_error_handler ( debug = FALSE  ) 

Custom error reportings: Sets $_UTY_DEBUG to $debug, php error handler to uty_error_handler, and php error_reporting to -1 if debug or E_ALL & ~E_NOTICE otherwise. Sets also display_errors = debug

NOTABENE:

  • all php errors will be handled by uty_error_handler ;)
  • DON'T USE debug=TRUE in production environments!
    Parameters:
    [debug] (bool) the utillyty debug status, default = FALSE
    See also:
    uty_error_handler()
uty_set_log ( log_path = "./log",
log_level = UTY_ERR_USR 
)

log settings

Parameters:
[log_path] (string) the path where log files are stored WITHOUT trailing '/', default='./log'. if log_path="" NO log will be saved.
[log_level] (UTY_ERR) one of UTY_ERR_* const. uty_log will log messages with level>=log_level (NB: utyResult calls uty_log when created), default = UTY_ERR_USR.
See also:
uty_log()

Variable Documentation

$_UTY_CSS = array()

(array) list of included stylesheets paths (not yet used...)

$_UTY_DEBUG = FALSE

(bool) if TRUE utyResult will include backtrace.

See also:
uty_set_error_handler()

class definitions =======================================================

/* * @ brief Detailed context information for the utyResult class. / class utyStackFrame { public $program; /**< (string) automatically set to uty_fullurl() * / public $file; /**< (string) php script file name* / public $line; /**< (int) line number in the file * / public $func; /**< (string) function name * / public $args; /**< (array) name=>value list of arguments * / public $time; /**< (string )unix time* / public $etc; /**< (array) contains: 'post'=>print_r($_POST, true), you can add anything else you want * /

/** Create utyStackFrame with the specified info.

Parameters:
file (string) __FILE__ (php executing file name)
line (int) __LINE__ (php file line number)
func (string) __FUNCTION__ (function name)
[args] (array) name=>value pairs of calling arguments, default=NULL / function utyStackFrame($file, $line, $func, $args=NULL) { $this->time = microtime(); $this->program = uty_fullurl(); $this->file = $file; $this->line = $line; $this->func = $func; $this->args = $args; $this->etc = array('post' => print_r($_POST, TRUE)); } /** Push an argument to the arguments list.
argn (string) argument name
argv (mixed) argument value / function arg($argn, $argv) { if (!$this->$args) $this->$args = array(); $this->$args[$argn] = $argv; } };
$_UTY_ERRORS = array()

(array) list of utyResult containing not catched runtime errors. you must call uty_set_error_reporting

$_UTY_JS = array()

(array) list of included javascript paths(used by uty_include_js)

$_UTY_LOG = ""

(string) path to the folder where errors are logged.

See also:
uty_set_log()
uty_log()
$_UTY_LOG_LEVEL = 0

(int) UTY_ERR_* level of messages to log.

See also:
uty_set_log()
uty_log()
 All Classes Files Functions Variables Enumerations

Copyright © 2010 Attilio Pavone - www.utillyty.eu