diff --git a/www/admin/class_test.php b/www/admin/class_test.php index 7c8e68c6..2de50470 100644 --- a/www/admin/class_test.php +++ b/www/admin/class_test.php @@ -1,4 +1,7 @@ dbInfo(1); +$basic->dbInfo(true); ob_end_flush(); echo "DB_CONFIG_SET constant:
".print_r(DB_CONFIG, true)."
tag added
+ */
public static function printAr(array $array): string
{
return "".print_r($array, true)."
";
@@ -874,6 +884,10 @@ class Basic
// PARAMS: none
// RETURN: none
// DESC : sets the random key range with the default values
+ /**
+ * sets the random key range with the default values
+ * @return void has no return
+ */
private function initRandomKeyData()
{
// random key generation
@@ -884,10 +898,11 @@ class Basic
$this->key_length = 4;
}
- // METHOD: validateRandomKeyLenght
- // PARAMS: int key length
- // RETURN: true for valid, false for invalid length
- // DESC : validates they key length
+ /**
+ * validates they key length for random string generation
+ * @param int $key_length key length
+ * @return bool true for valid, false for invalid length
+ */
private function validateRandomKeyLenght(int $key_length): bool
{
if (is_numeric($key_length) &&
@@ -900,11 +915,12 @@ class Basic
}
}
- // METHOD: initRandomKeyLength
- // PARAMS: key length in int
- // RETURN: true/false for set status
- // DESC : sets the key length and checks that they key given is valid
- // if failed it will not change the default key length and return false
+ /**
+ * sets the key length and checks that they key given is valid
+ * if failed it will not change the default key length and return false
+ * @param int $key_length key length
+ * @return bool true/false for set status
+ */
public function initRandomKeyLength(int $key_length): bool
{
// only if valid int key with valid length
@@ -916,12 +932,13 @@ class Basic
}
}
- // METHOD: randomKeyGen
- // PARAMS: key length override, -1 for use default
- // RETURN: random key
- // DESC : creates a random key based on the key_range with key_length
- // if override key length is set, it will check on valid key and use this
- // this will not set the class key length variable
+ /**
+ * creates a random key based on the key_range with key_length
+ * if override key length is set, it will check on valid key and use this
+ * this will not set the class key length variable
+ * @param int $key_length key length override, -1 for use default
+ * @return string random key
+ */
public function randomKeyGen(int $key_length = -1): string
{
$use_key_length = 0;
@@ -945,14 +962,15 @@ class Basic
// ****** RANDOM KEY GEN ******
- // METHOD: checked
- // PARAMS: haystack (search in) haystack can be an array or a string
- // needle (search for)
- // type: 0: returns selected, 1, returns checked
- // RETURN: returns checked or selected, else returns nothing (empty return)
- // DESC : returns 'checked' or 'selected' if okay
- // $needle is a var, $haystack an array
- // **** THE RETURN: VALUE WILL CHANGE TO A DEFAULT NULL IF NOT FOUND ****
+ /**
+ * returns 'checked' or 'selected' if okay
+ * $needle is a var, $haystack an array or a string
+ * **** THE RETURN: VALUE WILL CHANGE TO A DEFAULT NULL IF NOT FOUND ****
+ * @param array|string $haystack (search in) haystack can be an array or a string
+ * @param string $needle needle (search for)
+ * @param int $type type: 0: returns selected, 1, returns checked
+ * @return ?string returns checked or selected, else returns null
+ */
public static function checked($haystack, $needle, int $type = 0): ?string
{
if (is_array($haystack)) {
@@ -967,13 +985,14 @@ class Basic
return null;
}
- // METHOD: magicLinks
- // WAS : magic_links
- // PARAMS: string: data to transform to a valud HTML url, target: default _blank
- // RETURN: correctly formed html url link
- // DESC : tries to find mailto:user@bubu.at and changes it into -> E-Mail senden
- // or tries to take any url (http, ftp, etc) and transform it into a valid URL
- // the string is in the format: some url|name#css|, same for email
+ /**
+ * tries to find mailto:user@bubu.at and changes it into -> E-Mail senden
+ * or tries to take any url (http, ftp, etc) and transform it into a valid URL
+ * the string is in the format: some url|name#css|, same for email
+ * @param string $string data to transform to a valud HTML url
+ * @param string $target target string, default _blank
+ * @return string correctly formed html url link
+ */
public function magicLinks(string $string, string $target = "_blank"): string
{
$output = $string;
@@ -1037,15 +1056,18 @@ class Basic
return $output;
}
- // METHOD: createUrl [INTERNAL]
- // WAS : create_url
- // PARAMS: url link, anchor tag (define both type or url),
- // _1, _2, _3 = part of thel URL, if atag is set, _1 is not used
- // target: link target, name: name for the url, if not given _2 + _3 is used
- // class: style sheet
- // RETURN: correct string for url href process
- // DESC : internal function, called by the magic url create functions.
- // checks if title $_4 exists, if not, set url as title
+ /**
+ * internal function, called by the magic url create functions.
+ * checks if title $_4 exists, if not, set url as title
+ * @param string $href url link
+ * @param string $atag anchor tag (define both type or url)
+ * @param string $_1 part of the URL, if atag is set, _1 is not used
+ * @param string $_2 part of the URL
+ * @param string $_3 part of the URL
+ * @param string $name name for the url, if not given _2 + _3 is used
+ * @param string $class style sheet
+ * @return string correct string for url href process
+ */
private function createUrl($href, $atag, $_1, $_2, $_3, $name, $class): string
{
// $this->debug('URL', "1: $_1 - 2: $_2 - $_3 - atag: $atag - name: $name - class: $class");
@@ -1066,13 +1088,17 @@ class Basic
}
}
- // METHOD: createEmail [INTERNAL]
- // WAS : create_email
- // PARAMS: email address, atag (define type of url)
- // _1, _2, _3: parts of the email _1 before @, _2 after @, 3_ tld
- // title: name for the link, if not given use email
- // class: style sheet
- // DESC : internal function for createing email, returns data to magic_url method
+ /**
+ * internal function for createing email, returns data to magic_url method
+ * @param string $mailto email address
+ * @param string $atag atag (define type of url)
+ * @param string $_1 parts of the email _1 before @, 3_ tld
+ * @param string $_2 _2 domain part after @
+ * @param string $_3 _3 tld
+ * @param string $title name for the link, if not given use email
+ * @param string $class style sheet
+ * @return string created html email a href string
+ */
private function createEmail($mailto, $atag, $_1, $_2, $_3, $title, $class)
{
$email = $_1."@".$_2.".".$_3;
@@ -1085,11 +1111,10 @@ class Basic
}
}
- // METHOD: getHostName
- // WAS : get_host_name
- // PARAMS: none
- // RETURN: host name
- // DESC : get the host name without the port as given by the SELF var
+ /**
+ * get the host name without the port as given by the SELF var
+ * @return string host name
+ */
public function getHostName(): string
{
$port = '';
@@ -1106,13 +1131,13 @@ class Basic
return $host_name;
}
- // METHOD: getPageName
- // WAS : get_page_name
- // PARAMS: 1: strip page file name extension
- // 0: keep filename as is
- // 2: keep filename as is, but add dirname too
- // RETURN: filename
- // DESC : get the page name of the curronte page:
+ /**
+ * get the page name of the curronte page
+ * @param int $strip_ext 1: strip page file name extension
+ * 0: keep filename as is
+ * 2: keep filename as is, but add dirname too
+ * @return string filename
+ */
public static function getPageName(int $strip_ext = 0): string
{
// get the file info
@@ -1126,25 +1151,25 @@ class Basic
}
}
- // METHOD: getFilenameEnding
- // WAS : get_filename_ending
- // PARAMS: filename
- // RETURN: extension of the file name
- // DESC : quick return the extension of the given file name
+ /**
+ * quick return the extension of the given file name
+ * @param string $filename file name
+ * @return string extension of the file name
+ */
public static function getFilenameEnding(string $filename): string
{
$page_temp = pathinfo($filename);
return $page_temp['extension'];
}
- // METHOD: arraySearchRecursive
- // WAS : array_search_recursive
- // PARAMS: needle (search for)
- // haystack (search in)
- // key_lookin: the key to look out for, default empty
- // RETURN: array with the elements where the needle can be found in the haystack array
- // DESC : searches key = value in an array / array
- // only returns the first one found
+ /**
+ * searches key = value in an array / array
+ * only returns the first one found
+ * @param string|int $needle needle (search for)
+ * @param array $haystack haystack (search in)
+ * @param string $key_lookin the key to look out for, default empty
+ * @return ?array array with the elements where the needle can be found in the haystack array
+ */
public static function arraySearchRecursive($needle, array $haystack, $key_lookin = ''): ?array
{
$path = array ();
@@ -1173,14 +1198,14 @@ class Basic
return $path;
}
- // METHOD: arraySearchRecursiveAll
- // WAS : array_search_recursive_all
- // PARAMS: needle (search for)
- // haystack (search in)
- // key: the key to look for in
- // path: recursive call for previous path
- // RETURN: all array elements paths where the element was found
- // DESC : recursive array search function, which returns all found not only the first one
+ /**
+ * recursive array search function, which returns all found not only the first one
+ * @param string|int $needle needle (search for)
+ * @param array $haystack haystack (search in)
+ * @param string|int $key the key to look for in
+ * @param array $path recursive call for previous path
+ * @return ?array all array elements paths where the element was found
+ */
public static function arraySearchRecursiveAll($needle, array $haystack, $key, $path = null): ?array
{
if (!isset($path['level'])) {
@@ -1219,11 +1244,13 @@ class Basic
return $path;
}
- // METHOD: arraySearchSimple
- // WAS : array_search_simple
- // PARAMS: array (search in), key (key to search in), value (what to find
- // RETURN: true on found, false on not found
- // DESC : array search simple. looks for key, value combination, if found, returns true
+ /**
+ * array search simple. looks for key, value combination, if found, returns true
+ * @param array $array array (search in)
+ * @param string|int $key key (key to search in)
+ * @param string|int $value value (what to find)
+ * @return bool true on found, false on not found
+ */
public static function arraySearchSimple(array $array, $key, $value): bool
{
if (!is_array($array)) {
@@ -1244,17 +1271,21 @@ class Basic
return false;
}
- // METHOD: arrayMergeRecursive
- // PARAMS: array, array, ..., true/false flag how to handle key
- // key flag: true: handle keys as string or int, default false: all keys are string
- // RETURN: merged array
- // DESC : correctly recursive merges as an array as array_merge_recursive just glues things together
+ /**
+ * correctly recursive merges as an array as array_merge_recursive just glues things together
+ * array first array to merge
+ * array second array to merge
+ * ... etc
+ * bool key flag: true: handle keys as string or int
+ * default false: all keys are string
+ * @return array|bool merged array
+ */
public static function arrayMergeRecursive()
{
// croak on not enough arguemnts (we need at least two)
if (func_num_args() < 2) {
trigger_error(__FUNCTION__ .' needs two or more array arguments', E_USER_WARNING);
- return;
+ return false;
}
// default key is not string
$key_is_string = false;
@@ -1268,14 +1299,14 @@ class Basic
// check that arrays count is at least two, else we don't have enough to do anything
if (count($arrays) < 2) {
trigger_error(__FUNCTION__.' needs two or more array arguments', E_USER_WARNING);
- return;
+ return false;
}
$merged = array();
while ($arrays) {
$array = array_shift($arrays);
if (!is_array($array)) {
trigger_error(__FUNCTION__ .' encountered a non array argument', E_USER_WARNING);
- return;
+ return false;
}
if (!$array) {
continue;
@@ -1297,12 +1328,121 @@ class Basic
return $merged;
}
- // METHOD: arrayFlatForKey
- // PARAMS: array (nested)
- // search, key to find that has no sub leaf and will be pushed up
- // RETURN: modified array
- // DESC : searches for key -> value in an array tree and writes the value one level up
- // this will remove this leaf will all other values
+ /**
+ * search for the needle array elements in haystack and return the ones found as an array,
+ * is there nothing found, it returns FALSE (boolean)
+ * @param array $needle elements to search for
+ * @param array $haystack array where the $needle elements should be searched int
+ * @return array|bool either the found elements or false for nothing found or error
+ */
+ public static function inArrayAny(array $needle, array $haystack)
+ {
+ if (!is_array($needle)) {
+ return false;
+ }
+ if (!is_array($haystack)) {
+ return false;
+ }
+ $found = array ();
+ foreach ($needle as $element) {
+ if (in_array($element, $haystack)) {
+ $found[] = $element;
+ }
+ }
+ if (count($found) == 0) {
+ return false;
+ } else {
+ return $found;
+ }
+ }
+
+ /**
+ * creates out of a normal db_return array an assoc array
+ * @param array $db_array return array from the database
+ * @param string|int|bool $key key set, false for not set
+ * @param string|int|bool $value value set, false for not set
+ * @param bool $set_only flag to return all (default), or set only
+ * @return array associative array
+ */
+ public static function genAssocArray(array $db_array, $key, $value, bool $set_only = false): array
+ {
+ $ret_array = array ();
+ // do this to only run count once
+ for ($i = 0, $iMax = count($db_array); $i < $iMax; $i ++) {
+ // if no key then we make an order reference
+ if ($key !== false &&
+ $value !== false &&
+ (($set_only && $db_array[$i][$value]) || (!$set_only))
+ ) {
+ $ret_array[$db_array[$i][$key]] = $db_array[$i][$value];
+ } elseif ($key === false && $value !== false) {
+ $ret_array[] = $db_array[$i][$value];
+ } elseif ($key !== false && $value === false) {
+ $ret_array[$db_array[$i][$key]] = $i;
+ }
+ }
+ return $ret_array;
+ }
+
+ /**
+ * [NOTE]: This is an old function and is deprecated
+ * wrapper for join, but checks if input is an array and if not returns null
+ * @param array $array array to convert
+ * @param string $connect_char connection character
+ * @return string joined string
+ * @deprecated use join() instead
+ */
+ public static function arrayToString(array $array, string $connect_char): string
+ {
+ trigger_error('Method '.__METHOD__.' is deprecated, use join()', E_USER_DEPRECATED);
+ if (!is_array($array)) {
+ $array = array ();
+ }
+ return join($connect_char, $array);
+ }
+
+ /**
+ * converts multi dimensional array to a flat array
+ * does NOT preserve keys
+ * @param array $array ulti dimensionial array
+ * @return array flattened array
+ */
+ public static function flattenArray(array $array): array
+ {
+ $return = array ();
+ array_walk_recursive(
+ $array,
+ function ($value) use (&$return) {
+ $return[] = $value;
+ }
+ );
+ return $return;
+ }
+
+ /**
+ * will loop through an array recursivly and write the array keys back
+ * @param array $array multidemnsional array to flatten
+ * @return array flattened keys array
+ */
+ public static function flattenArrayKey(array $array/*, array $return = array ()*/): array
+ {
+ $return = array ();
+ array_walk_recursive(
+ $array,
+ function ($value, $key) use (&$return) {
+ $return [] = $key;
+ }
+ );
+ return $return;
+ }
+
+ /**
+ * searches for key -> value in an array tree and writes the value one level up
+ * this will remove this leaf will all other values
+ * @param array $array array (nested)
+ * @param string|int $search key to find that has no sub leaf and will be pushed up
+ * @return array modified, flattened array
+ */
public static function arrayFlatForKey(array $array, $search): array
{
if (!is_array($array)) {
@@ -1325,107 +1465,12 @@ class Basic
return $array;
}
- // METHOD: inArrayAny
- // WAS : in_array_any
- // PARAMS: needle: array
- // haystack: array
- // RETURN: found elements: array
- // DESC : search for the needle array elements in haystack and return the ones found as an array,
- // is there nothing found, it returns FALSE (boolean)
- public static function inArrayAny($needle, array $haystack)
- {
- if (!is_array($needle)) {
- return false;
- }
- if (!is_array($haystack)) {
- return false;
- }
- $found = array ();
- foreach ($needle as $element) {
- if (in_array($element, $haystack)) {
- $found[] = $element;
- }
- }
- if (count($found) == 0) {
- return false;
- } else {
- return $found;
- }
- }
-
- // METHOD: genAssocArray
- // WAS : GenAssocArray
- // PARAMS: db array, key, value part, flag if set all or only set
- // RETURN: returns and associative array
- // DESC : creates out of a normal db_return array an assoc array
- public static function genAssocArray(array $db_array, $key, $value, bool $set_only = false): array
- {
- $ret_array = array ();
- // do this to only run count once
- for ($i = 0, $iMax = count($db_array); $i < $iMax; $i ++) {
- // if no key then we make an order reference
- if ($key && $value && (($set_only && $db_array[$i][$value]) || (!$set_only))) {
- $ret_array[$db_array[$i][$key]] = $db_array[$i][$value];
- } elseif (!$key && $value) {
- $ret_array[] = $db_array[$i][$value];
- } elseif ($key && !$value) {
- $ret_array[$db_array[$i][$key]] = $i;
- }
- }
- return $ret_array;
- }
-
- // METHOD: arrayToString
- // WAS : ArrayToString
- // PARAMS: array, connect char
- // RETRUN: string
- // DESC : wrapper for join, but checks if input is an array and if not returns null
- public static function arrayToString(array $array, string $connect_char): string
- {
- if (is_array($array)) {
- $array = array ();
- }
- return join($connect_char, $array);
- }
-
- // METHOD: flattenArray
- // PARAMS: array in multi dimensions
- // RETURN: returns a flatten array
- // DESC : converts multi dimensional array to a flat array
- // does NOT preserve keys
- public static function flattenArray(array $array): array
- {
- $return = array ();
- array_walk_recursive(
- $array,
- function ($a) use (&$return) {
- $return[] = $a;
- }
- );
- return $return;
- }
-
- // METHOD: flattenArrayKey
- // PARAMS: the array to flatten
- // RETURN: flattened array with array keys as values in order of tree
- // DESC : note: the second parameter $return is automatically set
- // will loop through an array recursivly and write the array keys back
- public static function flattenArrayKey(array $array, array $return = array ()): array
- {
- foreach ($array as $key => $sub) {
- $return[] = $key;
- if (count($sub) > 0) {
- $return = Basic::flattenArrayKey($sub, $return);
- }
- }
- return $return;
- }
-
- // METHOD: __mbMimeEncode
- // WAS : _mb_mime_encode
- // PARAMS: string to encode, encoding to encode in
- // RETURN: encoded string
- // DESC : wrapper function for mb mime convert, for correct conversion with long strings
+ /**
+ * wrapper function for mb mime convert, for correct conversion with long strings
+ * @param string $string string to encode
+ * @param string $encoding target encoding
+ * @return string encoded string
+ */
public static function __mbMimeEncode(string $string, string $encoding): string
{
// set internal encoding, so the mimeheader encode works correctly
@@ -1455,11 +1500,12 @@ class Basic
return $string;
}
- // METHOD: byteStringFormat
- // WAS : ByteStringFormat
- // PARAMS: int bytes, boolean for space, default is set
- // RETURN: string
- // DESC : converts bytes into formated string with KB, MB, etc
+ /**
+ * converts bytes into formated string with KB, MB, etc
+ * @param string|int|float $number bytes as string int or pure int
+ * @param bool $space true (default) to add space between number and suffix
+ * @return string converted byte number (float) with suffix
+ */
public static function byteStringFormat($number, bool $space = true): string
{
if (is_numeric($number) && $number > 0) {
@@ -1471,13 +1517,14 @@ class Basic
return (string)$number;
}
- // METHOD: stringByteFormat
- // WAS : StringByteFormat
- // PARAMS: some string with byte info, flag if the number is . or , thousand notaded
- // RETURN: int or string as is if not mathcing
- // DESC : calculates the bytes based on a string with nnG, nnGB, nnM, etc
- // if the number has a non standard thousand seperator , inside, the second
- // flag needs to be set true (eg german style notaded numbers)
+ /**
+ * calculates the bytes based on a string with nnG, nnGB, nnM, etc
+ * if the number has a non standard thousand seperator ","" inside, the second
+ * flag needs to be set true (eg german style notaded numbers)
+ * @param string|int|float $number any string or number to convert
+ * @param bool $dot_thousand default is ".", set true for ","
+ * @return string|int|float converted value or original value
+ */
public static function stringByteFormat($number, bool $dot_thousand = false)
{
// detects up to exo bytes
@@ -1524,26 +1571,30 @@ class Basic
return $number;
}
- // METHOD: dateStringFormat
- // WAS : DateStringFormat
- // PARAMS: unix timestamp, true/false to show microtime
- // RETURN: string formated date+time in Y-M-D h:m:s
- // DESC : a simple wrapper for the date format
- public static function dateStringFormat($timestamp, bool $show_micro = true): string
+ /**
+ * a simple wrapper for the date format
+ * @param int|float $timestamp unix timestamp
+ * @param bool $show_micro show the micro time (default false)
+ * @return string formated date+time in Y-M-D h:m:s ms
+ */
+ public static function dateStringFormat($timestamp, bool $show_micro = false): string
{
- list ($timestamp, $ms) = explode('.', (string)round($timestamp, 4));
+ // split up the timestamp, assume . in timestamp
+ // array pad $ms if no microtime
+ list ($timestamp, $ms) = array_pad(explode('.', (string)round($timestamp, 4)), 2, null);
$string = date("Y-m-d H:i:s", (int)$timestamp);
- if ($show_micro) {
+ if ($show_micro && $ms) {
$string .= ' '.$ms.'ms';
}
return $string;
}
- // METHOD: timeStringFormat
- // WAS : TimeStringFormat
- // PARAMS: seconds
- // RETURN: formated time string
- // DESC : formats a timestamp into time from. not a date
+ /**
+ * formats a timestamp into interval, not into a date
+ * @param string|int|float $timestamp interval in seconds and optional float micro seconds
+ * @param bool $show_micro show micro seconds, default true
+ * @return string interval formatted string or string as is
+ */
public static function timeStringFormat($timestamp, bool $show_micro = true): string
{
// check if the timestamp has any h/m/s/ms inside, if yes skip
@@ -1575,13 +1626,13 @@ class Basic
return $time_string;
}
- // METHOD: stringToTime
- // WAS : StringToTime
- // PARAMS: TimeStringFormat string
- // RETURN: timestamp with microseconds
- // DESC : does a reverse of the TimeStringFormat and converts the string from
- // xd xh xm xs xms to a timestamp.microtime format
- public static function stringToTime($timestring): string
+ /**
+ * does a reverse of the TimeStringFormat and converts the string from
+ * xd xh xm xs xms to a timestamp.microtime format
+ * @param string|int|float $timestring formatted interval
+ * @return string|int|float converted float interval, or string as is
+ */
+ public static function stringToTime($timestring)
{
$timestamp = 0;
if (preg_match("/(d|h|m|s|ms)/", $timestring)) {
@@ -1606,11 +1657,11 @@ class Basic
}
}
- // METHOD: checkDate
- // WAS : CheckDate
- // PARAMS: date (YYYY-MM-DD)
- // RETURN: true if valid date, false if date not valid
- // DESC : splits & checks date, wrap around for check_date function
+ /**
+ * splits & checks date, wrap around for check_date function
+ * @param string $date a date string in the format YYYY-MM-DD
+ * @return bool true if valid date, false if date not valid
+ */
public static function checkDate($date): bool
{
list ($year, $month, $day) = preg_split("/[\/-]/", $date);
@@ -1623,11 +1674,11 @@ class Basic
return true;
}
- // METHOD: checkDateTime
- // WAS : CheckDateTime
- // PARAMS: date (YYYY-MM-DD) + time (HH:MM:SS), SS can be dropped
- // RETURN: true if valid date, false if date not valid
- // DESC : splits & checks date, wrap around for check_date function
+ /**
+ * splits & checks date, wrap around for check_date function
+ * @param string $datetime date (YYYY-MM-DD) + time (HH:MM:SS), SS can be dropped
+ * @return bool true if valid date, false if date not valid
+ */
public static function checkDateTime($datetime): bool
{
list ($year, $month, $day, $hour, $min, $sec) = preg_split("/[\/\- :]/", $datetime);
@@ -1649,14 +1700,17 @@ class Basic
return true;
}
- // METHOD: compareDate
- // WAS : CompareDate
- // PARAMS: start_date, end_date (both: YYYY-MM-DD)
- // RETURN: -1 if the first date is smaller the last
- // 0 if both are equal
- // 1 if the first date is bigger than the last
- // false if there are no valid dates to be found
- // DESC : splits & checks date, wrap around for check_date function
+ /**
+ * plits & checks date, wrap around for check_date function
+ * returns int in:
+ * -1 if the first date is smaller the last
+ * 0 if both are equal
+ * 1 if the first date is bigger than the last
+ * false (bool): error
+ * @param string $start_date start date string in YYYY-MM-DD
+ * @param string $end_date end date string in YYYY-MM-DD
+ * @return int|bool false on error, or int -1/0/1 as difference
+ */
public static function compareDate($start_date, $end_date)
{
// pre check for empty or wrong
@@ -1692,14 +1746,17 @@ class Basic
}
}
- // METHOD: compareDateTime
- // WAS : CompareDateTime
- // PARAMS: start_datetime, end_datetime (both YYYY-MM-DD HH:mm:ss)
- // RETURN: -1 if the first date is smaller the last
- // 0 if both are equal
- // 1 if the end date is bigger than the last
- // false if no valid date/times chould be found
- // DESC : compares the two dates + times. if seconds missing in one set, add :00, converts / to -
+ /**
+ * compares the two dates + times. if seconds missing in one set, add :00, converts / to -
+ * returns int/bool in:
+ * -1 if the first date is smaller the last
+ * 0 if both are equal
+ * 1 if the end date is bigger than the last
+ * false if no valid date/times chould be found
+ * @param string $start_datetime start date/time in YYYY-MM-DD HH:mm:ss
+ * @param string $end_datetime end date/time in YYYY-MM-DD HH:mm:ss
+ * @return int|bool false for error or -1/0/1 as difference
+ */
public static function compareDateTime($start_datetime, $end_datetime)
{
// pre check for empty or wrong
@@ -1717,10 +1774,15 @@ class Basic
}
}
- // METHOD: calcDaysInterval
- // PARAMS: start date, end date
- // RETURN: overall days, week days, weekend days as array 0...2 or named
- // DESC : calculates the days between two dates
+ /**
+ * calculates the days between two dates
+ * return: overall days, week days, weekend days as array 0...2 or named
+ * as overall, weekday and weekend
+ * @param string $start_date valid start date (y/m/d)
+ * @param string $end_date valid end date (y/m/d)
+ * @param bool $return_named return array type, false (default), true for named
+ * @return array 0/overall, 1/weekday, 2/weekend
+ */
public static function calcDaysInterval($start_date, $end_date, bool $return_named = false): array
{
// pos 0 all, pos 1 weekday, pos 2 weekend
@@ -1755,18 +1817,18 @@ class Basic
}
}
- // METHOD: createThumbnail
- // WAS : CreateThumbnail
- // PARAMS: pic -> picture where from we create a thumbnail
- // x -> max x size of thumbnail
- // y -> max y size of thumbnail
- // dummy -> empty, or file_type to show an icon instead of nothing if file is not found
- // path -> if source start is not ROOT path, if empty ROOT is choosen
- // cache -> cache path, if not given TMP is used
- // clear cache -> if set to true, will create thumb all the tame
- // RETURN: thumbnail name
- // DESC : converts picture to a thumbnail with max x and max y size
- public static function createThumbnail($pic, $size_x, $size_y, $dummy = "", $path = "", $cache_source = "", bool $clear_cache = false)
+ /**
+ * converts picture to a thumbnail with max x and max y size
+ * @param string $pic source image file with or without path
+ * @param int $size_x maximum size width
+ * @param int $size_y maximum size height
+ * @param string $dummy empty, or file_type to show an icon instead of nothing if file is not found
+ * @param string $path if source start is not ROOT path, if empty ROOT is choosen
+ * @param string $cache_source cache path, if not given TMP is used
+ * @param bool $clear_cache if set to true, will create thumb all the tame
+ * @return string|bool thumbnail name, or false for error
+ */
+ public static function createThumbnail(string $pic, int $size_x, int $size_y, string $dummy = '', string $path = '', string $cache_source = '', bool $clear_cache = false)
{
// get image type flags
$image_types = array (
@@ -1872,22 +1934,22 @@ class Basic
return $return_data;
}
- // METHOD: checkConvertEncoding
- // PARAMS: string: string to test
- // from_encoding: source encoding of this string
- // to_encoding: target encoding of this string
- // RETURN: false if no problem
- // on error, return array with characters that failed in the convert
- // DESC : test if a string can be safely convert between encodings. mostly utf8 to shift jis
- // the default compare has a possibility of failure, especially with windows
- // it is recommended to the following in the script which uses this method:
- // mb_substitute_character(0x2234);
- // $class->mbErrorChar = '∴';
- // if check to Shift JIS
- // if check to ISO-2022-JP
- // if check to ISO-2022-JP-MS
- // set three dots (∴) as wrong character for correct convert error detect
- // (this char is used, because it is one of the least used ones)
+ /**
+ * test if a string can be safely convert between encodings. mostly utf8 to shift jis
+ * the default compare has a possibility of failure, especially with windows
+ * it is recommended to the following in the script which uses this method:
+ * mb_substitute_character(0x2234);
+ * $class->mbErrorChar = '∴';
+ * if check to Shift JIS
+ * if check to ISO-2022-JP
+ * if check to ISO-2022-JP-MS
+ * set three dots (∴) as wrong character for correct convert error detect
+ * (this char is used, because it is one of the least used ones)
+ * @param string $string string to test
+ * @param string $from_encoding encoding of string to test
+ * @param string $to_encoding target encoding
+ * @return bool|array false if no error or array with failed characters
+ */
public function checkConvertEncoding(string $string, string $from_encoding, string $to_encoding)
{
// convert to target encoding and convert back
@@ -1913,12 +1975,13 @@ class Basic
}
}
- // METHOD: convertEncoding
- // PARAMS: string to convert
- // target encoding (to which to convert to)
- // optional source encoding
- // RETURN: converted string
- // DESC : detects the source encoding of the string and if doesn't match to the given target encoding it convert is
+ /**
+ * detects the source encoding of the string and if doesn't match to the given target encoding it convert is
+ * @param string $string string to convert
+ * @param string $to_encoding target encoding
+ * @param string $source_encoding optional source encoding, will try to auto detect
+ * @return string encoding converted string
+ */
public static function convertEncoding(string $string, string $to_encoding, string $source_encoding = ''): string
{
// set if not given
@@ -1935,11 +1998,11 @@ class Basic
return $string;
}
- // METHOD: __crc32b
- // WAS : _crc32b
- // PARAMS: string
- // RETURN: old (wrong) crc32b hash
- // DESC : checks php version and if >=5.2.7 it will flip the string
+ /**
+ * checks php version and if >=5.2.7 it will flip the string
+ * @param string $string string to crc
+ * @return string crc32b hash (old type)
+ */
public function __crc32b(string $string): string
{
// do normal hash crc32b
@@ -1952,27 +2015,31 @@ class Basic
return $string;
}
- // METHOD: __sha1Short
- // WAS : _sha1_short
- // PARAMS: string, flag to use sha
- // RETURN: sha1 short (9 chars), but current calls __crc32b
- // DESC : replacement for __crc32b call
+ /**
+ * replacement for __crc32b call
+ * @param string $string string to hash
+ * @param bool $use_sha use sha instead of crc32b (default false)
+ * @return string hash of the string
+ */
public function __sha1Short(string $string, bool $use_sha = false): string
{
if ($use_sha) {
+ // return only the first 9 characters
return substr(hash('sha1', $string), 0, 9);
} else {
return $this->__crc32b($string);
}
}
- // METHOD: __hash
- // WAS : _hash
- // PARAMS: string, type of hash to use
- // RETURN: hashed string
- // DESC : replacemend for __crc32b call (alternate)
- // defaults to adler 32, fnv132, fnv1a32, joaat
- // all that create 8 char long hashes
+ /**
+ * replacemend for __crc32b call (alternate)
+ * defaults to adler 32
+ * allowed adler32, fnv132, fnv1a32, joaat
+ * all that create 8 char long hashes
+ * @param string $string string to hash
+ * @param string $hash_type hash type (default adler32)
+ * @return string hash of the string
+ */
public function __hash(string $string, string $hash_type = 'adler32'): string
{
if (!in_array($hash_type, array('adler32', 'fnv132', 'fnv1a32', 'joaat'))) {
@@ -1981,11 +2048,12 @@ class Basic
return hash($hash_type, $string);
}
- // METHOD: checkPHPVersion
- // PARAMS: $min_version: minimum version. in format x, x.y or x.y.z
- // $max_version: default empty, else in same format as min version
- // RETURN: true if ok, false if not matching version
- // DESC : checks if running PHP version matches given PHP version (min or max)
+ /**
+ * checks if running PHP version matches given PHP version (min or max)
+ * @param string $min_version minimum version as string (x, x.y, x.y.x)
+ * @param string $max_version optional maximum version as string (x, x.y, x.y.x)
+ * @return bool true if ok, false if not matching version
+ */
public static function checkPHPVersion(string $min_version, string $max_version = ''): bool
{
// exit with false if the min/max strings are wrong
@@ -2032,15 +2100,16 @@ class Basic
// use the new password* instead
// [!!! DEPRECATED !!!] -> passwordInit
- // METHOD: cryptInit
- // PARAMS: none
- // RETURN: none
- // DESC : inits crypt settings for the crypt functions
- // this function NEEDS (!) to be called BEFORE any of the crypt functions is called
- // there is no auto init for this at the moment
+ /**
+ * inits crypt settings for the crypt functions
+ * this function NEEDS (!) to be called BEFORE any of the crypt functions is called
+ * there is no auto init for this at the moment
+ * @return void has not return
+ * @deprecated use passwordInit instead
+ */
private function cryptInit()
{
- trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
+ trigger_error('Method '.__METHOD__.' is deprecated, use passwordInit', E_USER_DEPRECATED);
// SET CRYPT SALT PREFIX:
// the prefix string is defined by what the server can do
// first we check if we can do blowfish, if not we try md5 and then des
@@ -2079,14 +2148,16 @@ class Basic
}
}
- // [!!! DEPRECATED !!!] -> not needed
- // METHOD: cryptSaltString
- // PARAMS: random string length, default is 22 (for blowfish crypt)
- // RETURN: random string
- // DESC : creates a random string from alphanumeric characters: A-Z a-z 0-9 ./
- private function cryptSaltString($nSize = 22)
+ // [!!! DEPRECATED !!!] -> passwordInit
+ /**
+ * creates a random string from alphanumeric characters: A-Z a-z 0-9 ./
+ * @param integer $nSize random string length, default is 22 (for blowfish crypt)
+ * @return string random string
+ * @deprecated use passwordInit instead
+ */
+ private function cryptSaltString(int $nSize = 22): string
{
- trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
+ trigger_error('Method '.__METHOD__.' is deprecated, use passwordInit', E_USER_DEPRECATED);
// A-Z is 65,90
// a-z is 97,122
// 0-9 is 48,57
@@ -2110,27 +2181,33 @@ class Basic
}
// [!!! DEPRECATED !!!] -> passwordSet
- // METHOD: cryptString
- // PARAMS: string to be crypted (one way)
- // RETURN: encrypted string
- // DESC : encrypts the string with blowfish and returns the full string + salt part that needs to be stored somewhere (eg DB)
- public function cryptString($string)
+ /**
+ * encrypts the string with blowfish and returns the full string + salt part that needs to be stored somewhere (eg DB)
+ * @param string $string string to be crypted (one way)
+ * @return string encrypted string
+ * @deprecated use passwordSet instead
+ */
+ public function cryptString(string $string): string
{
- trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
+ trigger_error('Method '.__METHOD__.' is deprecated, use passwordSet', E_USER_DEPRECATED);
// the crypt prefix is set in the init of the class
// uses the random string method to create the salt
+ // suppress deprecated error, as this is an internal call
+ /** @phan-suppress-next-line PhanDeprecatedFunction */
return crypt($string, $this->cryptSaltPrefix.$this->cryptSaltString($this->cryptSaltSize).$this->cryptSaltSuffix);
}
// [!!! DEPRECATED !!!] -> passwordVerify
- // METHOD: verifyCryptString
- // PARAMS: plain string (eg password)
- // full crypted string (from cryptString
- // RETURN: true on matching or false for not matching
- // DESC : compares the string with the crypted one, is counter method to cryptString
- public function verifyCryptString($string, $crypt)
+ /**
+ * compares the string with the crypted one, is counter method to cryptString
+ * @param string $string plain string (eg password)
+ * @param string $crypt full crypted string (from cryptString
+ * @return bool true on matching or false for not matching
+ * @deprecated use passwordVerify instead
+ */
+ public function verifyCryptString(string $string, string $crypt): bool
{
- trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
+ trigger_error('Method '.__METHOD__.' is deprecated, use passwordVerify', E_USER_DEPRECATED);
// the full crypted string needs to be passed on to the salt, so the init (for blowfish) and salt are passed on
if (crypt($string, $crypt) == $crypt) {
return true;
@@ -2140,11 +2217,11 @@ class Basic
}
// *** BETTER PASSWORD OPTIONS, must be used ***
- // METHOD: passwordInit
- // PARAMS: none
- // RETURN: none
- // DESC : inits the password options set
- // currently this is et empty, and the default options are used
+ /**
+ * inits the password options set
+ * currently this is et empty, and the default options are used
+ * @return void has no reutrn
+ */
private function passwordInit(): void
{
// set default password cost: use default set automatically
@@ -2157,6 +2234,11 @@ class Basic
// PARAMS: password
// RETURN: hashed password
// DESC : creates the password hash
+ /**
+ * creates the password hash
+ * @param string $password password
+ * @return string hashed password
+ */
public function passwordSet(string $password): string
{
// always use the PHP default for the password
@@ -2164,10 +2246,12 @@ class Basic
return password_hash($password, PASSWORD_DEFAULT, $this->password_options);
}
- // METHOD: passwordVerify
- // PARAMS: password and hash
- // RETURN: true or false
- // DESC : checks if the entered password matches the hash
+ /**
+ * checks if the entered password matches the hash
+ * @param string $password password
+ * @param string $hash password hash
+ * @return bool true or false
+ */
public function passwordVerify(string $password, string $hash): bool
{
if (password_verify($password, $hash)) {
@@ -2179,10 +2263,11 @@ class Basic
return false;
}
- // METHOD: passwordRehashCheck
- // PARAMS: hash
- // RETURN: true or false
- // DESC : checks if the password needs to be rehashed
+ /**
+ * checks if the password needs to be rehashed
+ * @param string $hash password hash
+ * @return bool true or false
+ */
public function passwordRehashCheck(string $hash): bool
{
if (password_needs_rehash($hash, PASSWORD_DEFAULT, $this->password_options)) {
@@ -2196,10 +2281,13 @@ class Basic
// *** COLORS ***
- // METHOD: hex2rgb
- // PARAMS: hexstring, flag to return as string (true/false), string seperator: default: ,
- // RETURN: array with RGB or a string with the seperator
- // DESC : converts a hex RGB color to the int numbers
+ /**
+ * converts a hex RGB color to the int numbers
+ * @param string $hexStr RGB hexstring
+ * @param bool $returnAsString flag to return as string
+ * @param string $seperator string seperator: default: ","
+ * @return string|array|bool false on error or array with RGB or a string with the seperator
+ */
public static function hex2rgb(string $hexStr, bool $returnAsString = false, string $seperator = ',')
{
$hexStr = preg_replace("/[^0-9A-Fa-f]/", '', $hexStr); // Gets a proper hex string
@@ -2216,29 +2304,73 @@ class Basic
$rgbArray['G'] = hexdec(str_repeat(substr($hexStr, 1, 1), 2));
$rgbArray['B'] = hexdec(str_repeat(substr($hexStr, 2, 1), 2));
} else {
- return false; //Invalid hex color code
+ // Invalid hex color code
+ return false;
}
- return $returnAsString ? implode($seperator, $rgbArray) : $rgbArray; // returns the rgb string or the associative array
+ // returns the rgb string or the associative array
+ return $returnAsString ? implode($seperator, $rgbArray) : $rgbArray;
}
- // METHOD: rgb2hex
- // PARAMS: red, green, blue (0-255)
- // RETURN: string with hex rgb color plus # in front
- // DESC : converts the rgb values from int data to the valid rgb html hex string
- public static function rgb2hex(int $red, int $green, int $blue): string
+ /**
+ * converts the rgb values from int data to the valid rgb html hex string
+ * optional can turn of leading #
+ * @param int $red red 0-255
+ * @param int $green blue 0-255
+ * @param int $blue green 0-255
+ * @param bool $hex_prefix default true, prefix with "#"
+ * @return string rgb in hex values with leading # if set
+ */
+ public static function rgb2hex(int $red, int $green, int $blue, bool $hex_prefix = true): string
{
- $hex_color = '#';
+ $hex_color = '';
+ if ($hex_prefix === true) {
+ $hex_color = '#';
+ }
foreach (array ('red', 'green', 'blue') as $color) {
+ // if not valid, set to gray
+ if ($$color < 0 || $$color > 255) {
+ $$color = 125;
+ }
// pad left with 0
$hex_color .= str_pad(dechex($$color), 2, '0', STR_PAD_LEFT);
}
return $hex_color;
}
- // METHOD: rgb2hsb
- // PARAMS: red, green, blue (0-255)
- // RETURN: array with hue (0-360), sat (0-100%), brightness/value (0-100%)
- // DESC : converts RGB to HSB/V values
+ /**
+ * converts and int RGB to the HTML color string in hex format
+ * @param int $red [description]
+ * @param int $green [description]
+ * @param int $blue [description]
+ * @return [type] [description]
+ * @deprecated use rgb2hex instead
+ */
+ public static function rgb2html(int $red, int $green, int $blue): string
+ {
+ trigger_error('Method '.__METHOD__.' is deprecated, use rgb2hex', E_USER_DEPRECATED);
+ // check that each color is between 0 and 255
+ foreach (array('red', 'green', 'blue') as $color) {
+ if ($$color < 0 || $$color > 255) {
+ $$color = 125;
+ }
+ // convert to HEX value
+ $$color = dechex($$color);
+ // prefix with 0 if only one char
+ $$color = ((strlen($$color) < 2) ? '0' : '').$$color;
+ }
+ // prefix hex parts with 0 if they are just one char long and return the html color string
+ return '#'.$red.$green.$blue;
+ }
+
+ /**
+ * converts RGB to HSB/V values
+ * returns:
+ * array with hue (0-360), sat (0-100%), brightness/value (0-100%)
+ * @param int $r red 0-255
+ * @param int $g green 0-255
+ * @param int $b blue 0-255
+ * @return array Hue, Sat, Brightness/Value
+ */
public static function rgb2hsb(int $r, int $g, int $b): array
{
// check that rgb is from 0 to 255
@@ -2271,11 +2403,14 @@ class Basic
return array(round($HUE), round((($MAX - $MIN) / $MAX) * 100), round($MAX * 100));
}
- // METHOD: hsb2rgb
- // PARAMS: hue (0-360), saturation (0-1), brightness/value (0-1)
- // RETURN: array with red, blue, green
- // DESC : converts HSB/V to RGB values RGB is full INT
- public static function hsb2rgb(int $H, int $S, int $V): array
+ /**
+ * converts HSB/V to RGB values RGB is full INT
+ * @param int $H hue 0-360
+ * @param float $S saturation 0-1 (float)
+ * @param float $V brightness/value 0-1 (float)
+ * @return array 0 red/1 green/2 blue array
+ */
+ public static function hsb2rgb(int $H, float $S, float $V): array
{
// check that H is 0 to 359, 360 = 0
// and S and V are 0 to 1
@@ -2339,10 +2474,15 @@ class Basic
return array(round($red * 255), round($green * 255), round($blue * 255));
}
- // METHOD: rgb2hsl
- // PARAMS: red, blue, green (all 0-255)
- // RETURN: array with hue (0-360), saturation (0-100%) and luminance (0-100%)
- // DESC : converts a RGB (0-255) to HSL
+ /**
+ * converts a RGB (0-255) to HSL
+ * return:
+ * array with hue (0-360), saturation (0-100%) and luminance (0-100%)
+ * @param int $r red 0-255
+ * @param int $g green 0-255
+ * @param int $b blue 0-255
+ * @return array hue/sat/luminance
+ */
public static function rgb2hsl(int $r, int $g, int $b): array
{
// check that rgb is from 0 to 255
@@ -2382,13 +2522,14 @@ class Basic
}
}
- // METHOD: hsl2rgb
- // PARAMS: hue: 0-360 (degrees)
- // saturation: 0-1
- // luminance: 0-1
- // RETURN: array with RGB as full int
- // DESC : converts an HSL to RGB
- public static function hsl2rgb(int $h, int $s, int $l): array
+ /**
+ * converts an HSL to RGB
+ * @param int $h hue: 0-360 (degrees)
+ * @param float $s saturation: 0-1
+ * @param float $l luminance: 0-1
+ * @return array red/blue/green 0-255 each
+ */
+ public static function hsl2rgb(int $h, float $s, float $l): array
{
$h = (1 / 360) * $h; // calc to internal convert value for hue
// if saturation is 0
@@ -2419,32 +2560,14 @@ class Basic
}
}
- // METHOD: rgb2html
- // PARAMS: red, green, blue
- // RETRUN valid # prefix hex html color string
- // DESC : converts and int RGB to the HTML color string in hex format
- public static function rgb2html(int $red, int $green, int $blue): string
- {
- // check that each color is between 0 and 255
- foreach (array('red', 'green', 'blue') as $color) {
- if ($$color < 0 || $$color > 255) {
- $$color = 125;
- }
- // convert to HEX value
- $$color = dechex($$color);
- // prefix with 0 if only one char
- $$color = ((strlen($$color) < 2) ? '0' : '').$$color;
- }
- // prefix hex parts with 0 if they are just one char long and return the html color string
- return '#'.$red.$green.$blue;
- }
-
- // METHOD: getEmailType
- // PARAMS: email, short == false
- // RETURN: string for email type, eg "pc", "docomo", etc
- // DESC : guesses the email type (mostly for mobile) from the domain
- // if second is set to true, it will return short naming scheme (only provider)
- public function getEmailType(string $email, bool $short = false): string
+ /**
+ * guesses the email type (mostly for mobile) from the domain
+ * if second is set to true, it will return short naming scheme (only provider)
+ * @param string $email email string
+ * @param bool $short default false, if true, returns only short type (pc instead of pc_html)
+ * @return string|bool email type, eg "pc", "docomo", etc, false for invalid short type
+ */
+ public function getEmailType(string $email, bool $short = false)
{
// trip if there is no email address
if (!$email) {
@@ -2468,10 +2591,11 @@ class Basic
}
}
- // METHOD: getShortEmailType
- // PARAMS: long email type (not email)
- // RETURN: short email type
- // DESC : gets the short email type from a long email type
+ /**
+ * gets the short email type from a long email type
+ * @param string $email_type email string
+ * @return string|bool short string or false for invalid
+ */
public function getShortEmailType(string $email_type)
{
// check if the short email type exists
@@ -2483,15 +2607,20 @@ class Basic
}
}
- // METHOD: printDateTime
- // PARAMS: year, month, day, hour, min: the date and time values
- // suffix: additional info printed after the date time variable in the drop down,
- // also used for ID in the on change JS call
- // min_steps: default is 1 (minute), can set to anything, is used as sum up from 0
- // name_pos_back: default false, if set to true, the name will be printend
- // after the drop down and not before the drop down
- // RETURN: HTML formated strings for drop down lists of date and time
- // DESC : print the date/time drop downs, used in any queue/send/insert at date/time place
+ /**
+ * print the date/time drop downs, used in any queue/send/insert at date/time place
+ * @param int $year year YYYY
+ * @param int $month month m
+ * @param int $day day d
+ * @param int $hour hour H
+ * @param int $min min i
+ * @param string $suffix additional info printed after the date time variable in the drop down
+ * also used for ID in the on change JS call
+ * @param int $min_steps default is 1 (minute), can set to anything, is used as sum up from 0
+ * @param bool $name_pos_back default false, if set to true, the name will be printend
+ * after the drop down and not before the drop down
+ * @return string HTML formated strings for drop down lists of date and time
+ */
public static function printDateTime($year, $month, $day, $hour, $min, string $suffix = '', int $min_steps = 1, bool $name_pos_back = false)
{
// if suffix given, add _ before
@@ -2580,11 +2709,12 @@ class Basic
return $string;
}
- // METHOD: htmlent
- // PARAMS: string to encode
- // RETURN: encoded string
- // DESC : full wrapper for html entities
- public function htmlent(string $string): string
+ /**
+ * full wrapper for html entities
+ * @param string $string string to html encode
+ * @return mixed if string, encoded, else as is
+ */
+ public function htmlent(string $string)
{
if (is_string($string)) {
return htmlentities($string, ENT_COMPAT|ENT_HTML401, 'UTF-8', false);
@@ -2593,39 +2723,48 @@ class Basic
}
}
- // METHOD: removeLB
- // PARAMS: string, optional replace character
- // RETURN: string with line breaks removed
- // DESC : strips out all line breaks or replaced with given string
+ /**
+ * strips out all line breaks or replaced with given string
+ * @param string $string string
+ * @param string $replace replace character, default ' '
+ * @return string cleaned string without any line breaks
+ */
public function removeLB(string $string, string $replace = ' '): string
{
return str_replace(array("\r", "\n"), $replace, $string);
}
- // METHOD: fceil
- // PARAMS: number, round decimals (default 10)
- // RETURN: correct ceil number
- // DESC : some float numbers will be rounded up even if they have no decimal entries
+ /**
+ * some float numbers will be rounded up even if they have no decimal entries
+ * this function fixes this by pre-rounding before calling ceil
+ * @param float $number number to round
+ * @param int|integer $precision intermediat round up decimals (default 10)
+ * @return float correct ceil number
+ */
public function fceil(float $number, int $precision = 10): float
{
return ceil(round($number, $precision));
}
- // METHOD floorp
- // PARAMS: number, round to
- // RETURN: floor number but with tround to
- // DESC : eg 48767 with -2 -> 48700
+ /**
+ * round inside an a number, not the decimal part only
+ * eg 48767 with -2 -> 48700
+ * @param float $number number to round
+ * @param int $precision negative number for position in number (default -2)
+ * @return float rounded number
+ */
public function floorp(float $number, int $precision = -2): float
{
$mult = pow(10, $precision); // Can be cached in lookup table
return floor($number * $mult) / $mult;
}
- // METHOD: initNumeric
- // PARAMS: any value
- // RETURN: if not numeric, sets to 0, else returns value already set
- // DESC : inits input to 0, if value is not numeric
- public function initNumeric(float $number): float
+ /**
+ * inits input to 0, if value is not numeric
+ * @param string|int|float $number string or number to check
+ * @return float if not number, then returns 0, else original input
+ */
+ public function initNumeric($number): float
{
if (!is_numeric($number)) {
return 0;
@@ -2634,10 +2773,11 @@ class Basic
}
}
- // METHOD: setFormToken
- // PARAMS: session name, if not set then default is form_token
- // RETURN: form token
- // DESC : sets a form token in a session and returns form token
+ /**
+ * sets a form token in a session and returns form token
+ * @param string $name optional form name, default form_token
+ * @return string token name for given form id string
+ */
public function setFormToken(string $name = 'form_token'): string
{
// current hard set to sha256
@@ -2646,10 +2786,12 @@ class Basic
return $token;
}
- // METHOD: validateFormToken
- // PARAMS: form token, session name (default form_token)
- // RETURN: true or false
- // DESC : checks if the form token matches the session set form token
+ /**
+ * checks if the form token matches the session set form token
+ * @param string $token token string to check
+ * @param string $name optional form name to check to, default form_token
+ * @return bool false if not set, or true/false if matching or not mtaching
+ */
public function validateFormToken(string $token, string $name = 'form_token'): bool
{
if (isset($_SESSION[$name])) {
@@ -2658,191 +2800,6 @@ class Basic
return false;
}
}
-
- // *************************************************************
- // *** DEPRICATED CALL ***
- // *************************************************************
- // should be removed later
- public function checkConvert($string, $from_encoding, $to_encoding)
- {
- error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
- trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
- return $this->checkConvertEncoding($string, $from_encoding, $to_encoding);
- }
-
- // *************************************************************
- // *** COMPATIBILITY METHODS ***
- // those methods are deprecated function call names
- // they exist for backwards compatibility only
- // *************************************************************
-
- public function running_time($simple = false)
- {
- error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
- trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
- return $this->runningTime($simple);
- }
-
- public static function print_time($set_microtime = -1)
- {
- error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
- trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
- return Basic::printTime($set_microtime);
- }
-
- private function fdebug_fp($flag = '')
- {
- error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
- trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
- $this->fdebugFP($flag);
- }
-
- public function debug_for($type, $flag)
- {
- error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
- trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
- $this->debugFor($type, $flag);
- }
-
- public function get_caller_method($level = 2)
- {
- error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
- trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
- return $this->getCallerMethod($level);
- }
-
- public function merge_errors($error_msg = array ())
- {
- error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
- trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
- $this->mergeErrors($error_msg);
- }
-
- public function print_error_msg($string = '')
- {
- error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
- trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
- return $this->printErrorMsg($string);
- }
-
- private function write_error_msg($level, $error_string)
- {
- error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
- trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
- $this->writeErrorMsg($level, $error_string);
- }
-
- public function reset_error_msg($level = '')
- {
- error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
- trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
- $this->resetErrorMsg($level);
- }
-
- public static function print_ar($array)
- {
- error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
- trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
- return Basic::printAr($array);
- }
-
- public function magic_links($string, $target = "_blank")
- {
- error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
- trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
- return $this->magicLinks($string, $target);
- }
-
- private function create_url($href, $atag, $_1, $_2, $_3, $name, $class)
- {
- error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
- trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
- return $this->createUrl($href, $atag, $_1, $_2, $_3, $name, $class);
- }
-
- private function create_email($mailto, $atag, $_1, $_2, $_3, $title, $class)
- {
- error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
- trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
- return $this->createEmail($mailto, $atag, $_1, $_2, $_3, $title, $class);
- }
-
- public function get_host_name()
- {
- error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
- trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
- return $this->getHostName();
- }
-
- public static function get_page_name($strip_ext = 0)
- {
- error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
- trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
- return Basic::getPageName($strip_ext);
- }
-
- public static function get_filename_ending($filename)
- {
- error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
- trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
- return Basic::getFilenameEnding($filename);
- }
-
- public static function array_search_recursive($needle, $haystack, $key_lookin = "")
- {
- error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
- trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
- return Basic::arraySearchRecursive($needle, $haystack, $key_lookin);
- }
-
- public static function array_search_recursive_all($needle, $haystack, $key, $path = null)
- {
- error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
- trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
- return Basic::arraySearchRecursiveAll($needle, $haystack, $key, $path);
- }
-
- public static function array_search_simple($array, $key, $value)
- {
- error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
- trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
- return Basic::arraySearchSimple($array, $key, $value);
- }
-
- public static function _mb_mime_encode($string, $encoding)
- {
- error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
- trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
- return Basic::__mbMimeEncode($string, $encoding);
- }
-
- public function _crc32b($string)
- {
- error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
- trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
- return $this->__crc32b($string);
- }
-
- public function _sha1_short($string, $use_sha = false)
- {
- error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
- trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
- return $this->__sha1Short($string, $use_sha);
- }
-
- public function _hash($string, $hash_type = 'adler32')
- {
- error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
- trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
- return $this->__hash($string, $hash_type);
- }
-
- public static function in_array_any($needle, $haystack)
- {
- error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
- trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
- return Basic::inArrayAny($needle, $haystack);
- }
}
// __END__
diff --git a/www/lib/CoreLibs/DB/Extended/ArrayIO.php b/www/lib/CoreLibs/DB/Extended/ArrayIO.php
index d977bd20..61dd1ed7 100644
--- a/www/lib/CoreLibs/DB/Extended/ArrayIO.php
+++ b/www/lib/CoreLibs/DB/Extended/ArrayIO.php
@@ -48,14 +48,14 @@ class ArrayIO extends \CoreLibs\DB\IO
public $pk_name; // the primary key from this table
public $pk_id; // the PK id
- // METHOD: db_array_io
- // PARAMS: db_config -> db_io class init vars
- // table_array -> the array from the table
- // table_name -> name of the table (for the array)
- // set_control_flag -> set basic class set/get variable error flags
- // RETURN: none
- // DESC : constructor for the array io class, set the
- // primary key name automatically (from array)
+ /**
+ * constructor for the array io class, set the
+ * primary key name automatically (from array)
+ * @param array $db_config db connection config
+ * @param array $table_array table array config
+ * @param string $table_name table name string
+ * @param int|integer $set_control_flag set basic class set/get variable error flags
+ */
public function __construct(array $db_config, array $table_array, string $table_name, int $set_control_flag = 0)
{
// instance db_io class
@@ -77,21 +77,23 @@ class ArrayIO extends \CoreLibs\DB\IO
} // set pk_name IF table_array was given
}
- // deconstruktor
+ /**
+ * class deconstructor
+ */
public function __destruct()
{
parent::__destruct();
}
- // METHOD: convertData
- // WAS : convert_data
- // PARAMS: string -> the string that should be changed
- // RETURN: string -> the altered string
- // DESC : changes all previously alterd HTML code into visible one,
- // works for ,, and (thought can be / or should
- // be handled with the magic links functions
- // used with the read function
- public function convertData($text)
+ /**
+ * changes all previously alterd HTML code into visible one,
+ * works for ,, and (thought can be / or should
+ * be handled with the magic links functions
+ * used with the read function
+ * @param string $text any html encoded string
+ * @return string decoded html string
+ */
+ public function convertData($text): string
{
$text = str_replace('<b>', '', $text);
$text = str_replace('</b>', '', $text);
@@ -109,7 +111,12 @@ class ArrayIO extends \CoreLibs\DB\IO
// PARAMS: string -> string to be changed
// RETURN: string -> altered string
// DESC : changeds all HTML entities into non HTML ones
- public function convertEntities($text)
+ /**
+ * changeds all HTML entities into non HTML ones
+ * @param string $text encoded html string
+ * @return string decoded html string
+ */
+ public function convertEntities($text): string
{
$text = str_replace('<', '<', $text);
$text = str_replace('>', '>', $text);
@@ -119,12 +126,12 @@ class ArrayIO extends \CoreLibs\DB\IO
return $text;
}
- // METHOD: dbDumpArray
- // WAS : db_dump_array
- // PARAMS: none
- // RETURN: returns the current array
- // DESC : dumps the current data
- public function dbDumpArray($write = 0)
+ /**
+ * dumps the current data
+ * @param bool $write write to error message, default false
+ * @return string the array data as html string entry
+ */
+ public function dbDumpArray($write = false): string
{
reset($this->table_array);
$string = '';
@@ -132,17 +139,16 @@ class ArrayIO extends \CoreLibs\DB\IO
$string .= ''.$column.' -> '.$data_array['value'].'
';
}
// add output to internal error_msg
- if ($write) {
+ if ($write === true) {
$this->error_msg['db'] .= $string;
}
return $string;
}
- // METHOD: dbCheckPkSet
- // WAS : db_check_pk_set
- // PARAMS: none
- // RETURN: none
- // DESC : checks if pk is set and if not, set from pk_id and if this also not set return 0
+ /**
+ * checks if pk is set and if not, set from pk_id and if this also not set return 0
+ * @return bool true if pk value is set, else false
+ */
public function dbCheckPkSet()
{
// if pk_id is set, overrule ...
@@ -154,18 +160,18 @@ class ArrayIO extends \CoreLibs\DB\IO
// if no PK found, error ...
$this->error_id = 91;
$this->__dbError();
- return 0;
+ return false;
} else {
- return 1;
+ return true;
}
}
- // METHOD: dbResetArray
- // WAS : db_reset_array
- // PARAMS: reset_pk -> if set reset the pk too
- // RETURN: none
- // DESC : resets the whole array
- public function dbResetArray($reset_pk = 0)
+ /**
+ * resets the whole array values
+ * @param boolean $reset_pk true if we want to reset the pk too
+ * @return void has no return
+ */
+ public function dbResetArray($reset_pk = false): void
{
reset($this->table_array);
foreach ($this->table_array as $column => $data_array) {
@@ -177,14 +183,16 @@ class ArrayIO extends \CoreLibs\DB\IO
}
}
- // METHOD: dbDelete
- // WAS : db_delete
- // PARAMS: optional the table_array, if not given uses class var
- // RETURN: 1 for successfull delete or 0 for error
- // DESC : deletes one dataset
- public function dbDelete($table_array = 0)
+ /**
+ * deletes one dataset
+ * @param array $table_array optional override for table array set
+ * set this as new table array too
+ * @return array returns the table array that was deleted
+ */
+ public function dbDelete($table_array = array ())
{
- if (is_array($table_array)) {
+ // is array and has values, override set and set new
+ if (is_array($table_array) && count($table_array)) {
$this->table_array = $table_array;
}
if (!$this->dbCheckPkSet()) {
@@ -234,15 +242,16 @@ class ArrayIO extends \CoreLibs\DB\IO
return $this->table_array;
}
- // METHOD: dbRead
- // WAS : db_read
- // PARAMS: edit -> if 1 data will not be altered for output, optional the table_array, if not given uses class var
- // RETURN: true or false for reading
- // DESC : reads one row into the array
- public function dbRead($edit = 0, $table_array = 0)
+ /**
+ * reads one row into the array
+ * @param boolean $edit on true convert data, else as is
+ * @param array $table_array optional table array, overwrites internal set array
+ * @return array set table array with values
+ */
+ public function dbRead($edit = false, $table_array = array ())
{
// if array give, overrules internal array
- if (is_array($table_array)) {
+ if (is_array($table_array) && count($table_array)) {
$this->table_array = $table_array;
}
if (!$this->dbCheckPkSet()) {
@@ -280,7 +289,7 @@ class ArrayIO extends \CoreLibs\DB\IO
if ($res = $this->dbFetchArray()) {
reset($this->table_array);
foreach ($this->table_array as $column => $data_array) {
- // wenn "edit" dann gib daten wie in DB zurck, ansonten aufbereiten fr ausgabe
+ // wenn "edit" dann gib daten wie in DB zurück, ansonten aufbereiten fr ausgabe
// ?? sollte das nicht drauen ??? man weis ja net was da drin steht --> is noch zu berlegen
// echo 'EDIT: $edit | Spalte: $column | type: '.$this->table_array[$column]['type'].' | Res: '.$res[$column].'
';
if ($edit) {
@@ -306,14 +315,15 @@ class ArrayIO extends \CoreLibs\DB\IO
return $this->table_array;
}
- // METHOD: dbWrite
- // WAS : db_write
- // PARAMS: addslashes -> if 1 will make an addslashes for each array field, optional the table_array, if not given uses class var
- // RETURN: true or false on write
- // DESC : writes on set into DB or updates one set (if PK exists)
- public function dbWrite($addslashes = 0, $table_array = 0)
+ /**
+ * writes one set into DB or updates one set (if PK exists)
+ * @param boolean $addslashes old convert entities and set set escape
+ * @param array $table_array optional table array, overwrites internal one
+ * @return array table array or null
+ */
+ public function dbWrite($addslashes = false, $table_array = array ())
{
- if (is_array($table_array)) {
+ if (is_array($table_array) && count($table_array)) {
$this->table_array = $table_array;
}
// PK ID check
@@ -524,68 +534,6 @@ class ArrayIO extends \CoreLibs\DB\IO
// return the table if needed
return $this->table_array;
}
-
- // *************************************************************
- // COMPATIBILITY METHODS
- // those methods are deprecated function call names
- // they exist for backwards compatibility only
- // *************************************************************
-
- public function convert_data($text)
- {
- error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
- trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
- return $this->convertData($text);
- }
-
- public function convert_entities($text)
- {
- error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
- trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
- return $this->convertEntities($text);
- }
-
- public function db_dump_array($write = 0)
- {
- error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
- trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
- return $this->dbDumpArray($write);
- }
-
- public function db_check_pk_set()
- {
- error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
- trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
- return $this->dbCheckPkSet();
- }
-
- public function db_reset_array($reset_pk = 0)
- {
- error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
- trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
- return $this->dbResetArray($reset_pk);
- }
-
- public function db_delete($table_array = 0)
- {
- error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
- trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
- return $this->dbDelete($table_array);
- }
-
- public function db_read($edit = 0, $table_array = 0)
- {
- error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
- trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
- return $this->dbRead($edit, $table_array);
- }
-
- public function db_write($addslashes = 0, $table_array = 0)
- {
- error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
- trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
- return $this->dbWrite($addslashes, $table_array);
- }
} // end of class
// __END__
diff --git a/www/lib/CoreLibs/DB/IO.php b/www/lib/CoreLibs/DB/IO.php
index c9d784fb..dda77af1 100644
--- a/www/lib/CoreLibs/DB/IO.php
+++ b/www/lib/CoreLibs/DB/IO.php
@@ -303,11 +303,6 @@ class IO extends \CoreLibs\Basic
// if a sync is running holds the md5 key of the query
private $async_running;
- // METHOD __construct
- // PARAMS db_config -> array with db, user, password & host
- // set_control_flag -> flags for core class get/set variable error handling
- // RETURN nothing
- // DESC constructor for db_clss
/**
* main DB concstructor with auto connection to DB and failure set on failed connection
* @param array $db_config DB configuration array
@@ -395,10 +390,9 @@ class IO extends \CoreLibs\Basic
$this->db_init_error = true;
}
- // METHOD: __destruct
- // PARAMS: none
- // RETURN: none
- // DESC: final desctruct method, closes the DB connection
+ /**
+ * final desctruct method, closes the DB connection
+ */
public function __destruct()
{
$this->__closeDB();
@@ -409,13 +403,11 @@ class IO extends \CoreLibs\Basic
// PRIVATE METHODS
// *************************************************************
- // METHOD: __connectToDB
- // WAS : _connect_to_db
- // PARAMS: none
- // RETURN: true on successfull connect, false if failed
- // DESC :
- // internal connection function. Used to connect to the DB if there is no connection done yet.
- // Called before any execute
+ /**
+ * internal connection function. Used to connect to the DB if there is no connection done yet.
+ * Called before any execute
+ * @return bool true on successfull connect, false if failed
+ */
private function __connectToDB(): bool
{
// generate connect string
@@ -445,12 +437,11 @@ class IO extends \CoreLibs\Basic
return true;
}
- // METHOD: __closeDB
- // WAS : _close_db
- // PARAMS: none
- // RETURN: none
- // DESC : close db connection
- // only used by the deconstructor
+ /**
+ * close db connection
+ * only used by the deconstructor
+ * @return void has no return
+ */
private function __closeDB(): void
{
if (isset($this->dbh) && $this->dbh) {
@@ -459,12 +450,13 @@ class IO extends \CoreLibs\Basic
}
}
- // METHOD: __checkQueryForSelect
- // WAS : _check_query_for_select
- // PARAMS: query
- // RETURN: true if matching, false if not
- // DESC : checks if query is a SELECT, SHOW or WITH, if not error, 0 return
- // NOTE : Query needs to start with SELECT, SHOW or WITH. if starts with "with" it is ignored
+ /**
+ * checks if query is a SELECT, SHOW or WITH, if not error, 0 return
+ * NOTE:
+ * Query needs to start with SELECT, SHOW or WITH. if starts with "with" it is ignored
+ * @param string $query query to check
+ * @return bool true if matching, false if not
+ */
private function __checkQueryForSelect(string $query): bool
{
// perhaps allow spaces before select ?!?
@@ -474,13 +466,15 @@ class IO extends \CoreLibs\Basic
return false;
}
- // METHOD: __checkQueryForInsert
- // WAS : _check_query_for_insert
- // PARAMS: query, pure flag (boolean)
- // RETURN: true if matching, flase if not
- // DESC : check for DELETE, INSERT, UPDATE
- // : if pure is set to true, only when INSERT is set will return true
- // NOTE : Queries need to start with INSERT, UPDATE, DELETE. Anything else is ignored
+ /**
+ * check for DELETE, INSERT, UPDATE
+ * if pure is set to true, only when INSERT is set will return true
+ * NOTE:
+ * Queries need to start with INSERT, UPDATE, DELETE. Anything else is ignored
+ * @param string $query query to check
+ * @param bool $pure pure check (only insert), default false
+ * @return bool true if matching, false if not
+ */
private function __checkQueryForInsert(string $query, bool $pure = false): bool
{
if ($pure && preg_match("/^insert /i", $query)) {
@@ -492,11 +486,12 @@ class IO extends \CoreLibs\Basic
return false;
}
- // METHOD: __checkQueryForUpdate
- // PARAMS: query
- // RETURN: true if UPDATE, else false
- // DESC : returns true if the query starts with UPDATE
- // NOTE : query NEEDS to start with UPDATE
+ /**
+ * returns true if the query starts with UPDATE
+ * query NEEDS to start with UPDATE
+ * @param string $query query to check
+ * @return bool returns true if the query starts with UPDATE
+ */
private function __checkQueryForUpdate(string $query): bool
{
if (preg_match("/^update /i", $query)) {
@@ -505,12 +500,13 @@ class IO extends \CoreLibs\Basic
return false;
}
- // METHOD: __printArray
- // WAS : _print_array
- // PARAMS: array to print
- // RETURN: string with printed and formated array
- // DESC : internal funktion that creates the array
- // NOTE : used in db_dump_data only
+ /**
+ * internal funktion that creates the array
+ * NOTE:
+ * used in db_dump_data only
+ * @param array $array array to print
+ * @return string string with printed and formated array
+ */
private function __printArray(array $array): string
{
$string = '';
@@ -531,14 +527,14 @@ class IO extends \CoreLibs\Basic
return $string;
}
- // METHOD: __dbDebug
- // WAS : _db_debug
- // PARAMS: debug_id -> group id for debug
- // error_string -> error message or debug data
- // id -> db debug group
- // type -> query identifiery (Q, I, etc)
- // RETURN: none
- // DESC : calls the basic class debug with strip command
+ /**
+ * calls the basic class debug with strip command
+ * @param string $debug_id group id for debug
+ * @param string $error_string error message or debug data
+ * @param string $id db debug group
+ * @param string $type query identifier (Q, I, etc)
+ * @return void has no return
+ */
private function __dbDebug(string $debug_id, string $error_string, string $id = '', string $type = ''): void
{
$prefix = '';
@@ -554,15 +550,16 @@ class IO extends \CoreLibs\Basic
$this->debug($debug_id, $prefix.$error_string, true);
}
- // METHOD: __dbError
- // WAS : _db_error
- // PARAMS: cursor -> current cursor for pg_result_error, mysql uses dbh, pg_last_error too,
- // but pg_result_error is more accurate
- // msg -> optional message
- // RETURN: none
- // DESC : if error_id set, writes long error string into error_msg
- // NOTE : needed to make public so it can be called from DB.Array.IO too
- public function __dbError($cursor = '', string $msg = ''): void
+ /**
+ * if error_id set, writes long error string into error_msg
+ * NOTE:
+ * needed to make public so it can be called from DB.Array.IO too
+ * @param resource|bool $cursor current cursor for pg_result_error, mysql uses dbh,
+ * pg_last_error too, but pg_result_error is more accurate
+ * @param string $msg optional message
+ * @return void has no return
+ */
+ public function __dbError($cursor = false, string $msg = ''): void
{
$pg_error_string = '';
$where_called = $this->getCallerMethod();
@@ -591,11 +588,11 @@ class IO extends \CoreLibs\Basic
$this->warning_id = 0;
}
- // METHOD: __dbConvertEncoding
- // WAS : _db_convert_encoding
- // PARAMS: array from fetch_row
- // RETURN: convert fetch_row array
- // DESC : if there is the 'to_encoding' var set, and the field is in the wrong encoding converts it to the target
+ /**
+ * if there is the 'to_encoding' var set, and the field is in the wrong encoding converts it to the target
+ * @param array|bool $row array from fetch_row
+ * @return array|bool convert fetch_row array, or false
+ */
private function __dbConvertEncoding($row)
{
// only do if array, else pass through row (can be false)
@@ -614,11 +611,12 @@ class IO extends \CoreLibs\Basic
return $row;
}
- // METHOD: __dbDebugPrepare
- // WAS : _db_debug_prepare
- // PARAMS: $stm_name, data array
- // RETURN: query in prepared form
- // DESC : for debug purpose replaces $1, $2, etc with actual data
+ /**
+ * for debug purpose replaces $1, $2, etc with actual data
+ * @param string $stm_name prepared statement name
+ * @param array $data the data array
+ * @return string string of query with data inside
+ */
private function __dbDebugPrepare(string $stm_name, array $data = array()): string
{
// get the keys from data array
@@ -631,11 +629,11 @@ class IO extends \CoreLibs\Basic
return str_replace(array_reverse($keys), array_reverse($data), $this->prepare_cursor[$stm_name]['query']);
}
- // METHOD: __dbReturnTable
- // WAS : _db_return_table
- // PARAMS: insert/select/update/delete query
- // RETURN: array with schema and table
- // DESC : extracts schema and table from the query, if no schema returns just empty string
+ /**
+ * extracts schema and table from the query, if no schema returns just empty string
+ * @param string $query insert/select/update/delete query
+ * @return array array with schema and table
+ */
private function __dbReturnTable(string $query): array
{
if (preg_match("/^SELECT /i", $query)) {
@@ -646,17 +644,18 @@ class IO extends \CoreLibs\Basic
return array($matches[3], $matches[4]);
}
- // METHOD: __dbPrepareExec
- // WAS : _db_prepare_exec
- // PARAMS: query, primary key [if set to NULL no returning will be added]
- // RETURN: md5 OR boolean false on error
- // DESC : sub function for dbExec and dbExecAsync
- // * checks query is set
- // * checks there is a database handler
- // * checks that here is no other query executing
- // * checks for insert if returning is set/pk name
- // * sets internal md5 for query
- // * checks multiple call count
+ /**
+ * sub function for dbExec and dbExecAsync
+ * - checks query is set
+ * - checks there is a database handler
+ * - checks that here is no other query executing
+ * - checks for insert if returning is set/pk name
+ * - sets internal md5 for query
+ * - checks multiple call count
+ * @param string $query query string
+ * @param string $pk_name primary key [if set to NULL no returning will be added]
+ * @return string|bool md5 OR boolean false on error
+ */
private function __dbPrepareExec(string $query, string $pk_name)
{
// to either use the returning method or the guess method for getting primary keys
@@ -744,11 +743,10 @@ class IO extends \CoreLibs\Basic
return $md5;
}
- // METHOD: __dbPostExec
- // WAS : _db_post_exec
- // PARAMS: none
- // RETURN: true on success or false if an error occured
- // DESC : runs post execute for rows affected, field names, inserted primary key, etc
+ /**
+ * runs post execute for rows affected, field names, inserted primary key, etc
+ * @return bool true on success or false if an error occured
+ */
private function __dbPostExec(): bool
{
// if FALSE returned, set error stuff
@@ -791,7 +789,10 @@ class IO extends \CoreLibs\Basic
// echo "** PREPARE RETURNING FOR CURSOR: ".$this->cursor."
";
// we have returning, now we need to check if we get one or many returned
// we'll need to loop this, if we have multiple insert_id returns
- while ($_insert_id = $this->db_functions->__dbFetchArray($this->cursor, PGSQL_ASSOC)) {
+ while ($_insert_id = $this->db_functions->__dbFetchArray(
+ $this->cursor,
+ $this->db_functions->__dbResultType(true)
+ )) {
// echo "*** RETURNING: ".print_r($_insert_id, true)."
";
$this->insert_id[] = $_insert_id;
}
@@ -835,15 +836,15 @@ class IO extends \CoreLibs\Basic
// PUBLIC METHODS
// *************************************************************
- // METHOD: dbSetDebug
- // WAS : db_set_debug
- // PARAMS: true/false or none
- // RETURN: new set debug flag
- // DESC : switches the debug flag on or off
- // if none given, then the debug flag auto switches from
- // the previous setting to either then on or off
- // else override with boolean true/false
- public function dbSetDebug($debug = '')
+ /**
+ * switches the debug flag on or off
+ * if none given, then the debug flag auto switches from
+ * the previous setting to either then on or off
+ * else override with boolean true/false
+ * @param bool|null $debug true/false or null for no set
+ * @return int debug flag in int
+ */
+ public function dbSetDebug($debug = null): int
{
if ($debug === true) {
$this->db_debug = 1;
@@ -857,23 +858,23 @@ class IO extends \CoreLibs\Basic
return $this->db_debug;
}
- // METHOD: dbResetQueryCalled
- // WAS : db_reset_query_called
- // PARAMS: query
- // RETURN: none
- // DESC : resets the call times for the max query called to 0
- // USE CAREFULLY: rather make the query prepare -> execute
- public function dbResetQueryCalled($query)
+ /**
+ * resets the call times for the max query called to 0
+ * USE CAREFULLY: rather make the query prepare -> execute
+ * @param string $query query string
+ * @return void has no return
+ */
+ public function dbResetQueryCalled(string $query): void
{
$this->query_called[md5($query)] = 0;
}
- // METHOD: dbGetQueryCalled
- // WAS : db_get_query_called
- // PARAMS: query
- // RETURN: count of query called
- // DESC : gets how often a query was called already
- public function dbGetQueryCalled($query)
+ /**
+ * gets how often a query was called already
+ * @param string $query query string
+ * @return int count of times the query was executed
+ */
+ public function dbGetQueryCalled(string $query): int
{
$md5 = md5($query);
if ($this->query_called[$md5]) {
@@ -883,13 +884,12 @@ class IO extends \CoreLibs\Basic
}
}
- // METHOD: dbClose
- // WAS : db_close
- // PARAMS: none
- // RETURN: none
- // DESC : closes the db_connection
- // normally this is not used, as the class deconstructor closes the connection down
- public function dbClose()
+ /**
+ * closes the db_connection
+ * normally this is not used, as the class deconstructor closes the connection down
+ * @return void has no return
+ */
+ public function dbClose(): void
{
if ($this->dbh) {
$this->db_functions->__dbClose();
@@ -897,12 +897,12 @@ class IO extends \CoreLibs\Basic
}
}
- // METHOD: dbSetSchema
- // WAS : db_set_schema
- // PARAMS: db_schema: if not given tries internal default db schema
- // RETURN: false on failure to find schema values, true of db exec schema set
- // DESC : sets new db schema
- public function dbSetSchema($db_schema = '')
+ /**
+ * sets new db schema
+ * @param string $db_schema schema name, if not given tries internal default db schema
+ * @return bool false on failure to find schema values, true of db exec schema set
+ */
+ public function dbSetSchema(string $db_schema = '')
{
if (!$db_schema && $this->db_schema) {
$db_schema = $this->db_schema;
@@ -914,22 +914,21 @@ class IO extends \CoreLibs\Basic
return $this->dbExec($q);
}
- // METHOD: dbGetSchema
- // WAS : db_get_schema
- // PARAMS: none
- // RETURN: db_schema current set
- // DESC : returns the current set db schema
- public function dbGetSchema()
+ /**
+ * returns the current set db schema
+ * @return string db schema name
+ */
+ public function dbGetSchema(): string
{
return $this->db_schema;
}
- // METHOD: dbSetEncoding
- // WAS : db_set_encoding
- // PARAMS: valid encoding name, so the the data gets converted to this encoding
- // RETURN: false, or true of db exec encoding set
- // DESC : sets the client encoding in the postgres database
- public function dbSetEncoding($db_encoding = '')
+ /**
+ * sets the client encoding in the postgres database
+ * @param string $db_encoding valid encoding name, so the the data gets converted to this encoding
+ * @return bool false, or true of db exec encoding set
+ */
+ public function dbSetEncoding(string $db_encoding = ''): bool
{
if (!$db_encoding && $this->db_encoding) {
$db_encoding = $this->db_encoding;
@@ -941,21 +940,22 @@ class IO extends \CoreLibs\Basic
return $this->dbExec($q);
}
- // METHOD: dbGetEncoding
- // PARAMS: none
- // RETURN: current client encoding
- // DESC : returns the current set client encoding from the connected DB
- public function dbGetEncoding()
+ /**
+ * returns the current set client encoding from the connected DB
+ * @return string current client encoding
+ */
+ public function dbGetEncoding(): string
{
return $this->dbReturnRow('SHOW client_encoding')['client_encoding'];
}
- // METHOD: dbInfo
- // WAS : db_info
- // PARAMS: show, default 1, if set to 0 won't write to error_msg var
- // RETURN: string with db_connection info
- // DESC : prints out status info from the connected DB (might be usefull for debug stuff)
- public function dbInfo($show = 1)
+ /**
+ * prints out status info from the connected DB (might be usefull for debug stuff)
+ * @param bool|boolean $show show db connection info, default true
+ * if set to false won't write to error_msg var
+ * @return string db connection information string
+ */
+ public function dbInfo(bool $show = true): string
{
$string = '';
$string .= '-DB-info-> Connected to db \''.$this->db_name.'\' ';
@@ -965,7 +965,7 @@ class IO extends \CoreLibs\Basic
$string .= 'on port \''.$this->db_port.'\' ';
$string .= 'with ssl mode \''.$this->db_ssl.'\'
';
$string .= '-DB-info-> DB IO Class debug output: '.(($this->db_debug) ? 'Yes' : 'No').'';
- if ($show) {
+ if ($show === true) {
$this->__dbDebug('db', $string, 'dbInfo');
} else {
$string = $string.'
';
@@ -973,12 +973,12 @@ class IO extends \CoreLibs\Basic
return $string;
}
- // METHOD: dbDumpData
- // WAS : db_dump_data
- // PARAMS: query -> if given, only from this quey (if found)
- // RETURN: formated string with all the data in the array
- // DESC : dumps ALL data for this query, OR if no query given all in cursor_ext array
- public function dbDumpData($query = 0)
+ /**
+ * dumps ALL data for this query, OR if no query given all in cursor_ext array
+ * @param string $query query, if given, only from this quey (if found), else current cursor
+ * @return string formated string with all the data in the array
+ */
+ public function dbDumpData($query = ''): string
{
// set start array
if ($query) {
@@ -995,26 +995,26 @@ class IO extends \CoreLibs\Basic
return $string;
}
- // METHOD: dbReturn
- // WAS : db_return
- // PARAMS: query -> the query ...
- // reset -> if set to 1, at the end of the query (last row returned), the stored array will be deleted ...
- // if set to 2, the data will be read new and cached (wheres 1 reads cache AND destroys at end of read)
- // -> if set to 3, after EACH row, the data will be reset, no caching is done except for basic (count, etc)
- // RETURN: res mixed (array/bool)
- // DESC : single running function, if called creates md5 from
- // query string and so can itself call exec/return calls
- // caches data, so next time called with IDENTICAL (!!!!)
- // [this means 1:1 bit to bit identical query] returns cached
- // data, or with reset flag set calls data from DB again
/**
- * returned array is database number/fieldname -> value element
- * @param string $query Query string
- * @param integer $reset reset status: 1: read cache, clean at the end, 2: read new, clean at end, 3: never cache
- * @param bool $assoc_only true to only returned the named and not index position ones
- * @return array|boolean return array data or false on error/end
+ * single running function, if called creates md5 from
+ * query string and so can itself call exec/return calls
+ * caches data, so next time called with IDENTICAL (!!!!)
+ * [this means 1:1 bit to bit identical query] returns cached
+ * data, or with reset flag set calls data from DB again
+ * NOTE on $reset param:
+ * - if set to 1, at the end of the query (last row returned),
+ * the stored array will be deleted ...
+ * - if set to 2, the data will be read new and cached
+ * (wheres 1 reads cache AND destroys at end of read)
+ * - if set to 3, after EACH row, the data will be reset,
+ * no caching is done except for basic (count, etc)
+ * @param string $query Query string
+ * @param int $reset reset status: 1: read cache, clean at the end, 2: read new, clean at end, 3: never cache
+ * @param bool $assoc_only true to only returned the named and not index position ones
+ * @return array|bool return array data or false on error/end
+ * @suppress PhanTypeMismatchDimFetch
*/
- public function dbReturn($query, $reset = 0, bool $assoc_only = false)
+ public function dbReturn(string $query, int $reset = 0, bool $assoc_only = false)
{
if (!$query) {
$this->error_id = 11;
@@ -1040,7 +1040,7 @@ class IO extends \CoreLibs\Basic
// before doing ANYTHING check if query is "SELECT ..." everything else does not work
if (!$this->__checkQueryForSelect($this->cursor_ext[$md5]['query'])) {
$this->error_id = 17;
- $this->__dbError('', $this->cursor_ext[$md5]['query']);
+ $this->__dbError(false, $this->cursor_ext[$md5]['query']);
return false;
}
// init return als false
@@ -1137,7 +1137,8 @@ class IO extends \CoreLibs\Basic
if (isset($this->cursor_ext[$md5]['data'][$this->cursor_ext[$md5]['pos']][$i])) {
$return[$this->cursor_ext[$md5]['field_names'][$i]] = $this->cursor_ext[$md5]['data'][$this->cursor_ext[$md5]['pos']][$i];
} else {
- // throws PhanTypeMismatchDimFetch error
+ // throws PhanTypeMismatchDimFetch error, but in this case we know we will access only named array parts
+ // @suppress PhanTypeMismatchDimFetch
$return[$this->cursor_ext[$md5]['field_names'][$i]] = $this->cursor_ext[$md5]['data'][$this->cursor_ext[$md5]['pos']][$this->cursor_ext[$md5]['field_names'][$i]];
}
}
@@ -1174,13 +1175,12 @@ class IO extends \CoreLibs\Basic
return $return;
}
- // METHOD: dbCacheReset
- // WAS : db_cache_reset
- // PARAMS: $query -> The Query whose cache should be cleaned
- // RETURN: 0 if failure (eg no query with this md5 found)
- // 1 if successfull
- // DESC : resets all data stored to this query
- public function dbCacheReset($query)
+ /**
+ * resets all data stored to this query
+ * @param string $query The Query whose cache should be cleaned
+ * @return bool false if query not found, true if success
+ */
+ public function dbCacheReset(string $query): bool
{
$md5 = md5($query);
// clears cache for this query
@@ -1193,19 +1193,19 @@ class IO extends \CoreLibs\Basic
return true;
}
- // METHOD: dbExec
- // METHOD: db_exec
- // PARAMS: query -> the query, if not given, the query class var will be used
- // (if this was not set, method will quit with a 0 (failure)
- // pk_name -> optional primary key name, for insert id return if the pk name is very different
- // if pk name is table name and _id, pk_name is not needed to be set
- // if NULL is given here, no RETURNING will be auto added
- // RETURN: cursor for this query
- // DESC : executes the query and returns & sets the internal cursor
- // fruthermore this functions also sets varios other vars
- // like num_rows, num_fields, etc depending on query
- // for INSERT INTO queries it is highly recommended to set the pk_name to avoid an additional
- // read from the database for the PK NAME
+ /**
+ * executes the query and returns & sets the internal cursor
+ * furthermore this functions also sets varios other vars
+ * like num_rows, num_fields, etc depending on query
+ * for INSERT INTO queries it is highly recommended to set the pk_name to avoid an
+ * additional read from the database for the PK NAME
+ * @param string $query the query, if not given, the query class var will be used
+ * (if this was not set, method will quit with a 0 (failure)
+ * @param string $pk_name optional primary key name, for insert id return if the pk name is very different
+ * if pk name is table name and _id, pk_name is not needed to be set
+ * if NULL is given here, no RETURNING will be auto added
+ * @return resource|false cursor for this query or false on error
+ */
public function dbExec(string $query = '', string $pk_name = '')
{
// prepare and check if we can actually run it
@@ -1224,15 +1224,15 @@ class IO extends \CoreLibs\Basic
}
}
- // METHOD: dbExecAsync
- // WAS : db_exec_async
- // PARAMS: query -> query to run
- // pk_name -> optional primary key name, only used with insert for returning call
- // RETURN: true if async query was sent ok, false if error happened
- // DESC : executres the query async so other methods can be run during this
- // for INSERT INTO queries it is highly recommended to set the pk_name to avoid an additional
- // read from the database for the PK NAME
- // NEEDS : dbCheckAsync
+ /**
+ * executres the query async so other methods can be run during this
+ * for INSERT INTO queries it is highly recommended to set the pk_name to avoid an additional
+ * read from the database for the PK NAME
+ * NEEDS : dbCheckAsync
+ * @param string $query query to run
+ * @param string $pk_name optional primary key name, only used with insert for returning call
+ * @return bool true if async query was sent ok, false if error happened
+ */
public function dbExecAsync(string $query, string $pk_name = ''): bool
{
// prepare and check if we can actually run the query
@@ -1253,13 +1253,12 @@ class IO extends \CoreLibs\Basic
}
}
- // METHOD: dbCheckAsync
- // WAS : db_check_async
- // PARAMS: none
- // RETURN: true if the query is still running, false if an error occured or cursor of that query
- // DESC : checks a previous async query and returns data if finished
- // NEEDS : dbExecAsync
- public function dbCheckAsync()
+ /**
+ * checks a previous async query and returns data if finished
+ * NEEDS : dbExecAsync
+ * @return bool true if the query is still running, false if an error occured or cursor of that query
+ */
+ public function dbCheckAsync(): bool
{
// if there is actually a async query there
if ($this->async_running) {
@@ -1284,14 +1283,14 @@ class IO extends \CoreLibs\Basic
}
}
- // METHOD: dbFetchArray
- // WAS : db_fetch_array
- // PARAMS: cusors -> the cursor from db_exec or pg_query/pg_exec/mysql_query
- // if not set will use internal cursor, if not found, stops with 0 (error)
- // assoc_only -> false is default, if true only assoc rows
- // RETURN: a mixed row
- // DESC : executes a cursor and returns the data, if no more data 0 will be returned
- public function dbFetchArray($cursor = 0, bool $assoc_only = false)
+ /**
+ * executes a cursor and returns the data, if no more data 0 will be returned
+ * @param resource|false $cursor the cursor from db_exec or pg_query/pg_exec/mysql_query
+ * if not set will use internal cursor, if not found, stops with 0 (error)
+ * @param bool $assoc_only false is default, if true only assoc rows
+ * @return array|bool row array or false on error
+ */
+ public function dbFetchArray($cursor = false, bool $assoc_only = false)
{
// return false if no query or cursor set ...
if (!$cursor) {
@@ -1310,12 +1309,12 @@ class IO extends \CoreLibs\Basic
);
}
- // METHOD: dbReturnRow
- // WAS : db_return_row
- // PARAMS: query -> the query to be executed
- // assoc_only -> if true, only return assoc entry, else both (pgsql)
- // RETURN: mixed db result
- // DESC : returns the FIRST row of the given query
+ /**
+ * returns the FIRST row of the given query
+ * @param string $query the query to be executed
+ * @param bool $assoc_only if true, only return assoc entry, else both (pgsql)
+ * @return array|bool row array or false on error
+ */
public function dbReturnRow(string $query, bool $assoc_only = false)
{
if (!$query) {
@@ -1326,7 +1325,7 @@ class IO extends \CoreLibs\Basic
// before doing ANYTHING check if query is "SELECT ..." everything else does not work
if (!$this->__checkQueryForSelect($query)) {
$this->error_id = 17;
- $this->__dbError('', $query);
+ $this->__dbError(false, $query);
return false;
}
$cursor = $this->dbExec($query);
@@ -1334,12 +1333,12 @@ class IO extends \CoreLibs\Basic
return $result;
}
- // METHOD: dbReturnArray
- // WAS : db_return_array
- // PARAMS: query -> the query to be executed
- // assoc_only -> if true, only name ref are returned
- // RETURN: array of hashes (row -> fields)
- // DESC : createds an array of hashes of the query (all data)
+ /**
+ * createds an array of hashes of the query (all data)
+ * @param string $query the query to be executed
+ * @param bool $assoc_only if true, only name ref are returned
+ * @return array|bool array of hashes (row -> fields), false on error
+ */
public function dbReturnArray(string $query, bool $assoc_only = false)
{
if (!$query) {
@@ -1350,7 +1349,7 @@ class IO extends \CoreLibs\Basic
// before doing ANYTHING check if query is "SELECT ..." everything else does not work
if (!$this->__checkQueryForSelect($query)) {
$this->error_id = 17;
- $this->__dbError('', $query);
+ $this->__dbError(false, $query);
return false;
}
$cursor = $this->dbExec($query);
@@ -1365,11 +1364,11 @@ class IO extends \CoreLibs\Basic
return $rows;
}
- // METHOD: dbCursorPos
- // WAS : db_cursor_pos
- // PARAMS: $query -> query to find in cursor_ext
- // RETURN: position (int)
- // DESC : returns the current position the read out
+ /**
+ * returns the current position the read out
+ * @param string $query query to find in cursor_ext
+ * @return int|bool query position (row pos), false on error
+ */
public function dbCursorPos(string $query)
{
if (!$query) {
@@ -1381,11 +1380,11 @@ class IO extends \CoreLibs\Basic
return $this->cursor_ext[$md5]['pos'];
}
- // METHOD: dbCursorNumRows
- // WAS : db_cursor_num_rows
- // PARAMS: $query -> query to find in cursor_ext
- // RETURN: row count (int)
- // DESC : returns the number of rows for the current select query
+ /**
+ * returns the number of rows for the current select query
+ * @param string $query query to find in cursor_ext
+ * @return int|bool query position (row pos), false on error
+ */
public function dbCursorNumRows(string $query)
{
if (!$query) {
@@ -1397,12 +1396,12 @@ class IO extends \CoreLibs\Basic
return $this->cursor_ext[$md5]['num_rows'];
}
- // METHOD: dbShowTableMetaData
- // WAS : db_show_table_meta_data
- // PARAMS: $table -> table name
- // $schema -> optional schema name
- // RETURN: array of table data, false on error (table not found)
- // DESC : returns an array of the table with columns and values. FALSE on no table found
+ /**
+ * returns an array of the table with columns and values. FALSE on no table found
+ * @param string $table table name
+ * @param string $schema optional schema name
+ * @return array|bool array of table data, false on error (table not found)
+ */
public function dbShowTableMetaData(string $table, string $schema = '')
{
$table = ($schema ? $schema.'.' : '').$table;
@@ -1414,13 +1413,15 @@ class IO extends \CoreLibs\Basic
return $array;
}
- // METHOD: dbPrepare
- // WAS : db_prepare
- // PARAMS: $stm_name, $query, $pk_name: optional
- // RETURN: false on error, true on warning or result on full ok
- // DESC : prepares a query
- // for INSERT INTO queries it is highly recommended to set the pk_name to avoid an additional
- // read from the database for the PK NAME
+ /**
+ * prepares a query
+ * for INSERT INTO queries it is highly recommended to set the pk_name to avoid an additional
+ * read from the database for the PK NAME
+ * @param string $stm_name statement name
+ * @param string $query queryt string to run
+ * @param string $pk_name optional primary key
+ * @return bool|resource false on error, true on warning or result on full ok
+ */
public function dbPrepare(string $stm_name, string $query, string $pk_name = '')
{
if (!$query) {
@@ -1497,11 +1498,12 @@ class IO extends \CoreLibs\Basic
}
}
- // METHOD: dbExecute
- // WAS : db_execute
- // PARAMS: $stm_name, data array
- // RETURN: false on error, result on OK
- // DESC : runs a prepare query
+ /**
+ * runs a prepare query
+ * @param string $stm_name statement name for the query to run
+ * @param array $data data to run for this query, empty array for none
+ * @return ?mixed false on error, or result on OK
+ */
public function dbExecute(string $stm_name, array $data = array())
{
// if we do not have no prepare cursor array entry for this statement name, abort
@@ -1525,7 +1527,7 @@ class IO extends \CoreLibs\Basic
}
$result = $this->db_functions->__dbExecute($stm_name, $data);
if (!$result) {
- $this->debug('ExecuteData', 'ERROR in STM['.$stm_name.'|'.$this->prepare_cursor[$stm_name]['result'].']: '.$this->print_ar($data));
+ $this->debug('ExecuteData', 'ERROR in STM['.$stm_name.'|'.$this->prepare_cursor[$stm_name]['result'].']: '.$this->printAr($data));
$this->error_id = 22;
$this->__dbError($this->prepare_cursor[$stm_name]['result']);
$this->__dbDebug('db', 'DB-Error '.$stm_name.': Execution failed', 'DB_ERROR');
@@ -1541,7 +1543,10 @@ class IO extends \CoreLibs\Basic
$this->insert_id_ext = array ();
// we have returning, now we need to check if we get one or many returned
// we'll need to loop this, if we have multiple insert_id returns
- while ($_insert_id = $this->db_functions->__dbFetchArray($result, PGSQL_ASSOC)) {
+ while ($_insert_id = $this->db_functions->__dbFetchArray(
+ $result,
+ $this->db_functions->__dbResultType(true)
+ )) {
$this->insert_id[] = $_insert_id;
}
// if we have only one, revert from arry to single
@@ -1583,42 +1588,51 @@ class IO extends \CoreLibs\Basic
}
}
- // METHOD: dbEscapeString
- // WAS : db_escape_string
- // PARAMS: $string -> string to escape
- // RETURN: escaped string
- // DESC : neutral function to escape a string for DB writing
- public function dbEscapeString(string $string): string
+ /**
+ * neutral function to escape a string for DB writing
+ * @param string|int|float|bool $string string to escape
+ * @return string escaped string
+ */
+ public function dbEscapeString($string): string
{
return $this->db_functions->__dbEscapeString($string);
}
- // METHOD: dbEscapeBytea
- // WAS : db_escape_bytea
- // PARAMS: $bytea -> bytea to escape
- // RETURN: escaped bytea
- // DESC : neutral function to escape a bytea for DB writing
+ /**
+ * neutral function to escape a string for DB writing
+ * this one adds '' quotes around the string
+ * @param string|int|float|bool $string string to escape
+ * @return string escaped string
+ */
+ public function dbEscapeLiteral($string): string
+ {
+ return $this->db_functions->__dbEscapeLiteral($string);
+ }
+
+ /**
+ * neutral function to escape a bytea for DB writing
+ * @param string $bytea bytea to escape
+ * @return string escaped bytea
+ */
public function dbEscapeBytea($bytea)
{
return $this->db_functions->__dbEscapeBytea($bytea);
}
- // METHOD: dbVersion
- // WAS : db_version
- // PARAMS: none
- // RETURN: database version as string
- // DESC : return current database version
+ /**
+ * return current database version
+ * @return string database version as string
+ */
public function dbVersion(): string
{
return $this->db_functions->__dbVersion();
}
- // METHOD: dbCompareVersion
- // WAS : db_compare_version
- // PARAMS: string to which the return will return true or false
- // =X.Y, >X.Y, X.Y, =X.Y
+ * @return bool true for ok, false on not ok
+ */
public function dbCompareVersion(string $compare): bool
{
// compare has =, >, < prefix, and gets stripped, if the rest is not X.Y format then error
@@ -1671,11 +1685,12 @@ class IO extends \CoreLibs\Basic
return $return;
}
- // METHOD: dbBoolean
- // WAS : db_boolean
- // PARAMS: 't' / 'f' or any string
- // RETURN: correct php boolean true/false
- // DESC : if the input is a single char 't' or 'f' it will return the boolean value instead
+ /**
+ * if the input is a single char 't' or 'f' it will return the boolean value instead
+ * @param string|bool $string 't' / 'f' or any string, or bool true/false
+ * @param boolean $rev do reverse (bool to string)
+ * @return bool|string correct php boolean true/false or postgresql 't'/'f'
+ */
public function dbBoolean($string, $rev = false)
{
if (!$rev) {
@@ -1706,15 +1721,16 @@ class IO extends \CoreLibs\Basic
// db_write_data is the old without separate update no write list
// db_write_data_ext is the extended with additional array for no write list for update
- // METHOD: dbWriteData
- // WAS : db_write_data
- // PARAMS: write_array -> list of elements to write
- // not_write_array -> list of elements not to write
- // primary_key -> id key to decide if we write insert or update
- // table -> name for the target table
- // RETURN: primary key id
- // DESC: writes into one table based on array of table columns
- public function dbWriteData($write_array, $not_write_array, $primary_key, $table, $data = array ())
+ /**
+ * writes into one table based on array of table columns
+ * @param array $write_array list of elements to write
+ * @param array $not_write_array list of elements not to write
+ * @param int $primary_key id key to decide if we write insert or update
+ * @param string $table name for the target table
+ * @param array $data data array to override _POST data
+ * @return int|bool primary key
+ */
+ public function dbWriteData(array $write_array, array $not_write_array, $primary_key, string $table, $data = array ())
{
if (!is_array($write_array)) {
$write_array = array ();
@@ -1729,21 +1745,19 @@ class IO extends \CoreLibs\Basic
return $this->dbWriteDataExt($write_array, $primary_key, $table, $not_write_array, $not_write_update_array, $data);
}
- // METHOD: dbWriteDataExt
- // WAS : db_write_data_ext
- // PARAMS: write_array -> list of elements to write
- // primary_key -> id key to decide if we write insert or update
- // -> alternate the primary key can be an array with
- // 'row' => 'row name', 'value' => 'data' to use a
- // different column as the primary key
- // !!! primary key can be an array or a number/string
- // table -> name for the target table
- // (optional)
- // not_write_array -> list of elements not to write
- // not_write_update_array -> list of elements not to write during update
- // data -> optional array with data, if not _POST vars are used
- // RETURN: primary key id
- // DESC : writes into one table based on array of table columns
+ /**
+ * writes into one table based on array of table columns
+ * PARAM INFO: $primary key
+ * this can be a plain string/int and will be internal transformed into the array form
+ * or it takes the array form of array (row => column, value => pk value)
+ * @param array $write_array list of elements to write
+ * @param int|string|array $primary_key primary key string or array set
+ * @param string $table name for the target table
+ * @param array $not_write_array list of elements not to write (optional)
+ * @param array $not_write_update_array list of elements not to write during update (optional)
+ * @param array $data optional array with data, if not _POST vars are used
+ * @return int|bool primary key
+ */
public function dbWriteDataExt(
array $write_array,
$primary_key,
@@ -1843,12 +1857,12 @@ class IO extends \CoreLibs\Basic
return $primary_key['value'];
}
- // METHOD: dbTimeFormat
- // WAS : db_time_format
- // PARAMS: age or datetime difference
- // micro on off (default false)
- // RETURN: Y/M/D/h/m/s formatted string (like TimeStringFormat
- // DESC : only for postgres. pretty formats an age or datetime difference string
+ /**
+ * only for postgres. pretty formats an age or datetime difference string
+ * @param string $age age or datetime difference
+ * @param bool $show_micro micro on off (default false)
+ * @return string Y/M/D/h/m/s formatted string (like TimeStringFormat)
+ */
public function dbTimeFormat(string $age, bool $show_micro = false): string
{
// in string (datetime diff): 1786 days 22:11:52.87418
@@ -1866,11 +1880,11 @@ class IO extends \CoreLibs\Basic
return $prefix.($hour ? $hour.'h ' : '').($minutes ? $minutes.'m ' : '').($seconds ? $seconds.'s' : '').($show_micro && $milliseconds? ' '.$milliseconds.'ms' : '');
}
- // METHOD: dbArrayParse
- // WAS : db_array_parse
- // PARAMS: text: input text to parse to an array
- // RETURN: PHP array of the parsed data
- // DESC : this is only needed for Postgresql. Converts postgresql arrays to PHP
+ /**
+ * this is only needed for Postgresql. Converts postgresql arrays to PHP
+ * @param string $text input text to parse to an array
+ * @return array PHP array of the parsed data
+ */
public function dbArrayParse(string $text): array
{
$output = array ();
@@ -1883,6 +1897,12 @@ class IO extends \CoreLibs\Basic
// kbn -> escape trigger type
// RETURN: escaped value
// DESC : clear up any data for valid DB insert
+ /**
+ * clear up any data for valid DB insert
+ * @param int|float|string $value to escape data
+ * @param string $kbn escape trigger type
+ * @return string escaped value
+ */
public function dbSqlEscape($value, string $kbn = '')
{
switch ($kbn) {
@@ -1904,320 +1924,6 @@ class IO extends \CoreLibs\Basic
}
return $value;
}
-
- // *************************************************************
- // COMPATIBILITY METHODS
- // those methods are deprecated function call names
- // they exist for backwards compatibility only
- // *************************************************************
-
- private function _connect_to_db()
- {
- error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
- trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
- return $this->__connectToDB();
- }
-
- private function _close_db()
- {
- error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
- trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
- $this->__closeDB();
- }
-
- private function _check_query_for_select($query)
- {
- error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
- trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
- return $this->__checkQueryForSelect($query);
- }
-
- private function _check_query_for_insert($query, $pure = false)
- {
- error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
- trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
- return $this->__checkQueryForInsert($query, $pure);
- }
-
- private function _print_array($array)
- {
- error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
- trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
- return $this->__printArray($array);
- }
-
- private function _db_debug($debug_id, $error_string, $id = '', $type = '')
- {
- error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
- trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
- $this->__dbDebug($debug_id, $error_string, $id, $type);
- }
-
- public function _db_error($cursor = '', $msg = '')
- {
- error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
- trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
- $this->__dbError($cursor, $msg);
- }
-
- private function _db_convert_encoding($row)
- {
- error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
- trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
- return $this->__dbConvertEncoding($row);
- }
-
- private function _db_debug_prepare($stm_name, $data = array())
- {
- error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
- trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
- return $this->__dbDebugPrepare($stm_name, $data);
- }
-
- private function _db_return_table($query)
- {
- error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
- trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
- return $this->__dbReturnTable($query);
- }
-
- private function _db_prepare_exec($query, $pk_name)
- {
- error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
- trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
- return $this->__dbPrepareExec($query, $pk_name);
- }
-
- private function _db_post_exec()
- {
- error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
- trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
- return $this->__dbPostExec();
- }
-
- public function db_set_debug($debug = '')
- {
- error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
- trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
- return $this->dbSetDebug($debug);
- }
-
- public function db_reset_query_called($query)
- {
- error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
- trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
- return $this->dbResetQueryCalled($query);
- }
-
- public function db_get_query_called($query)
- {
- error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
- trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
- return $this->dbGetQueryCalled($query);
- }
-
- public function db_close()
- {
- error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
- trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
- return $this->dbClose();
- }
-
- public function db_set_schema($db_schema = '')
- {
- error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
- trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
- return $this->dbSetSchema($db_schema);
- }
-
- public function db_get_schema()
- {
- error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
- trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
- return $this->dbGetSchema();
- }
-
- public function db_set_encoding($db_encoding = '')
- {
- error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
- trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
- return $this->dbSetEncoding($db_encoding);
- }
-
- public function db_info($show = 1)
- {
- error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
- trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
- return $this->dbInfo($show);
- }
-
- public function db_dump_data($query = 0)
- {
- error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
- trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
- return $this->dbDumpData($query);
- }
-
- public function db_return($query, $reset = 0)
- {
- error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
- trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
- return $this->dbReturn($query, $reset);
- }
-
- public function db_cache_reset($query)
- {
- error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
- trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
- return $this->dbCacheReset($query);
- }
-
- public function db_exec($query = '', $pk_name = '')
- {
- error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
- trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
- return $this->dbExec($query, $pk_name);
- }
-
- public function db_exec_async($query, $pk_name = '')
- {
- error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
- trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
- return $this->dbExecAsync($query, $pk_name);
- }
-
- public function db_check_async()
- {
- error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
- trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
- return $this->dbCheckAsync();
- }
-
- public function db_fetch_array($cursor = 0)
- {
- error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
- trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
- return $this->dbFetchArray($cursor);
- }
-
- public function db_return_row($query)
- {
- error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
- trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
- return $this->dbReturnRow($query);
- }
-
- public function db_return_array($query, $named_only = false)
- {
- error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
- trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
- return $this->dbReturnArray($query, $named_only);
- }
-
- public function db_cursor_pos($query)
- {
- error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
- trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
- return $this->dbCursorPos($query);
- }
-
- public function db_cursor_num_rows($query)
- {
- error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
- trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
- return $this->dbCursorNumRows($query);
- }
-
- public function db_show_table_meta_data($table, $schema = '')
- {
- error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
- trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
- return $this->dbShowTableMetaData($table, $schema);
- }
-
- public function db_prepare($stm_name, $query, $pk_name = '')
- {
- error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
- trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
- return $this->dbPrepare($stm_name, $query, $pk_name);
- }
-
- public function db_execute($stm_name, $data = array())
- {
- error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
- trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
- return $this->dbExecute($stm_name, $data);
- }
-
- public function db_escape_string($string)
- {
- error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
- trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
- return $this->dbEscapeString($string);
- }
-
- public function db_escape_bytea($bytea)
- {
- error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
- trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
- return $this->dbEscapeBytea($bytea);
- }
-
- public function db_version()
- {
- error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
- trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
- return $this->dbVersion();
- }
-
- public function db_compare_version($compare)
- {
- error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
- trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
- return $this->dbCompareVersion($compare);
- }
-
- public function db_boolean($string, $rev = false)
- {
- error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
- trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
- return $this->dbBoolean($string, $rev);
- }
-
- public function db_write_data($write_array, $not_write_array, $primary_key, $table, $data = array ())
- {
- error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
- trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
- return $this->dbWriteData($write_array, $not_write_array, $primary_key, $table, $data);
- }
-
- public function db_write_data_ext($write_array, $primary_key, $table, $not_write_array = array (), $not_write_update_array = array (), $data = array ())
- {
- error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
- trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
- return $this->dbWriteDataExt($write_array, $primary_key, $table, $not_write_array, $not_write_update_array, $data);
- }
-
- public function db_time_format($age, $show_micro = false)
- {
- error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
- trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
- return $this->dbTimeFormat($age, $show_micro);
- }
-
- public function db_array_parse($text)
- {
- error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
- trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
- return $this->dbArrayParse($text);
- }
-
- public function db_sql_escape($value, $kbn = "")
- {
- error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
- trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
- return $this->dbSqlEscape($value, $kbn);
- }
} // end if db class
// __END__
diff --git a/www/lib/CoreLibs/DB/SQL/PgSQL.php b/www/lib/CoreLibs/DB/SQL/PgSQL.php
index 9f66a19e..6c4b71e3 100644
--- a/www/lib/CoreLibs/DB/SQL/PgSQL.php
+++ b/www/lib/CoreLibs/DB/SQL/PgSQL.php
@@ -48,19 +48,17 @@ class PgSQL
private $last_error_query;
private $dbh;
- // METHOD: __construct
- // PARAMS: none
- // RETURN: none
- // DESC : class constructor
+ /**
+ * class constructor, empty does nothing
+ */
public function __construct()
{
}
- // METHOD: __dbLastErrorQuery
- // WAS : _db_last_error_query
- // PARAMS: none
- // RETURN: true/false if last error is set
- // DESC : queries last error query and returns true or false if error was set
+ /**
+ * queries last error query and returns true or false if error was set
+ * @return bool true/false if last error is set
+ */
public function __dbLastErrorQuery()
{
if ($this->last_error_query) {
@@ -70,12 +68,12 @@ class PgSQL
}
}
- // METHOD: __dbQuery
- // WAS : _db_query
- // PARAMS: query
- // RETURN: query result
- // DESC : wrapper for gp_query, catches error and stores it in class var
- public function __dbQuery($query)
+ /**
+ * wrapper for gp_query, catches error and stores it in class var
+ * @param string $query query string
+ * @return resource|bool query result
+ */
+ public function __dbQuery(string $query)
{
$this->last_error_query = '';
// read out the query status and save the query if needed
@@ -86,21 +84,20 @@ class PgSQL
return $result;
}
- // METHOD: __dbSendQuery
- // WAS : _db_send_query
- // PARAMS: query
- // RETURN: true/false if query was sent successful
- // DESC : sends an async query to the server
- public function __dbSendQuery($query)
+ /**
+ * sends an async query to the server
+ * @param string $query query string
+ * @return bool true/false if query was sent successful
+ */
+ public function __dbSendQuery(string $query): bool
{
return pg_send_query($this->dbh, $query);
}
- // METHOD: __dbGetResult
- // WAS : _db_get_result
- // PARAMS: none
- // RETURN: resource handler
- // DESC : wrapper for pg_get_result
+ /**
+ * wrapper for pg_get_result
+ * @return resource|bool resource handler or false for error
+ */
public function __dbGetResult()
{
$this->last_error_query = '';
@@ -111,12 +108,11 @@ class PgSQL
return $result;
}
- // METHOD: __dbClose
- // WAS : _db_close
- // PARAMS: none
- // RETURN: none
- // DESC : wrapper for pg_close
- public function __dbClose()
+ /**
+ * wrapper for pg_close
+ * @return void has no return
+ */
+ public function __dbClose(): void
{
if (is_resource($this->dbh)) {
if (pg_connection_status($this->dbh) === PGSQL_CONNECTION_OK) {
@@ -125,12 +121,13 @@ class PgSQL
}
}
- // METHOD: __dbPrepare
- // WAS : _db_prepare
- // PARAMS: prepare name, query
- // RETURN: prepared statement handler
- // DESC : wrapper for pg_prepare
- public function __dbPrepare($name, $query)
+ /**
+ * wrapper for pg_prepare
+ * @param string $name statement name
+ * @param string $query query string
+ * @return resource|bool prepare statement handler or false for error
+ */
+ public function __dbPrepare(string $name, string $query)
{
$result = pg_prepare($this->dbh, $name, $query);
if (!$result) {
@@ -139,12 +136,13 @@ class PgSQL
return $result;
}
- // METHOD: __dbExecute
- // WAS : _db_execute
- // PARAMS: prepare name, data for query
- // RETURN: returns status
- // DESC : wrapper for pg_execute for running a prepared statement
- public function __dbExecute($name, $data)
+ /**
+ * wrapper for pg_execute for running a prepared statement
+ * @param string $name statement name
+ * @param array $data data array
+ * @return resource|bool returns status or false for error
+ */
+ public function __dbExecute(string $name, array $data)
{
$result = pg_execute($this->dbh, $name, $data);
if (!$result) {
@@ -153,95 +151,94 @@ class PgSQL
return $result;
}
- // METHOD: __dbNumRows
- // WAS : _db_num_rows
- // PARAMS: cursor
- // RETURN: rows
- // DESC : wrapper for pg_num_rows
- public function __dbNumRows($cursor)
+ /**
+ * wrapper for pg_num_rows
+ * @param resource $cursor cursor resource
+ * @return int number of rows, -1 on error
+ */
+ public function __dbNumRows($cursor): int
{
return pg_num_rows($cursor);
}
- // METHOD: __dbNumFields
- // WAS : _db_num_fields
- // PARAMS: cursor
- // RETURN: number for fields in query
- // DESC : wrapper for pg_num_fields
- public function __dbNumFields($cursor)
+ /**
+ * wrapper for pg_num_fields
+ * @param resource $cursor cursor resource
+ * @return int number for fields in result, -1 on error
+ */
+ public function __dbNumFields($cursor): int
{
return pg_num_fields($cursor);
}
- // METHOD: __dbFieldName
- // WAS : _db_field_name
- // PARAMS: cursor, field position
- // RETURN: name of field
- // DESC : wrapper for pg_field_name
+ /**
+ * wrapper for pg_field_name
+ * @param resource $cursor cursor resource
+ * @param int $i field position
+ * @return string|bool name or false on error
+ */
public function __dbFieldName($cursor, $i)
{
return pg_field_name($cursor, $i);
}
- // METHOD: __dbFetchArray
- // WAS : _db_fetch_array
- // PARAMS: cursor, opt result type
- // RETURN: row
- // DESC : wrapper for pg_fetch_array
- public function __dbFetchArray($cursor, $result_type = '')
+ /**
+ * wrapper for pg_fetch_array
+ * if through/true false, use __dbResultType(true)
+ * @param resource $cursor cursor resource
+ * @param int $result_type result type as int number
+ * @return array|bool array result data or false on end/error
+ */
+ public function __dbFetchArray($cursor, int $result_type = PGSQL_BOTH)
{
- if ($result_type == true) {
- $result_type = PGSQL_ASSOC;
- }
// result type is passed on as is [should be checked]
- if ($result_type) {
- return pg_fetch_array($cursor, null, $result_type);
- } else {
- return pg_fetch_array($cursor);
- }
+ return pg_fetch_array($cursor, null, $result_type);
}
- // METHOD: __dbResultType
- // PARAMS: true/false for ASSOC only or BOTH
- // RETURN: PGSQL assoc type
- // DESC : simple match up between assoc true/false
- public function __dbResultType($assoc_type)
+ /**
+ * simple match up between assoc true/false
+ * @param bool $assoc_type true (default) for PGSQL_ASSOC, false for PGSQL_BOTH
+ * @return int valid result type for fetch array
+ */
+ public function __dbResultType(bool $assoc_type = true): int
{
if ($assoc_type == true) {
return PGSQL_ASSOC;
}
- return ''; // fallback to default
+ // fallback to default
+ return PGSQL_BOTH;
}
- // METHOD: __dbFetchAll
- // WAS : _db_fetch_all
- // PARAMS: cursor
- // RETURN: all rows as array
- // DESC : wrapper for pg_fetch_array
+ /**
+ * wrapper for pg_fetch_all
+ * @param resource $cursor cursor resource
+ * @return array|bool data array or false for end/error
+ */
public function __dbFetchAll($cursor)
{
return pg_fetch_all($cursor);
}
- // METHOD: __dbAffectedRows
- // WAS : _db_affected_rows
- // PARAMS: cursor
- // RETURN: number for rows
- // DESC : wrapper for pg_affected_rows
- public function __dbAffectedRows($cursor)
+ /**
+ * wrapper for pg_affected_rows
+ * @param resource $cursor cursor resource
+ * @return int affected rows, 0 for none
+ */
+ public function __dbAffectedRows($cursor): int
{
return pg_affected_rows($cursor);
}
- // METHOD: __dbInsertId
- // WAS : _db_insert_id
- // PARAMS: query, primary key name
- // RETURN: last insert primary key
- // DESC : reads the last inserted primary key for the query
- // if ther is no pk_name tries to auto built it from the table name
- // this only works if db schema is after "no plural names. and pk name is table name + _id
- // detects schema prefix in table name
- public function __dbInsertId($query, $pk_name)
+ /**
+ * reads the last inserted primary key for the query
+ * if there is no pk_name tries to auto built it from the table name
+ * this only works if db schema is after "no plural names. and pk name is table name + _id
+ * detects schema prefix in table name
+ * @param string $query query string
+ * @param string $pk_name primary key name, if '' then auto detect
+ * @return string|int primary key value
+ */
+ public function __dbInsertId(string $query, string $pk_name)
{
// only if an insert has been done
if (preg_match("/^insert /i", $query)) {
@@ -275,12 +272,13 @@ class PgSQL
}
}
- // METHOD: __dbPrimaryKey
- // WAS : _db_primary_key
- // PARAMS: table and optional schema
- // RETURN: primary key name OR false if not possible
- // DESC : queries database for the primary key name to this table in the selected schema
- public function __dbPrimaryKey($table, $schema = '')
+ /**
+ * queries database for the primary key name to this table in the selected schema
+ * @param string $table table name
+ * @param string $schema optional schema name, '' for default
+ * @return string|bool primary key name or false if not found
+ */
+ public function __dbPrimaryKey(string $table, string $schema = '')
{
if ($table) {
// check if schema set is different from schema given, only needed if schema is not empty
@@ -322,12 +320,17 @@ class PgSQL
}
}
- // METHOD: __dbConnect
- // WAS : _db_connect
- // PARAMS: host name, user name, password, database name, optional port (defaults to default postgres port), optional ssl (default allow)
- // RETURN: database handler
- // DESC : wrapper for pg_connect, writes out failure to screen if error occurs (hidden var)
- public function __dbConnect($db_host, $db_user, $db_pass, $db_name, $db_port = 5432, $db_ssl = 'allow')
+ /**
+ * wrapper for pg_connect, writes out failure to screen if error occurs (hidden var)
+ * @param string $db_host host name
+ * @param string $db_user user name
+ * @param string $db_pass password
+ * @param string $db_name databse name
+ * @param integer $db_port port (int, 5432 is default)
+ * @param string $db_ssl SSL (allow is default)
+ * @return ?resource db handler resource or null on error
+ */
+ public function __dbConnect(string $db_host, string $db_user, string $db_pass, string $db_name, int $db_port = 5432, string $db_ssl = 'allow')
{
// to avoid empty db_port
if (!$db_port) {
@@ -336,16 +339,18 @@ class PgSQL
$this->dbh = pg_connect("host=".$db_host." port=".$db_port." user=".$db_user." password=".$db_pass." dbname=".$db_name." sslmode=".$db_ssl);
if (!$this->dbh) {
die("");
+ return null;
}
return $this->dbh;
}
- // METHOD: __dbPrintError
- // WAS : _db_print_error
- // PARAMS: database handler, cursor
- // RETURN: error string (HTML)
- // DESC : reads the last error for this cursor
- public function __dbPrintError($cursor = '')
+ /**
+ * reads the last error for this cursor and returns
+ * html formatted string with error name
+ * @param ?resource $cursor cursor resource or null
+ * @return string error string
+ */
+ public function __dbPrintError($cursor = null): string
{
// run the query again for the error result here
if (!$cursor && $this->last_error_query) {
@@ -355,56 +360,71 @@ class PgSQL
}
if (pg_result_error($cursor)) {
return "-PostgreSQL-Error-> ".pg_result_error($cursor)."
";
+ } else {
+ return '';
}
}
- // METHOD: __dbMetaData
- // WAS : _db_meta_data
- // PARAMS: table name
- // RETURN: array with table data
- // DESC : wrapper for pg_emta_data
- public function __dbMetaData($table)
+ /**
+ * wrapper for pg_meta_data
+ * @param string $table table name
+ * @param bool $extended show extended info (default false)
+ * @return array|bool array data for the table info or false on error
+ */
+ public function __dbMetaData(string $table, $extended = false)
{
// needs to prefixed with @ or it throws a warning on not existing table
- return @pg_meta_data($this->dbh, $table);
+ return @pg_meta_data($this->dbh, $table, $extended);
}
- // METHOD: __dbEscapeString
- // WAS : _db_escape_string
- // PARAMS: string
- // RETURN: escaped string for postgres
- // DESC : wrapper for pg_escape_string
- public function __dbEscapeString($string)
+ /**
+ * wrapper for pg_escape_string
+ * @param string|int|float|bool $string any string/int/float/bool
+ * @return string excaped string
+ */
+ public function __dbEscapeString($string): string
{
return pg_escape_string($this->dbh, (string)$string);
}
- // METHOD: __dbEscapeBytea
- // WAS : _db_escape_bytea
- // PARAMS: string
- // RETURN: escape bytes for postgres
- // DESC : wrapper for pg_escape_bytea
- public function __dbEscapeBytea($bytea)
+ /**
+ * wrapper for pg_escape_literal
+ * difference to escape string is that this one adds quotes ('') around
+ * the string too
+ * @param string|int|float|bool $string any string/int/float/bool
+ * @return string excaped string including quites
+ */
+ public function __dbEscapeLiteral($string): string
+ {
+ return pg_escape_string($this->dbh, (string)$string);
+ }
+
+ /**
+ * wrapper for pg_escape_byte
+ * @param string $bytea bytea data stream
+ * @return string escaped bytea string
+ */
+ public function __dbEscapeBytea($bytea): string
{
return pg_escape_bytea($this->dbh, $bytea);
}
- // METHOD: __dbConnectionBusy
- // WAS : _db_connection_busy
- // PARAMS: none
- // RETURN: true/false for busy connection
- // DESC : wrapper for pg_connection_busy
- public function __dbConnectionBusy()
+ /**
+ * wrapper for pg_connection_busy
+ * @return bool true/false for busy connection
+ */
+ public function __dbConnectionBusy(): bool
{
return pg_connection_busy($this->dbh);
}
- // METHOD: __dbVersion
- // WAS : _db_version
- // PARAMS: none
- // RETURN: databse version
- // DESC : wrapper for pg_version
- public function __dbVersion()
+ /**
+ * wrapper for pg_version
+ * Note: this only returns server version
+ * not connection version OR client version
+ * @return string version string
+ */
+ public function __dbVersion(): string
{
// array has client, protocol, server
// we just need the server
@@ -412,13 +432,14 @@ class PgSQL
return $v['server'];
}
- // METHOD: __dbArrayParse
- // WAS : _db_array_parse
- // PARAMS: input text, output array [needed]
- // [internal] limit: are we at the end of the parse
- // [internal] offset: shift for {}
- // RETURN: array with the elements
- // DESC : postgresql array to php array
+ /**
+ * postgresql array to php array
+ * @param string $text array text from PostgreSQL
+ * @param array &$output (internal) recursive pass on for nested arrays
+ * @param bool|int $limit (internal) max limit to not overshoot the end, start with false
+ * @param integer $offset (internal) shift offset for {}
+ * @return array|int converted PHP array, interal recusrive int position
+ */
public function __dbArrayParse($text, &$output, $limit = false, $offset = 1)
{
if (false === $limit) {
diff --git a/www/lib/CoreLibs/Language/Core/FileReader.php b/www/lib/CoreLibs/Language/Core/FileReader.php
index 330832cb..03fee4ff 100755
--- a/www/lib/CoreLibs/Language/Core/FileReader.php
+++ b/www/lib/CoreLibs/Language/Core/FileReader.php
@@ -29,6 +29,10 @@ class FileReader
public $fr_length;
public $error = 0;
+ /**
+ * file read constructor
+ * @param string $filename file name to load
+ */
public function __construct($filename)
{
if (file_exists($filename)) {
@@ -43,6 +47,11 @@ class FileReader
}
}
+ /**
+ * read byte data length
+ * @param int $bytes how many bytes to read
+ * @return string read data as string
+ */
public function read($bytes)
{
if ($bytes) {
@@ -64,6 +73,11 @@ class FileReader
}
}
+ /**
+ * seek to a position in the file
+ * @param int $pos position where to go to
+ * @return int file position after seek done
+ */
public function seekto($pos)
{
fseek($this->fr_fd, $pos);
@@ -71,17 +85,29 @@ class FileReader
return $this->fr_pos;
}
+ /**
+ * get current position in file
+ * @return int current position in bytes
+ */
public function currentpos()
{
return $this->fr_pos;
}
+ /**
+ * file length/size
+ * @return int file size in bytes
+ */
public function length()
{
return $this->fr_length;
}
- public function close()
+ /**
+ * close open file handler
+ * @return void has no return
+ */
+ public function close(): void
{
fclose($this->fr_fd);
}
diff --git a/www/lib/CoreLibs/Language/Core/StreamReader.php b/www/lib/CoreLibs/Language/Core/StreamReader.php
index f990d766..08bd2d4a 100755
--- a/www/lib/CoreLibs/Language/Core/StreamReader.php
+++ b/www/lib/CoreLibs/Language/Core/StreamReader.php
@@ -26,29 +26,47 @@ namespace CoreLibs\Language\Core;
// seek is essential, and it should be byte stream
class StreamReader
{
+ /**
+ * constructor, empty
+ */
public function __construct()
{
// empty
}
- // should return a string [FIXME: perhaps return array of bytes?]
+
+ /**
+ * should return a string [FIXME: perhaps return array of bytes?]
+ * @param int $bytes bytes to read
+ * @return bool dummy false
+ */
public function read($bytes)
{
return false;
}
- // should return new position
+ /**
+ * should return new position
+ * @param int $position seek to position
+ * @return bool dummy false
+ */
public function seekto($position)
{
return false;
}
- // returns current position
+ /**
+ * returns current position
+ * @return bool dummy false
+ */
public function currentpos()
{
return false;
}
- // returns length of entire stream (limit for seekto()s)
+ /**
+ * returns length of entire stream (limit for seekto()s)
+ * @return bool dummy false
+ */
public function length()
{
return false;
diff --git a/www/lib/CoreLibs/Language/Core/StringReader.php b/www/lib/CoreLibs/Language/Core/StringReader.php
index 0f527751..6329b877 100755
--- a/www/lib/CoreLibs/Language/Core/StringReader.php
+++ b/www/lib/CoreLibs/Language/Core/StringReader.php
@@ -27,12 +27,21 @@ class StringReader
public $sr_pos;
public $sr_str;
+ /**
+ * constructor for string reader
+ * @param string $str basic string
+ */
public function __construct($str = '')
{
$this->sr_str = $str;
$this->sr_pos = 0;
}
+ /**
+ * read bytes in string
+ * @param int $bytes bytes to read in string
+ * @return string data read in length of bytes as string
+ */
public function read($bytes)
{
$data = substr($this->sr_str, $this->sr_pos, $bytes);
@@ -44,6 +53,11 @@ class StringReader
return $data;
}
+ /**
+ * go to position in string
+ * @param int $pos position in string
+ * @return int new position in string after seek
+ */
public function seekto($pos)
{
$this->sr_pos = $pos;
@@ -53,11 +67,19 @@ class StringReader
return $this->sr_pos;
}
+ /**
+ * get current position in string
+ * @return int position in string
+ */
public function currentpos()
{
return $this->sr_pos;
}
+ /**
+ * get length of string
+ * @return int return length of assigned string
+ */
public function length()
{
return strlen($this->sr_str);
diff --git a/www/lib/CoreLibs/Language/L10n.php b/www/lib/CoreLibs/Language/L10n.php
index 5cf0617d..a291fd42 100644
--- a/www/lib/CoreLibs/Language/L10n.php
+++ b/www/lib/CoreLibs/Language/L10n.php
@@ -35,6 +35,12 @@ class L10n extends \CoreLibs\Basic
private $input;
private $l10n;
+ /**
+ * class constructor call for language getstring
+ * @param string $lang language name (optional), fallback is en
+ * @param string $path path, if empty fallback on default internal path
+ * @param int|integer $set_control_flag control flags for Basic class set/get checks
+ */
public function __construct(string $lang = '', string $path = '', int $set_control_flag = 0)
{
parent::__construct($set_control_flag);
@@ -60,7 +66,12 @@ class L10n extends \CoreLibs\Basic
$this->l10n = new GetTextReader($this->input);
}
- // reloads the mofile, if the location of the lang file changes
+ /**
+ * reloads the mofile, if the location of the lang file changes
+ * @param string $lang language to reload data
+ * @param string $path optional path, if not set fallback on internal
+ * @return bool successfull reload true/false
+ */
public function l10nReloadMOfile(string $lang, string $path = ''): bool
{
$success = false;
@@ -90,27 +101,52 @@ class L10n extends \CoreLibs\Basic
return $success;
}
- public function __($text)
+ /**
+ * translates a string and returns translated text
+ * @param string $text text to translate
+ * @return string translated text
+ */
+ public function __($text): string
{
return $this->l10n->translate($text);
}
- public function __e($text)
+ /**
+ * prints translated string out to the screen
+ * @param string $text text to translate
+ * @return void has no return
+ */
+ public function __e($text): void
{
echo $this->l10n->translate($text);
}
// Return the plural form.
+ /**
+ * Return the plural form.
+ * @param string $single string for single word
+ * @param string $plural string for plural word
+ * @param string $number number value
+ * @return string translated plural string
+ */
public function __ngettext($single, $plural, $number)
{
return $this->l10n->ngettext($single, $plural, $number);
}
+ /**
+ * get current set language
+ * @return string current set language string
+ */
public function __getLang()
{
return $this->lang;
}
+ /**
+ * get current set mo file
+ * @return string current set mo language file
+ */
public function __getMoFile()
{
return $this->mofile;
diff --git a/www/lib/CoreLibs/Output/Form/Generate.php b/www/lib/CoreLibs/Output/Form/Generate.php
index dc23ca1a..e6ca1231 100644
--- a/www/lib/CoreLibs/Output/Form/Generate.php
+++ b/www/lib/CoreLibs/Output/Form/Generate.php
@@ -248,11 +248,13 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
// now some default error msgs (english)
public $language_array = array ();
- // METHOD: constructor
- // PARAMS: $db_config -> connect to DB
- // $lang -> language code ('en', 'ja', etc)
- // $table_width -> width of table
- // $set_control_flag -> basic class set/get variable error flags
+ /**
+ * construct form generator
+ * @param array $db_config db config array
+ * @param string $lang interface language
+ * @param int|integer $table_width table/div width (default 750)
+ * @param int|integer $set_control_flag basic class set/get variable error flags
+ */
public function __construct(array $db_config, string $lang, int $table_width = 750, int $set_control_flag = 0)
{
$this->my_page_name = $this->getPageName(1);
@@ -335,7 +337,21 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
$this->security_level = $config_array['security_level'];
}
- // dumps all values into output (for error msg)
+ /**
+ * deconstructor
+ * writes out error msg to global var
+ * closes db connectio
+ */
+ public function __destruct()
+ {
+ // close DB connection
+ parent::__destruct();
+ }
+
+ /**
+ * dumps all values into output (for error msg)
+ * @return string full table array data output as string html formatted
+ */
public function formDumpTableArray()
{
if (!is_array($this->table_array)) {
@@ -349,45 +365,38 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
return $string;
}
- // dekonstruktor
- // writes out error msg to global var
- // closes db connection
- public function __destruct()
- {
- // close DB connection
- parent::__destruct();
- }
-
- // METHOD: formGetColNameFromKey
- // WAS : form_get_col_name_from_key
- // PARAMS: $want_key: the key where you want the data from
- // $key_value: if set searches for special right value
- // RETURN: the value of the $want_key array field
- // works only with fields that appear only ONCE
- // if multiple gets only FIRST
- public function formGetColNameFromKey($want_key, $key_value = '')
+ /**
+ * the value of the $want_key array field
+ * works only with fields that appear only ONCE
+ * if multiple gets only FIRST
+ * @param string $want_key key to search for
+ * @param string|null $key_value value to match to (optional)
+ * @return string|null returns key found or empty string
+ */
+ public function formGetColNameFromKey(string $want_key, ?string $key_value = null): ?string
{
if (!is_array($this->table_array)) {
$this->table_array = array ();
}
reset($this->table_array);
foreach ($this->table_array as $key => $value) {
- if (isset($value[$want_key]) && !isset($key_value)) {
+ if (isset($value[$want_key]) && !$key_value) {
return $key;
- } elseif (isset($value[$want_key]) && $value[$want_key] == $key_value && isset($key_value)) {
+ } elseif (isset($value[$want_key]) && $value[$want_key] == $key_value && $key_value) {
return $key;
}
}
// return nothing on nothing
- return '';
+ return null;
}
- // METHOD: formGetColNameArrayFromKey
- // WAS : form_get_col_name_array_from_key
- // PARAMS: $want_key: the key where u want the data from
- // $key_value: if set searches for special right value
- // RETURN: array of fields
- public function formGetColNameArrayFromKey($want_key, $key_value = '')
+ /**
+ * array of fields
+ * @param string $want_key the key where you want the data from
+ * @param string|null $key_value if set searches for special right value
+ * @return array found key fields
+ */
+ public function formGetColNameArrayFromKey(string $want_key, ?string $key_value = null): array
{
$key_array = array();
if (!is_array($this->table_array)) {
@@ -405,11 +414,11 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
return $key_array;
}
- // METHOD: formPrintMsg
- // WAS : form_print_msg
- // PARAMS: none
- // RETURN: formated output for the error && warning msg
- public function formPrintMsg()
+ /**
+ * formated output for the error && warning msg
+ * @return array error message with msg, width, clas
+ */
+ public function formPrintMsg(): array
{
$class = '';
if ($this->error) {
@@ -426,12 +435,12 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
}
// next for functions are pre_test fkts for easier default new,load, etc handling
- // METHOD: formProcedureLoad
- // WAS : form_procedure_load
- // PARAMS: archive_id - which ID should be loaded
- // RETURN: none
- // DESC : default load procedure
- public function formProcedureLoad($archive_id)
+ /**
+ * default load procedure
+ * @param int $archive_id archive id to load
+ * @return void has no return
+ */
+ public function formProcedureLoad(int $archive_id): void
{
if ($this->archive && $archive_id && $this->base_acl_level >= $this->security_level['load']) {
$this->formLoadTableArray($archive_id);
@@ -439,12 +448,11 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
}
}
- // METHOD: formProcedureNew
- // WAS : form_procedure_new
- // PARAMS: none
- // RETURN: none
- // DESC : default new procedure
- public function formProcedureNew()
+ /**
+ * default new procedure
+ * @return void has no return
+ */
+ public function formProcedureNew(): void
{
if ($this->new && $this->base_acl_level >= $this->security_level['new']) {
if ($this->really_new == 'yes') {
@@ -457,12 +465,11 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
}
}
- // METHOD: formProcedureSave
- // WAS : form_procedure_save
- // PARAMS: none
- // RETURN: none
- // DESC : default save procedure
- public function formProcedureSave()
+ /**
+ * default save procedure
+ * @return void has no return
+ */
+ public function formProcedureSave(): void
{
if ($this->save && $this->base_acl_level >= $this->security_level['save']) {
$this->formErrorCheck();
@@ -473,12 +480,11 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
}
}
- // METHOD: formProcedureDelete
- // WAS : form_procedure_delete
- // PARAMS: none
- // RETURN: none
- // DESC : default delete procedure
- public function formProcedureDelete()
+ /**
+ * default delete procedure
+ * @return void has no return
+ */
+ public function formProcedureDelete(): void
{
// delete is also by 'protected'
if ($this->delete && $this->base_acl_level >= $this->security_level['delete']) {
@@ -496,12 +502,13 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
}
}
- // METHOD: formProcedureDeleteFromElementList
- // WAS : form_procedure_delete_from_element_list
- // PARAMS: none
- // RETURN: none
- // DESC : default delete procedure
- public function formProcedureDeleteFromElementList($element_list, $remove_name)
+ /**
+ * default delete procedure
+ * @param array $element_list element array that should be removed
+ * @param array $remove_name key names that should be removed
+ * @return void has no return
+ */
+ public function formProcedureDeleteFromElementList(array $element_list, array $remove_name): void
{
$this->debug('REMOVE ELEMENT', 'Remove REF ELEMENT: '.$this->base_acl_level.' >= '.$this->security_level['delete']);
$this->debug('REMOVE ELEMENT', 'Protected Value set: '.(string)isset($this->table_array['protected']['value']));
@@ -579,11 +586,11 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
}
}
- // METHOD: formCreateLoad
- // WAS : form_create_load
- // PARAMS: none
- // RETURN: string from 'load' part of form ...
- public function formCreateLoad()
+ /**
+ * create the load list and return it as an array
+ * @return array load list array with primary key, name and selected entry
+ */
+ public function formCreateLoad(): array
{
$pk_selected = '';
$t_pk_name = '';
@@ -627,11 +634,12 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
);
}
- // METHOD: formCreateNew
- // WAS : form_create_new
- // PARAMS: none
- // RETURN: part for new
- public function formCreateNew($hide_new_checkbox = 0)
+ /**
+ * Create new entry element for HTML output
+ * @param bool $hide_new_checkbox show or hide the new checkbox, default is false
+ * @return array return the new create array with name & checkbox show flag
+ */
+ public function formCreateNew($hide_new_checkbox = false): array
{
$show_checkbox = 0;
$new_name = '';
@@ -653,11 +661,13 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
);
}
- // METHOD: formCreateSaveDelete
- // WAS : form_create_save_delete
- // PARAMS: none
- // RETURN: string for delete / save part
- public function formCreateSaveDelete($hide_delete = 0, $hide_delete_checkbox = 0)
+ /**
+ * create the save and delete element html group data
+ * @param bool $hide_delete hide the delete button (default false)
+ * @param bool $hide_delete_checkbox hide the delete checkbox (default false)
+ * @return array return the hide/show delete framework for html creation
+ */
+ public function formCreateSaveDelete($hide_delete = false, $hide_delete_checkbox = false): array
{
$seclevel_okay = 0;
$save = '';
@@ -699,14 +709,15 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
);
} // end of function
- // METHOD: formCreateElement
- // WAS : form_create_element
- // PARAMS: $element_name: the name from the array, you want to have build
- // $query: can overrule internal query data,
- // for drop down, as data comes from a reference table
- // for drop_down_text it has to be an array with $key->$value
- // RETURN: element in HTML
- public function formCreateElement($element_name, $query = '')
+ /**
+ * create a form element based on the settings in the element array entry
+ * @param string $element_name the name from the array, you want to have build
+ * @param string|null $query can overrule internal query data,
+ * for drop down, as data comes from a reference table
+ * for drop_down_text it has to be an array with $key->$valu
+ * @return array html settings array
+ */
+ public function formCreateElement(string $element_name, ?string $query = null): array
{
// special 2nd color for 'binary' attribut
if ($this->table_array[$element_name]['type'] == 'binary' && !isset($this->table_array[$element_name]['value'])) {
@@ -897,17 +908,23 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
$data['value'] = $this->table_array[$element_name]['value'];
}
}
- return array('output_name' => $output_name, 'color' => $EDIT_FGCOLOR_T, 'type' => $type, 'data' => $data);
+ return array(
+ 'output_name' => $output_name,
+ 'color' => $EDIT_FGCOLOR_T,
+ 'type' => $type,
+ 'data' => $data
+ );
}
- // METHOD: formErrorCheck
- // WAS : form_error_check
- // PARAMS: none
- // RETURN: full error message string for output
- // should be cought like this ...
- // if ($msg=$form->form_error_check())
- // $error=1;
- public function formErrorCheck()
+ /**
+ * full error message string for output
+ * checks each filled entry to the table array defined error checks
+ * should be cought like this ...
+ * if ($msg = $form->form_error_check())
+ * $error=1;
+ * @return void has no return
+ */
+ public function formErrorCheck(): void
{
if (!is_array($this->table_array)) {
$this->table_array = array ();
@@ -1170,12 +1187,11 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
}
}
- // METHOD: formSetOrder
- // WAS: form_set_order
- // PARAMS: none
- // RETURN: the table array
- // DESC : sets the order to the maximum, if order flag is set in array
- public function formSetOrder()
+ /**
+ * sets the order to the maximum, if order flag is set in array
+ * @return array table array with set order number
+ */
+ public function formSetOrder(): array
{
// get order name
$order_name = $this->formGetColNameFromKey('order');
@@ -1198,12 +1214,11 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
return $this->table_array;
}
- // METHOD: formUnsetTableArray
- // WAS : form_unsert_table_array
- // PARAMS: none
- // RETURN: none
- // DESC : resets all values in table_array and in the reference tables
- public function formUnsetTableArray()
+ /**
+ * resets all values in table_array and in the reference tables
+ * @return void has no return
+ */
+ public function formUnsetTableArray(): void
{
unset($this->pk_id);
if (!is_array($this->table_array)) {
@@ -1231,17 +1246,17 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
$this->msg = $this->l->__('Cleared for new Dataset!');
}
- // METHOD: formLoadTableArray
- // WAS : form_load_table_array
- // PARAMS: pk_id - overrule pk_id
- // RETURN: none
- // DESC : load a table & reference
- public function formLoadTableArray($pk_id = 0)
+ /**
+ * load a table & reference
+ * @param int|null $pk_id overrule pk_id
+ * @return void has no return
+ */
+ public function formLoadTableArray(?int $pk_id = null): void
{
if ($pk_id) {
$this->pk_id = $pk_id;
}
- $this->table_array = $this->dbRead(1);
+ $this->table_array = $this->dbRead(true);
// reset all temp fields
if (!is_array($this->table_array)) {
@@ -1270,12 +1285,14 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
$this->msg = $this->l->__('Dataset has been loaded!
');
}
- // METHOD: formSaveTableArray
- // WAS : form_save_table_array
- // PARAMS: addslashes - if one, passes 1 to the db_write function
- // RETURN: none
- // DESC : save a table, reference and all input fields
- public function formSaveTableArray($addslashes = 0)
+ /**
+ * save a table, reference and all input fields
+ * note that the addslashes flag here is passed on to the dbWrite method
+ * it only does html conversion, add slashes for DB is done automatically
+ * @param bool $addslashes override internal addslasahes flag (default false)
+ * @return void has no return
+ */
+ public function formSaveTableArray($addslashes = false)
{
// for drop_down_db_input check if text field is filled and if, if not yet in db ...
// and upload files
@@ -1670,14 +1687,15 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
return array('output_name' => $output_name, 'type' => $type, 'color' => 'edit_fgcolor', 'data' => $data);
}
- // METHOD: formCreateElementListTable
- // WAS : form_create_element_list_table
- // PARAMS: show which element list
- // RETURN: array for output
- // DESC : create list of elements next to each other for a group of data in an input field
- // this currently only works for a list that is filled from a sub table and creates only a connection to this one
- // new version will allow a sub list with free input fields to directly fill a sub table to a master table
- public function formCreateElementListTable($table_name)
+ /**
+ * create list of elements next to each other for a group of data in an input field
+ * this currently only works for a list that is filled from a sub table and creates
+ * only a connection to this one new version will allow a sub list with free input
+ * fields to directly fill a sub table to a master table
+ * @param string $table_name which element entry to create
+ * @return array element for html creation
+ */
+ public function formCreateElementListTable(string $table_name): array
{
// output name for the viewable left table td box, prefixed with * if mandatory
$output_name = $this->element_list[$table_name]['output_name'];
@@ -1737,7 +1755,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
}
// if drop down db read data for element list from the given sub table as from the query
// only two elements are allowed: pos 0 is key, pso 1 is visible output name
- if ($data_array['type'] == 'drop_down_db') {
+ if (isset($data_array['type']) && $data_array['type'] == 'drop_down_db') {
$md_q = md5($data_array['query']);
while ($res = $this->dbReturn($data_array['query'])) {
$this->debug('edit', 'Q['.$md_q.'] pos: '.$this->cursor_ext[$md_q]['pos'].' | want: '.(isset($data_array['preset']) ? $data_array['preset'] : '-').' | set: '.(isset($data['preset'][$el_name]) ? $data['preset'][$el_name] : '-'));
diff --git a/www/lib/CoreLibs/Output/Progressbar.php b/www/lib/CoreLibs/Output/Progressbar.php
index 16402657..ce149e9d 100644
--- a/www/lib/CoreLibs/Output/Progressbar.php
+++ b/www/lib/CoreLibs/Output/Progressbar.php
@@ -73,8 +73,12 @@ class ProgressBar
)
*/
- // constructor
- public function __construct($width = 0, $height = 0)
+ /**
+ * progress bar constructor
+ * @param integer $width progress bar width, default 0
+ * @param integer $height progress bar height, default 0
+ */
+ public function __construct(int $width = 0, int $height = 0)
{
$this->code = substr(md5(microtime()), 0, 6);
if ($width > 0) {
@@ -90,7 +94,12 @@ class ProgressBar
// private functions
- private function __flushCache($clear_buffer_size = 0)
+ /**
+ * flush cache hack for IE and others
+ * @param integer $clear_buffer_size buffer size override
+ * @return void has not return
+ */
+ private function __flushCache(int $clear_buffer_size = 0): void
{
if (!$clear_buffer_size) {
$clear_buffer_size = $this->clear_buffer_size;
@@ -100,7 +109,12 @@ class ProgressBar
flush();
}
- private function __calculatePercent($step)
+ /**
+ * [__calculatePercent description]
+ * @param float $step percent step to do
+ * @return float percent step done
+ */
+ private function __calculatePercent(float $step): float
{
// avoid divison through 0
if ($this->max - $this->min == 0) {
@@ -113,7 +127,12 @@ class ProgressBar
return $percent;
}
- private function __calculatePosition($step)
+ /**
+ * calculate position in bar step
+ * @param float $step percent step to do
+ * @return array bar position as array
+ */
+ private function __calculatePosition(float $step): array
{
$bar = 0;
switch ($this->direction) {
@@ -168,7 +187,12 @@ class ProgressBar
return $position;
}
- private function __setStep($step)
+ /**
+ * set the step
+ * @param float $step percent step to do
+ * @return void has no return
+ */
+ private function __setStep(float $step): void
{
if ($step > $this->max) {
$step = $this->max;
@@ -180,7 +204,13 @@ class ProgressBar
}
// public functions
- public function setFrame($width = 0, $height = 0)
+ /**
+ * set frame layout
+ * @param integer $width bar width
+ * @param integer $height bar height
+ * @return void has no return
+ */
+ public function setFrame(int $width = 0, int $height = 0): void
{
$this->frame = array (
'show' => true,
@@ -201,7 +231,15 @@ class ProgressBar
}
}
- public function addLabel($type, $name, $value = ' ')
+ /**
+ * set bar label text
+ * allowed types are: text, button, step, percent, percentlbl, crossbar
+ * @param string $type label type
+ * @param string $name label name (internal)
+ * @param string $value label output name (optional)
+ * @return void has no return
+ */
+ public function addLabel(string $type, string $name, string $value = ' '): void
{
switch ($type) {
case 'text':
@@ -276,7 +314,6 @@ class ProgressBar
'color' => '#000000',
'bgr_color' => ''
);
-// print "THIS[$name]: ".$this->label[$name]['left']." | ".$this->label[$name]['width']."
";
break;
case 'crossbar':
$this->label[$name] = array(
@@ -297,14 +334,32 @@ class ProgressBar
}
}
- public function addButton($name, $value, $action, $target = 'self')
+ /**
+ * add a button to the progress bar
+ * @param string $name button name (internal)
+ * @param string $value button text (output)
+ * @param string $action button action (link)
+ * @param string $target button action target (default self)
+ * @return void has no return
+ */
+ public function addButton(string $name, string $value, string $action, string $target = 'self'): void
{
$this->addLabel('button', $name, $value);
$this->label[$name]['action'] = $action;
$this->label[$name]['target'] = $target;
}
- public function setLabelPosition($name, $left, $top, $width, $height, $align = '')
+ /**
+ * set the label position
+ * @param string $name label name to set
+ * @param int $left left px
+ * @param int $top top px
+ * @param int $width width px
+ * @param int $height height px
+ * @param string $align alignment (left/right/etc), default empty
+ * @return void has no return
+ */
+ public function setLabelPosition(string $name, int $left, int $top, int $width, int $height, string $align = ''): void
{
// print "SET POSITION[$name]: $left
";
// if this is percent, we ignore anything, it is auto positioned
@@ -333,7 +388,13 @@ class ProgressBar
}
}
- public function setLabelColor($name, $color)
+ /**
+ * set label color
+ * @param string $name label name to set
+ * @param string $color color value in rgb html hex
+ * @return void has no return
+ */
+ public function setLabelColor(string $name, string $color): void
{
$this->label[$name]['color'] = $color;
if ($this->status != 'new') {
@@ -342,7 +403,13 @@ class ProgressBar
}
}
- public function setLabelBackground($name, $color)
+ /**
+ * set the label background color
+ * @param string $name label name to set
+ * @param string $color background color to set in rgb html hex
+ * @return void has no return
+ */
+ public function setLabelBackground(string $name, string $color): void
{
$this->label[$name]['bgr_color'] = $color;
if ($this->status != 'new') {
@@ -351,7 +418,15 @@ class ProgressBar
}
}
- public function setLabelFont($name, $size, $family = '', $weight = '')
+ /**
+ * [setLabelFont description]
+ * @param string $name label name to set
+ * @param int $size font size in px
+ * @param string $family font family (default empty)
+ * @param string $weight font weight (default empty)
+ * @return void has no return
+ */
+ public function setLabelFont(string $name, int $size, string $family = '', string $weight = ''): void
{
// just in case if it is too small
if (intval($size) < 0) {
@@ -386,7 +461,13 @@ class ProgressBar
}
}
- public function setLabelValue($name, $value)
+ /**
+ * set the label valeu
+ * @param string $name label name to set
+ * @param string $value label value (output)
+ * @return void has no return
+ */
+ public function setLabelValue(string $name, string $value): void
{
$this->label[$name]['value'] = $value;
// print "NAME[$name], Status: ".$this->status.": ".$value."
";
@@ -396,7 +477,12 @@ class ProgressBar
}
}
- public function setBarColor($color)
+ /**
+ * set the bar color
+ * @param string $color color for the progress bar in rgb html hex
+ * @return void has no return
+ */
+ public function setBarColor(string $color): void
{
$this->color = $color;
if ($this->status != 'new') {
@@ -405,7 +491,12 @@ class ProgressBar
}
}
- public function setBarBackground($color)
+ /**
+ * set the progress bar background color
+ * @param string $color background color in rgb html hex
+ * @return void has no return
+ */
+ public function setBarBackground(string $color): void
{
$this->bgr_color = $color;
if ($this->status != 'new') {
@@ -414,7 +505,12 @@ class ProgressBar
}
}
- public function setBarDirection($direction)
+ /**
+ * progress bar direct (left/right)
+ * @param string $direction set direction as left/right
+ * @return void has no return
+ */
+ public function setBarDirection(string $direction): void
{
$this->direction = $direction;
@@ -431,7 +527,11 @@ class ProgressBar
}
}
- public function getHtml()
+ /**
+ * get the progress bar base HTML
+ * @return string progress bar HTML code
+ */
+ public function getHtml(): string
{
$html = '';
$js = '';
@@ -582,14 +682,24 @@ class ProgressBar
return $html;
}
- public function show()
+ /**
+ * show the progress bar after initialize
+ * @return void has no return
+ */
+ public function show(): void
{
$this->status = 'show';
echo $this->getHtml();
$this->__flushCache();
}
- public function moveStep($step)
+ /**
+ * move the progress bar by one step
+ * prints out javascript to move progress bar
+ * @param float $step percent step
+ * @return void has no return
+ */
+ public function moveStep(float $step): void
{
$last_step = $this->step;
$this->__setStep($step);
@@ -636,17 +746,29 @@ class ProgressBar
}
}
- public function moveNext()
+ /**
+ * moves progress bar by one step (1)
+ * @return void has no return
+ */
+ public function moveNext(): void
{
$this->moveStep($this->step + 1);
}
- public function moveMin()
+ /**
+ * moves the progress bar back to the beginning
+ * @return void has no return
+ */
+ public function moveMin(): void
{
$this->moveStep($this->min);
}
- public function hide()
+ /**
+ * hide the progress bar if it is visible
+ * @return void has no return
+ */
+ public function hide(): void
{
if ($this->status == 'show') {
$this->status = 'hide';
@@ -659,7 +781,11 @@ class ProgressBar
}
}
- public function unhide()
+ /**
+ * show progress bar again after it was hidden with hide()
+ * @return void has no return
+ */
+ public function unhide(): void
{
if ($this->status == 'hide') {
$this->status = 'show';
diff --git a/www/lib/CoreLibs/Template/SmartyExtend.php b/www/lib/CoreLibs/Template/SmartyExtend.php
index 91d264b8..2879a4c2 100644
--- a/www/lib/CoreLibs/Template/SmartyExtend.php
+++ b/www/lib/CoreLibs/Template/SmartyExtend.php
@@ -1,4 +1,9 @@