U
class U
Some really small, simple, and self-contained utility public static functions
Methods
No description
No description
No description
No description
Produce a Python-style get() to avoid use of ternary operator
No description
No description
No description
No description
No description
No description
Get the last bit of the path
Get the protocol, host, and port from an absolute URL
Get the path to the current request, w/o trailing slash
Get the path to one above the current request, w/o trailing slash
Get the controller for the current request
Return a rest-path
No description
No description
No description
No description
No description
Remove any relative elements from a path
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
Return the URL as seen by PHP (no query string or parameters)
Tightly serialize an integer-only PHP array
No description
Deserialize an tightly serialized integer-only PHP array
Pull off the first element of a key/value array
No description
No description
No description
Give the current time in the "conversion format"
No description
Return if APC cache is available (Deprecated)
Return if APCU cache is available
No description
No description
No description
No description
No description
Create a unique GUID return string
No description
No description
Validate a CSS color value
Build a PHP 7 strlen for PHP 8.2 and later
Determine if a variable is empty
Imitate StringUtils.isNotEmpty()
Check if a key in an array is not empty
Make an htmlentities() that is more tolerant than the PHP 8.2 version.
Build an "always works" json_decode()
Details
at line 10
static
die_with_error_log($msg, $extra = false, $prefix = "DIE:")
at line 16
static
echo_log($msg)
at line 21
static
session_safe_id()
at line 26
static
print_stack_trace()
at line 36
static
get($arr, $key, $default = null)
Produce a Python-style get() to avoid use of ternary operator
at line 43
static
htmlpre_utf8($string)
at line 47
static
htmlspec_utf8($string)
at line 52
static
htmlent_utf8($string)
at line 57
static
safe_href($string)
at line 64
static
lti_sha256($val)
at line 69
static
route_get_local_path($dir)
at line 86
static
get_request_document()
Get the last bit of the path
input: /py4e/lessons/intro?x=2 output: intro
at line 104
static
get_base_url($url)
Get the protocol, host, and port from an absolute URL
input: http://localhost:8888/tsugi output: http://localhost:8888
at line 121
static
get_rest_path($uri = false)
Get the path to the current request, w/o trailing slash
input: /py4e/lessons/intro?x=2 output: /py4e/lessons/intro
input: /py4e/lessons/intro/?x=2 output: /py4e/lessons/intro
at line 141
static
get_rest_parent($uri = false)
Get the path to one above the current request, w/o trailing slash
input: /py4e/lessons/intro?x=2 output: /py4e/lessons
input: /py4e/lessons/intro/?x=2 output: /py4e/lessons/intro
at line 168
static
parse_rest_path($uri = false, $SERVER_SCRIPT_NAME = false)
Get the controller for the current request
executing script: /py4e/koseu.php input: /py4e/lessons/intro?x=2 output: (/py4e, lessons, intro)
input: /py4e/lessons/intro/?x=2 output: /py4e/lessons/intro
at line 229
static
rest_path($uri = false, $SERVER_SCRIPT_NAME = false)
Return a rest-path
This knows the current working folder we are in. The model is that a folder is an "application" with many possible controllers and within each controller there are actions followed by parameters.
for example, assume these files exist in a folder:
../tsugi/mod/zap/index.php
../tsugi/mod/zap/rows.php
../tsugi/mod/zap/store.php
If this URL were called with .htaccess and tsugi.php set up, rows.php would be run and this would be the output:
http://localhost:8888/tsugi/mod/zap/rows/add/1/2
base_url: http://localhost:8888
parent: /tsugi/mod/zap
current: /tsugi/mod/zap/rows
controller: rows
action: add
parameters: (1, 2)
full: /tsugi/mod/zap/rows/add/1/2
As a special case, when the index.php runs (not through tsugi.php) The results are as follows:
http://localhost:8888/tsugi/mod/zap/
base_url: http://localhost:8888
parent: /tsugi/mod/zap
current: /tsugi/mod/zap
controller: empty string
action: empty string
parameters: empty array
full: /tsugi/mod/zap
at line 262
static
addSession($url, $force = false)
at line 286
static
reconstruct_query($baseurl, $newparms = false)
at line 299
static
add_url_parm($url, $key, $val)
at line 306
static
absolute_url_ref($url)
at line 310
static
absolute_url($url)
at line 329
static
remove_relative_path($path)
Remove any relative elements from a path
Before After a/b/c a/b/c a/b/c/ a/b/c/ a/./c/ a/c/ a/../c/ c/
at line 346
static
apache_request_headers()
at line 361
static
http_response_code($newcode = NULL)
at line 373
static
isCli()
at line 381
static
lmsDie($message = false)
at line 397
static
line_out($output)
at line 402
static
error_out($output)
at line 407
static
success_out($output)
at line 413
static
startsWith($haystack, $needle)
at line 418
static
endsWith($haystack, $needle)
at line 423
static
goodFolder($folder)
at line 427
static
conservativeUrl($url)
at line 442
static
curPHPUrl()
Return the URL as seen by PHP (no query string or parameters)
Borrowed from from_request on OAuthRequest.php
at line 466
static
array_Integer_Serialize($arar)
Tightly serialize an integer-only PHP array
$arar = Array ( 1 => 42 ,2 => 43, 3 => 44 ); $str = U::array_Integer_Serialize($arar); echo($str); // 1=42,2=43,3=44
https://stackoverflow.com/questions/30231476/i-want-to-array-key-and-array-value-comma-separated-string
at line 471
static
array_Integer_Serialize_Map($a, $b)
at line 488
static
array_Integer_Deserialize($input)
Deserialize an tightly serialized integer-only PHP array
$str = '1=42,2=43,3=44'; $arar = U::array_Integer_Deserialize($str); print_r($arar); // Array ( '1' => 42 ,'2' => 43, '3' => 44 );
https://stackoverflow.com/questions/4923951/php-split-string-in-key-value-pairs
at line 519
static
array_kshift($arr)
Pull off the first element of a key/value array
$arr = array('x'=>'ball','y'=>'hat','z'=>'apple'); print_r($arr); print_r(array_kshift($arr)); // [x] => ball print_r($arr);
http://php.net/manual/en/function.array-shift.php#84179
at line 535
static
allow_track()
at line 546
static
safe_var_dump($x)
at line 557
static
safe_array($inp)
at line 573
static
conversion_time($time = "now")
Give the current time in the "conversion format"
201711261315
at line 579
static
iso8601($time = "now")
at line 588
static
apcAvailable()
Return if APC cache is available (Deprecated)
at line 596
static
apcuAvailable()
Return if APCU cache is available
at line 601
static
appCacheGet($key, $default = null)
at line 609
static
appCacheSet($key, $value, $ttl = 0)
at line 615
static
appCacheDelete($key)
at line 631
static
getCaller($count = 1)
at line 652
static
displaySize($size)
at line 671
static
createGUID()
Create a unique GUID return string
https://www.texelate.co.uk/blog/create-a-guid-with-php
at line 693
static
isGUIDValid($guid)
at line 698
static
getServerBase($url)
at line 710
static
isValidCSSColor($color)
Validate a CSS color value
at line 725
static
strlen($string)
Build a PHP 7 strlen for PHP 8.2 and later
This is needed because in PHP 8.2 strlen() demands a string (i.e. can't handle false, etc)
at line 746
static
isEmpty($string)
Determine if a variable is empty
This is needed because in PHP 8.2 strlen() demands a string (i.e. can't handle false, etc) Sadly, empty('0') becomes falsey and so returns true - What??
The method name is taken from Java since its rules are corect.
https://docs.oracle.com/javase/8/docs/api/java/lang/String.html#isEmpty--
at line 760
static
isNotEmpty($string)
Imitate StringUtils.isNotEmpty()
Sigh, Java 8.0 does not have isNotEmpty - which is super useful so we imitate
https://commons.apache.org/proper/commons-lang/javadocs/api-3.3/org/apache/commons/lang3/StringUtils.html
It is the little things - sigh.
at line 767
static
isKeyNotEmpty(array $collection, string $key)
Check if a key in an array is not empty
at line 776
static
escapeHtml($string)
Make an htmlentities() that is more tolerant than the PHP 8.2 version.
https://commons.apache.org/proper/commons-text/apidocs/org/apache/commons/text/StringEscapeUtils.html
at line 787
static
json_decode($string)
Build an "always works" json_decode()
This is needed because in PHP 8.2 json_decode() demands a string (i.e. can't handle false, etc)