Hints: It is recommended to use the methods in this class instead of PHP native methods whenever is possible because this class will offer Long Term Support and the methods will be supported even if the behind PHP methods can change over time, so the code would be easier to maintain.
Usage: static object: Class::method() - This class provides only STATIC methods
class Methods
public staticfunctionis_nscalar (
MIXED$val
) {} :: BOOL
@return: {BOOL} FALSE if array, object or resource ; TRUE for the rest
@param: {MIXED} $val: The value to be tested
@return: {MIXED} The value for the selected parameter. If the Config parameter does not exists, will return an empty string.
@param: {STRING} $param: The selected configuration parameter. Example: 'app.info-url' will get value (STRING) from $configs['app']['info-url'] ; 'app' will get the value (ARRAY) from $configs['app']
@param: {ENUM} $type: The type to pre-format the value: 'array', 'string', 'boolean', 'integer', 'numeric' OR '' to leave the value as is (raw)
Get the value for a Config parameter from the app $configs array.
@return: {STRING} The fixed path name
@param: {STRING} $y_path: The path name to fix
Fix for Directory Separator if on Windows
public staticfunctionreal_path (
string$y_path
) {} :: STRING
@return: {STRING} The real path
@param: {STRING} $y_path: The path name from to extract realpath()
Return the FIXED realpath() as absolute path, also with fix on Windows
This should be mostly used for existing paths. If path does not exists will return the same path as passed argument.
It does not support passing empty paths to avoid security issues like rtrim(Smart::real_path(''),'/').'/' which will point to the root folder of the filesystem.
public staticfunctiondir_name (
string$y_path
) {} :: STRING
@return: {STRING} The dirname or . or empty string
@param: {STRING} $y_path: The path name from to extract dirname()
Return the FIXED dirname(), safe on Linux and Unix and with safety fix on Windows
@return: {STRING} The basename
@param: {STRING} $y_path: The path name from to extract basename()
@param: {STRING} $y_suffix: If the name component ends in suffix this will also be cut off
Return the FIXED basename(), in a safe way
The directory separator character is the forward slash (/), except Windows where both slash (/) and backslash (\) are considered
public staticfunctionpath_info (
string$y_path
) {} :: ARRAY
@return: {ARRAY} The pathinfo array
@param: {STRING} $y_path: The path to process as pathinfo()
Return the FIXED pathinfo(), also with fix on Windows
public staticfunctionstr_replace_first (
string$search,
string$replace,
string$str
) {} :: STRING
@return: {STRING} This function returns a string with the replaced value only on first occurence if search value is found
@param: {STRING} $search: The value being searched for, otherwise known as the needle
@param: {STRING} $replace: The replacement value that replaces found search value
@param: {STRING} $str: The string being searched and replaced on, otherwise known as the haystack
Str Replace, Only First Occurence
public staticfunctionstr_replace_last (
string$search,
string$replace,
string$str
) {} :: STRING
@return: {STRING} This function returns a string with the replaced value only on last occurence if search value is found
@param: {STRING} $search: The value being searched for, otherwise known as the needle
@param: {STRING} $replace: The replacement value that replaces found search value
@param: {STRING} $str: The string being searched and replaced on, otherwise known as the haystack
Str Replace, Only Last Occurence
public staticfunctionurl_build_query (
array$y_params,
bool$y_allow_late_binding_params
) {} :: STRING
@return: {STRING} The prepared URL in the standard RFC3986 format (all values are escaped using rawurlencode() to be Unicode full compliant
@param: {ARRAY} $y_params: Associative array as [param1 => value1, Param2 => Value2]
@param: {BOOLEAN} $y_allow_late_binding_params: Allow late binding params ex: a={{{param}}}&b=true
Build an URL Query (Build a standard RFC3986 URL from an array of parameters) as: a=b¶m1=value1¶m2=value2&c[0]=a&c[1]=x&d[a]=15&d[b]=z
@return: {STRING} The prepared URL in the standard RFC3986 format (all values are escaped using rawurlencode() to be Unicode full compliant
@param: {STRING} $y_url: The base URL like: script.php or script.php?a=b or empty
@param: {ARRAY} $y_params: Associative array as [param1 => value1, Param2 => Value2, param3 => {{{late-binding}}}]
@param: {BOOLEAN} $y_allow_late_binding_params: Allow late binding params ex: a={{{param}}}&b=true
Add URL Params (Build a standard RFC3986 URL from script and parameters) as: script.xyz?a=b¶m1=value1¶m2=value2¶m3={{{late-binding}}}
It allows late binding params such as 'param3' => '{{{late-binding}}}'
public staticfunctionurl_add_suffix (
string$y_url,
string$y_suffix
) {} :: STRING
@return: {STRING} The prepared URL in the standard RFC3986 format (all values are escaped using rawurlencode() to be Unicode full compliant
@param: {STRING} $y_url: The base URL to use as prefix like: script.php or script.php?a=b&c=d or empty
@param: {STRING} $y_suffix: A RFC3986 URL segment like: a=b or E=%20d (without ? or not starting with & as they will be detected if need append ? or &; variable values must be encoded using rawurlencode() RFC3986)
Add URL Suffix (to a standard RFC3986 URL) as: script.php?a=b&C=D&e=%20d
public staticfunctionurl_add_anchor (
string$y_url,
string$y_anchor
) {} :: STRING
@return: {STRING} The prepared URL as script.php?a=b&c=d&e=%20d#myAnchor
@param: {STRING} $y_url: The base URL to use as prefix like: script.php or script.php?a=b&c=d or empty
@param: {STRING} $y_anchor: A RFC3986 URL anchor like: myAnchor
Add URL Anchor (to a standard RFC3986 URL) as: script.php?a=b&C=D&e=%20d
public staticfunctionescape_url (
string$y_string
) {} :: STRING
@return: {STRING} The escaped URL variable using the RFC3986 standard format (this variable can be appended to URL, by example: ?variable={escaped-value-returned-by-this-method}
@param: {STRING} $y_string: The variable value to be escaped
Safe escape URL Variable (using RFC3986 standards to be full Unicode compliant)
This is a shortcut to the rawurlencode() to provide a standard into Smart.Framework
public staticfunctionescape_html (
string$y_string
) {} :: STRING
@return: {STRING} The escaped string using htmlspecialchars() standards with Unicode-Safe control
@param: {STRING} $y_string: The string to be escaped
Safe escape strings to be injected in HTML code
This is a shortcut to the htmlspecialchars() to avoid use long options each time and provide a standard into Smart.Framework
public staticfunctionescape_css (
string$y_string
) {} :: STRING
@return: {STRING} The escaped string using the WD-CSS21-20060411 standard
@param: {STRING} $y_string: The string to be escaped
Safe escape strings to be injected in CSS code
public staticfunctionescape_js (
string$str
) {} :: STRING
@return: {STRING} The escaped string using a json_encode() standard to be injected between single quotes '' or double quotes ""
@param: {STRING} $str: The string to be escaped
Safe escape strings to be injected in Javascript code as strings
@return: {STRING} The JSON encoded string
@param: {MIXED} $data: The variable to be encoded (mixed): numeric, string, array
@param: {BOOLEAN} $prettyprint: *Optional* Default to FALSE ; If TRUE will format the json as pretty-print (takes much more space, but sometimes make sense ...)
@param: {BOOLEAN} $unescaped_unicode: *Optional* Default to TRUE ; If FALSE will escape unicode characters
@param: {BOOLEAN} $htmlsafe: *Optional* Default to TRUE ; If FALSE the JSON will not be HTML-Safe as it will not escape: < > ' " &
@return: {MIXED} The PHP native Variable: NULL ; INT ; NUMERIC ; STRING ; ARRAY
@param: {STRING} $json: The JSON string
@param: {BOOLEAN} $return_array: *Optional* Default to FALSE ; When TRUE, returned objects will be converted into associative arrays (default to TRUE)
Decode JSON strings to PHP native variable(s)
public staticfunctionseryalize (
MIXED$data
) {} :: STRING
@return: {STRING} The JSON encoded string
@param: {MIXED} $data: The variable to be encoded: numeric, string, array
Serialize PHP variables to a JSON string
This is a safe replacement for PHP serialize() which can break the security if contain unsafe Objects
public staticfunctionunseryalize (
string$y_json
) {} :: MIXED
@return: {MIXED} The PHP native Variable
@param: {STRING} $y_json: The JSON string
Unserialize JSON data to PHP native variable(s)
This is a safe replacement for PHP unserialize() which can break the security if contain unsafe Objects
public staticfunctioncheck_int_number_overflow (
$y_number
) {} :: BOOL
@return: {BOOLEAN} TRUE if overflows the max safe integer ; FALSE if is OK (not overflow maximum)
Check if an integer number overflows the minimum or maximum safe int
All numbers over this must use special operators from BCMath to avoid floating point precision issues
On 32-bit platforms the INTEGER is between -2147483648 to 2147483647
On 64-bit platforms the INTEGER is between -9223372036854775808 to 9223372036854775807
public staticfunctioncheck_dec_number_overflow (
$y_number
) {} :: BOOL
@return: {BOOLEAN} TRUE if overflows the max safe decimal ; FALSE if is OK (not overflow maximum)
Check if a decimal number overflows the minimum or maximum safe decimal as precision = 14 (PHP default)
Thus decimal numbers must be between -999999999999.9900 and 999999999999.9900
All numbers over this must use special operators from BCMath to avoid floating point precision issues
This is more intended for decimal numbers like financial operations where the significant decimal digits are important
@return: {FLOAT} An float number
@param: {NUMERIC} $y_number: A numeric value
@param: {ENUM} $y_signed: Default to '' ; If set to '+' will return (enforce) an UNSIGNED/POSITIVE Number ; If set to '-' will return (enforce) an NEGATIVE Number ; Otherwise if set to NULL or '' will return just a regular SIGNED Number wich can be negative or positive
Format a number as FLOAT
public staticfunctionformat_number_int (
NUMERIC$y_number,
string$y_signed = null
) {} :: INT
@return: {INTEGER} An integer number
@param: {NUMERIC} $y_number: A numeric value
@param: {ENUM} $y_signed: Default to '' ; If set to '+' will return (enforce) an UNSIGNED/POSITIVE Number ; If set to '-' will return (enforce) an NEGATIVE Number ; Otherwise if set to NULL or '' will return just a regular SIGNED Number wich can be negative or positive
Format a number as INTEGER
On 64-bit platforms the INTEGER is between -9223372036854775808 to 9223372036854775807
@return: {DECIMAL} DECIMAL :: A decimal number as string
@param: {NUMERIC} $y_number: A numeric value
@param: {INTEGER+} $y_decimals: The number of decimal to use (safe value is between 1..13, keeping in mind the 14 max precision) ; Default is 2
@param: {STRING} $y_sep_decimals: The decimal separator symbol as: . or , (default is .)
@param: {STRING} $y_sep_thousands: The thousand separator symbol as: , or . (default is [none])
Format a number as DECIMAL (NOTICE: The maximum PHP.INI precision is 14, includding decimals).
Because of the precision, it supports values between -999999999999.9900 and 999999999999.9900 ; If a value overflows limits will return -limit / +limit depends if value is negative or positive
This is a better replacement for the PHP's number_format() which throws a warning if first argument passed is a string since PHP 5.3
public staticfunctionarray_size (
ARRAY/MIXED$y_arr
) {} :: INT
@return: {INTEGER} The array COUNT of elements, or zero if array is empty or non-array is provided
@param: {ARRAY/MIXED} $y_arr: The array to count elements on ; can be a mixed variable ; if non-array will return zero
Safe array count(), for safety, with array type check ; this should be used instead of count() because count(string) returns a non-zero value and can confuse if a string is passed to count instead of an array
public staticfunctionarray_sort (
array$y_arr,
string$y_mode
) {} :: ARRAY
@return: {ARRAY} The sorted array
@param: {ARRAY} $y_arr: The array to be sorted by a criteria (type, see below)
@param: {ENUM} $y_mode: The sort type: natsort, sort, rsort, asort, arsort, ksort, krsort
Easy sort for NON-Associative arrays ...
public staticfunctionarray_shuffle (
array$y_arr
) {} :: ARRAY
@return: {ARRAY} The sorted array
@param: {ARRAY} $y_arr: The array to be sorted by a criteria (type, see below)
Shuffle for NON-Associative arrays ...
public staticfunctionarray_get_by_key_path (
array$y_arr,
string$y_key_path,
string$y_path_separator
) {} :: MIXED
@return: {MIXED} The value from the specified array by the specific key path or NULL if the value does not exists
@param: {ARRAY} $y_arr: The input array
@param: {STRING} $y_key_path: The composed key path by levels (Ex: key1.key2) :: case-sensitive
@param: {STRING} $y_path_separator: The key path separator (Example: .)
Array Get (value) By Key Path (case sensitive)
public staticfunctionarray_test_key_by_path_exists (
array$y_arr,
string$y_key_path,
string$y_path_separator
) {} :: BOOL
@return: {BOOL} TRUE if Key Exist / FALSE if NOT
@param: {ARRAY} $y_arr: The input array
@param: {STRING} $y_key_path: The composed key path by levels (Ex: key1.key2) :: case-sensitive
@param: {STRING} $y_path_separator: The key path separator (Example: .)
Array Test if Key Exist By (Key) Path (case sensitive)
public staticfunctionarray_change_key_case_recursive (
array$y_arr,
string$y_mode
) {} :: ARRAY
@return: {ARRAY} The modified array
@param: {ARRAY} $y_arr: The input array
@param: {ENUM} $y_mode: Change Mode: LOWER | UPPER
Array Recursive Change Key Case
public staticfunctionarray_init_keys (
ARRAY/MIXED$y_arr,
LIST/ARRAY$y_keys
) {} :: ARRAY
@return: {ARRAY} The modified array
@param: {ARRAY/MIXED} $y_arr: The input array
@param: {LIST/ARRAY} $y_keys: The array keys to initialize: will add these keys to the array assigned with a NULL value only if the key does not exists ; the existing keys will be preserved with their existing values ; must be a non-associative array, as: [ 'key1', 'key2', '', ...] ; a key can be also an empty string
Array Initialize Keys
public staticfunctionarray_type_test (
ARRAY$y_arr
) {} :: INT
@return: {INT/ENUM} The array type as: 0 = not an array ; 1 = non-associative (sequential) array or empty array ; 2 = associative array or non-sequential, must be non-empty
@param: {ARRAY} $y_arr: The array to test
Test if the Array Type for being associative or non-associative sequential (0..n)
public staticfunctionarray_diff_assoc_recursive (
array$array1,
array$array2
) {} :: ARRAY
@return: {STRING} The processed string (text)
@param: {STRING} $ytxt: The text string to be processed
@param: {STRING} $ylen: The fixed length of the string
@param: {BOOLEAN} $y_cut_words: *Optional* Default TRUE ; if TRUE, will CUT last word to provide a fixed length ; if FALSE will eliminate unterminate last word ; default is TRUE
@param: {ENUM} $y_suffix: *Optional* Default '...' ; Can be '' or '[...a cutoff-message...]'
Cut a text by a fixed length, if longer than allowed length.
If cut words option is FALSE it may make the string shorted by rolling back until the last space and cutting off the last partial word.
The default cut suffix is (...) but can be disabled using the last parameter.
@return: {STRING} The processed HTML Code
@param: {ARRAY} $yhtmlcode: HTML Code to be stripped of tags
@param: {BOOL} $y_mode: Default is TRUE to convert <br> to new lines \n, otherwise (if FALSE) will convert <br> to spaces
@param: {BOOL} $ynormalize: Default is TRUE to normalize the code as text, otherwise (if FALSE) will do not use extra normalize feature so the code may be re-used for re-encoding as html (ex: extract markdown) ...
Enhanced strip_tags() :: will revert also special entities like nbsp; and more
@return: {STRING} The safe path ; if invalid will return empty value
@param: {STRING} $y_path: Path to be processed
@param: {STRING} $ysupresschar: The suppression character to replace weird characters ; optional ; default is ''
Create a Safe Path Name to be used to process dynamic build paths to avoid weird path character injections
This should be used for relative or absolute path to files or dirs
It should allow also both: absolute and relative paths, thus if absolute path should be tested later
NOTICE: It may return an empty string if all characters in the path are invalid or invalid path sequences detected, so if empty path name must be tested later
ALLOWED CHARS: [a-zA-Z0-9] _ - . @ # /
@return: {STRING} The safe file or dir name ; if invalid will return empty value
@param: {STRING} $y_fname: File Name or Dir Name to be processed
@param: {STRING} $ysupresschar: The suppression character to replace weird characters ; optional ; default is ''
Create a Safe File Name to be used to process dynamic build file names or dir names to avoid weird path character injections
To should be used only for file or dir names (not paths)
NOTICE: DO NOT USE for full paths or full dir paths because will break them, as the / character is supressed
NOTICE: It may return an empty string if all characters in the file/dir name are invalid or invalid path sequences detected, so if empty file/dir name must be tested later
ALLOWED CHARS: [a-zA-Z0-9] _ - . @ #
@return: {STRING} The safe variable name ; if invalid should return empty value
@param: {STRING} $y_name: Variable Name to be processed
@param: {BOOL} $y_allow_upper: Allow UpperCase ; *Optional* ; Default is TRUE
Creates a Safe Valid Variable Name
NOTICE: this have a special usage and must allow also 0..9 as prefix because is can be used for other purposes not just for real safe variable names, thus if real safe valid variable name must be tested later (real safe variable names cannot start with numbers ...)
NOTICE: It may return an empty string if all characters in the given variable name are invalid or invalid path sequences detected, so if empty variable name must be tested later
ALLOWED CHARS: [a-zA-Z0-9] _
@return: {STRING} The safe name ; if invalid should return empty value
@param: {STRING} $y_name: Name to be processed
@param: {STRING} $ysupresschar: The suppression character to replace weird characters ; optional ; default is ''
Create a (RFC, ISO) Safe compliant User Name, Domain Name or Email Address
NOTICE: It may return an empty string if all characters in the given name are invalid or invalid path sequences detected, so if empty name must be tested later
ALLOWED CHARS: [a-z0-9] _ - . @
public staticfunctionsafe_username (
string$y_name
) {} :: STRING
@return: {STRING} The safe name ; if invalid should return empty value
@param: {STRING} $y_name: Name to be processed
Create a Safe Valid Strict User Name
NOTICE: It may return an empty string if all characters in the given name are invalid or invalid path sequences detected, so if empty name must be tested later
ALLOWED CHARS: [a-z0-9] .
@return: {STRING} The slug which will contain only: a-z 0-9 _ - (A-Z will be converted to a-z if lowercase is enforced)
@param: {STRING} $y_str: The string to be processed
@param: {BOOLEAN} $y_lowercase: *OPTIONAL* If TRUE will return the slug with enforced lowercase characters ; DEFAULT is FALSE
@param: {INTEGER+} $y_maxlen: *OPTIONAL* If a positive value greater than zero is supplied here the slug max length will be constrained to this value
Creates a Slug (URL safe slug) from a string
public staticfunctioncreate_htmid (
string$y_str
) {} :: STRING
@return: {STRING} The HTML-ID which will contain only: a-z A-Z 0-9 _ -
@param: {STRING} $y_str: The string to be processed
Creates a compliant HTML-ID (HTML ID used for HTML elements) from a string
public staticfunctioncreate_jsvar (
string$y_str
) {} :: STRING
@return: {STRING} The Js-Var which will contain only: a-z A-Z 0-9 _ $
@param: {STRING} $y_str: The string to be processed
Creates a compliant Js-Var (JavaScript Variable Name) from a string
public staticfunctionnormalize_spaces (
string$y_txt
) {} :: STRING
@return: {STRING} The normalized text
@param: {STRING} $y_txt: Text to be normalized
Normalize Spaces
This will replace: "\r", "\n", "\t", "\x0B", "\0", "\f" with normal space ' '
public staticfunctionrandom_number (
$y_min = 0,
$y_max = -1,
bool$y_seed = false
) {} :: INT
@return: {INTEGER} An integer random number
Generates an integer random number between min and max using mt_rand() which is4x times faster than rand().
It may use a random seed based on microtime or custom using mt_srand() which uses MT_RAND_MT19937 for PHP >= 7.1
NOTICE: using a time based seed may result in most of the calls to a random number may return the same number which perhaps is not what is expected !!
The min is zero. The max is limited to 2147483647 on most of the platforms.
@return: {STRING} The decoded string (as hex) from the selected base or empty string on error
@param: {STRING} $encoded: A string (baseXX encoded) that was previous encoded using Smart::base_from_hex_convert()
@param: {INTEGER} $currentBase: The base to convert ; Available source base: 32, 36, 58, 62, 85, 92
@param: {STRING} $charset: *OPTIONAL* an alternate charset if non-empty ; if empty (default) the built-in charset will be used
Safe convert to hex from any of the following bases: 32, 36, 58, 62, 85, 92
In case of error will return an empty string.
@return: {STRING} The encoded string in the selected base or empty string on error
@param: {STRING} $hexstr: A hexadecimal string (base16) ; can be from bin2hex($string) or from dechex($integer) but in the case of using dechex must use also left padding with zeros to have an even length of the hex data
@param: {INTEGER} $targetBase: The base to convert ; Available target base: 32, 36, 58, 62, 85, 92
@param: {STRING} $charset: *OPTIONAL* an alternate charset if non-empty ; if empty (default) the built-in charset will be used
Safe convert from hex to any of the following bases: 32, 36, 58, 62, 85, 92
In case of error will return an empty string.
public staticfunctionhex_to_int10 (
string$hex
) {} :: INT
public staticfunctionint10_to_hex (
int$num
) {} :: STRING
public staticfunctionint10_to_base62_str (
int$num
) {} :: STRING
public staticfunctionnet_server_id (
bool$base36 = false
) {} :: STRING
Returns the valid Net Server ID (to be used in a cluster)
Valid values are 0..1295 (or 00..ZZ if BASE36)
Generates a time based entropy as replacement for uniqid() to ensure is unique in time and space.
It is based on a full unique signature in space and time: server name, server unique id, a unique time sequence that repeats once in 1000 years and 2 extremely large (fixed length) random values .
If a suffix is provided will append it.
public staticfunctionuuid_10_num (
) {} :: STRING
@return: {STRING} the UUID
Intended usage: Small scale.
Generates a random, almost unique numeric UUID of 10 characters [0..9] ; Example: 5457229400 .
For the same time moment, duplicate values can happen with a chance of 1 in a 9 million.
Min is: 0000000001 ; Max id: 9999999999 .
Values: 9999999998 .
public staticfunctionuuid_10_str (
) {} :: STRING
@return: {STRING} the UUID
Intended usage: Medium scale.
Generates a random, almost unique string (base36) UUID of 10 characters [0..9A..Z] ; Example: Z4C9S6F1H1 .
For the same time moment, duplicate values can occur with a chance of ~ 1 in a 3000 trillion.
Min is: 0A0A0A0A0A (28232883707050) ; Max id: Z9Z9Z9Z9Z9 (3582752942424645) .
Values YZYZYZYZYZ (3554520058717595) .
public staticfunctionuuid_10_seq (
) {} :: STRING
@return: {STRING} the UUID
Intended usage: Large scale.
Generates a random string (base36) UUID of 10 characters [0..9A..Z] ; Example: 0G1G74W362 .
Intended usage: Medium scale / Sequential / Non-Repeating (never repeats in a period cycle of 1000 years).
This is sequential, date and time based with miliseconds and a randomizer factor to ensure an ~ unique ID.
Duplicate values can occur just in the same milisecond (1000 miliseconds = 1 second) with a chance of ~ 3%
Values: 34 k / sec ; 200 k / min ; 120 mil / hour .
Advantages: This is one of the most powerful UUID system for medium scale as the ID will never repeat in a large period of time.
Compared with the classic autoincremental IDs this UUID is much better as on the next cycle can fill up unallocated
values and more, because the next cycle occur after so many time there is no risk to re-use some IDs if they were
previous deleted or deactivated in terms of generating confusions with previous records.
The classic autoincremental systems can NOT do this and also, once the max ID is reached the DB table is blocked
as autoincremental records reach the max ID !!!
Disadvantages: The database connectors require more complexity and must be able to retry within a cycle with
double check before alocating, such UUIDs and must use a pre-alocation table since the UUIDs are time based and if
in the same milisecond more than 1 inserts is allocated they can conflict each other without such pre-alocation !
Smart.Framework implements the retry + cycle + pre-alocating table as a standard feature
in the bundled PostgreSQL library (connector/plugin) as PostgreSQL can do DDLs in transactions.
Using such functionality with MySQL would be tricky as DDLs will break the transactions, but still usable ;-).
And for SQLite it does not make sense since SQLite is designed for small DBs thus no need for such high scalability ...
public staticfunctionuuid_12_seq (
) {} :: STRING
@return: {STRING} the UUID
Intended usage: Large scale, in a cluster.
Generates a random string (base62) UUID of 12 characters [0..9a..zA..Z] ; Example: 0K4M6V04JM01 .
It is based on Smart::uuid_10_seq() but will append the last two characters in base36 00..ZZ using Smart::net_server_id(true) that represent the Net Server ID in a cluster.
To set the Net Server ID as unique per each running instance of Smart.Framework under the same domain,
set the constant SMART_FRAMEWORK_NETSERVER_ID in etc/init.php with a number between 0..1295 to have a unique number for each instance of Smart.Framework
where supposed all this instances will run in a cluster.
If there is only one instance running and no plans at all to implement a multi-server cluster, makes non-sense to use this function, use instead the Smart::uuid_10_seq()
For how is implemented, read the documentation for the functions: Smart::uuid_10_seq() and Smart::net_server_id(true)
public staticfunctionuuid_13_seq (
) {} :: STRING
@return: {STRING} the UUID
Intended usage: Very Large scale. Case sensitive.
Generates a random string (base62) UUID of 13 characters [0..9a..zA..Z] ; Example: 00wA0whhw2e9L .
Intended usage: Very Large scale / Sequential / Non-Repeating (never repeats in a period cycle of 9999999 years).
This is sequential, date and time based with miliseconds and a randomizer factor to ensure an ~ unique ID.
Duplicate values can occur just in the same milisecond (1000 miliseconds = 1 second) with a chance of ~ 0.3%
Values: 340000 k / sec ; 2000000 k / min ; 1200000 mil / hour .
Advantages: This is one of the most powerful UUID system for large scale as the ID will never repeat in a huge period of time.
Compared with the classic autoincremental IDs this UUID is much better as on the next cycle can fill up unallocated
values and more, because the next cycle occur after so many time there is no risk to re-use some IDs if they were
previous deleted or deactivated in terms of generating confusions with previous records.
The classic autoincremental systems can NOT do this and also, once the max ID is reached the DB table is blocked
as autoincremental records reach the max ID !!!
Disadvantages: The database connectors require more complexity and must be able to retry within a cycle with
double check before alocating, such UUIDs and must use a pre-alocation table since the UUIDs are time based and if
in the same milisecond more than 1 inserts is allocated they can conflict each other without such pre-alocation !
Smart.Framework implements the retry + cycle + pre-alocating table as a standard feature
in the bundled PostgreSQL library (connector/plugin) as PostgreSQL can do DDLs in transactions.
Using such functionality with MySQL would be tricky as DDLs will break the transactions, but still usable ;-).
And for SQLite it does not make sense since SQLite is designed for small DBs thus no need for such high scalability ...
public staticfunctionuuid_15_seq (
) {} :: STRING
@return: {STRING} the UUID
Intended usage: Very Large scale, in a cluster. Case sensitive.
Generates a random string (base62) UUID of 15 characters [0..9a..zA..Z] ; Example: 00wA0whhw2e9L01 .
It is based on Smart::uuid_13_seq() but will append the last two characters in base36 00..ZZ using Smart::net_server_id(true) that represent the Net Server ID in a cluster.
To set the Net Server ID as unique per each running instance of Smart.Framework under the same domain,
set the constant SMART_FRAMEWORK_NETSERVER_ID in etc/init.php with a number between 0..1295 to have a unique number for each instance of Smart.Framework
where supposed all this instances will run in a cluster.
If there is only one instance running and no plans at all to implement a multi-server cluster, makes non-sense to use this function, use instead the Smart::uuid_13_seq()
For how is implemented, read the documentation for the functions: Smart::uuid_13_seq() and Smart::net_server_id(true)
public staticfunctionuuid_32 (
) {} :: STRING
@return: {STRING} the UUID
Generates an almost unique BASE36 based UUID of 32 characters [0..9A..Z] ; Example: Y123AY7WK5-9187139702-Z98W7T091K .
This compose as: Smart::uuid_10_seq().'-'.Smart::uuid_10_num().'-'.Smart::uuid_10_str()
Intended usage: Very Large scale.
public staticfunctionuuid_34 (
) {} :: STRING
@return: {STRING} the UUID
Generates an almost unique BASE36 based UUID of 34 characters [0..9A..Z] ; Example: Y123AY7WK501-9187139702-Z98W7T091K .
This compose as: Smart::uuid_12_seq().'-'.Smart::uuid_10_num().'-'.Smart::uuid_10_str()
Intended usage: Very Large scale, in a cluster.
public staticfunctionuuid_35 (
) {} :: STRING
@return: {STRING} the UUID
Generates an almost unique BASE62 + BASE36 based UUID of 35 characters [0..9a..zA..Z] ; Example: 00wA0whhw2e9L-9187139702-Z98W7T091K .
This compose as: Smart::uuid_13_seq().'-'.Smart::uuid_10_num().'-'.Smart::uuid_10_str()
Intended usage: Extremely Large scale. Case sensitive.
public staticfunctionuuid_37 (
) {} :: STRING
@return: {STRING} the UUID
Generates an almost unique BASE62 + BASE36 based UUID of 37 characters [0..9a..zA..Z] ; Example: 00wA0whhw2e9L01-9187139702-Z98W7T091K .
This compose as: Smart::uuid_15_seq().'-'.Smart::uuid_10_num().'-'.Smart::uuid_10_str()
Intended usage: Extremely Large scale, in a cluster. Case sensitive.
public staticfunctionuuid_36 (
string$prefix = ""
) {} :: STRING
@return: {STRING} the UUID
@param: {STRING} $prefix: A prefix to use for more uniqueness entropy ; Ex: can use the Smart::net_server_id()
Generates an almost unique MD5 based UUID of 36 characters [0..9a..f] ; Example: cfcb6c2a-a6e0-f539-141d-083abee19a4e .
The uniqueness of this is based on a full unique signature in space and time: 2 random UUIDS, server name, year/day/month hour:minute:seconds, time, microseconds, a random value 0...9999 .
For the same time moment, duplicates values can occur with a chance of 1 in ~ a 340282366920938586008062602462446642046 .
The Net Server ID can be passed via the $prefix parameter
Intended usage: Large scale. Standard.
public staticfunctionuuid_45 (
string$prefix = ""
) {} :: STRING
@return: {STRING} the UUID
@param: {STRING} $prefix: A prefix to use for more uniqueness entropy ; Ex: can use the Smart::net_server_id()
Generates an almost unique SHA1 based UUID of 45 characters [0..9a..f] ; Example: c02acc84-97f4-0807-b12c-ed6f28dd2078-400c1baf .
The uniqueness of this is based on a full unique signature in space and time: 2 random UUIDS, server name, year/day/month hour:minute:seconds, time, microseconds, a random value 0...9999 .
For the same time moment, duplicates values can occur with a chance of 1 in ~ a 1461501637330903466848266086008062602462446642046 .
The Net Server ID can be passed via the $prefix parameter
Intended usage: Large scale. Standard.
public staticfunctionurl_parse (
string$y_url
) {} :: ARRAY
@return: {ARRAY} The separed URL (associative array) as: protocol, server, port, path, scriptname
@param: {STRING} $y_url: The URL to be separed
Safe Parse URL :: a better replacement for parse_url()
public staticfunctionarray_to_list (
ARRAY$y_arr
) {} :: STRING
@return: {STRING} The List String: '<elem1>, <elem2>, ..., <elemN>'
@param: {ARRAY} $y_arr: The Array to be converted: Array(elem1, elem2, ..., elemN)
@return: {ARRAY} The Array: Array(elem1, elem2, ..., elemN)
@param: {STRING} $y_list: The List String to be converted: '<elem1>, <elem2>, ..., <elemN>'
@param: {BOOLEAN} $y_trim: *Optional* default is TRUE ; If set to FALSE will not trim the values in the list
Convert a List String to Array
public staticfunctionlog_info (
string$title,
string$message
) {} :: VOID
@return: {-} This function does not return anything
@param: {STRING} $title: The title of the message to be logged
@param: {STRING} $message: The message to be logged
The Info logger.
This will add messages to the App Info Log. (depending if on admin or index, will output into 'tmp/logs/adm/' or 'tmp/logs/idx/')
public staticfunctionlog_notice (
string$message
) {} :: VOID
@return: {-} This function does not return anything
@param: {STRING} $message: The message to be triggered
A quick replacement for trigger_error() / E_USER_NOTICE.
This is intended to log APP Level Notices.
This will log the message as NOTICE into the App Error Log.
Notices are logged ONLY for Development Environment (and NOT for Production Environment)
public staticfunctionlog_warning (
string$message
) {} :: VOID
@return: {-} This function does not return anything
@param: {STRING} $message: The message to be triggered
A quick replacement for trigger_error() / E_USER_WARNING.
This is intended to log APP Level Warnings.
This will log the message as WARNING into the App Error Log.
@return: {-} This function does not return anything
@param: {STRING} $message_to_log: The message to be triggered
@param: {STRING} $message_to_display: *Optional* the message to be displayed (must be html special chars safe)
A quick replacement for trigger_error() / E_USER_ERROR.
This is intended to log APP Level Errors.
This will log the message as ERROR into the App Error Log and stop the execution (also in the Smart Error Handler will raise a HTTP 500 Code).