Code clean up for Basic Class clean up

Fix all other class code for calling former Basic class methods.
Also try to replace all remaining array() calls to [] type

Some docblock updates when missing or wrong set
This commit is contained in:
Clemens Schwaighofer
2021-06-14 15:00:02 +09:00
parent cb17b553b0
commit 3035287b5c
26 changed files with 228 additions and 199 deletions

View File

@@ -27,6 +27,7 @@ $LOG_FILE_ID = 'classTest-array';
ob_end_flush();
use CoreLibs\Combined\ArrayHandler;
use CoreLibs\Debug\Support as DgS;
$basic = new CoreLibs\Basic();
// $_array= new CoreLibs\Combined\ArrayHandler();
@@ -37,24 +38,30 @@ print "<body>";
print '<div><a href="class_test.php">Class Test Master</a></div>';
// recursive array search
$test_array = array(
$test_array = [
'foo' => 'bar',
'input' => array(
'element_a' => array(
'input' => [
'element_a' => [
'type' => 'text'
),
'element_b' => array(
],
'element_b' => [
'type' => 'email'
),
'element_c' => array(
],
'element_c' => [
'type' => 'email'
)
)
);
],
],
];
echo "SOURCE ARRAY: ".$basic->printAr($test_array)."<br>";
echo "FOUND ELEMENTS [base]: ".$basic->printAr(ArrayHandler::arraySearchRecursive('email', $test_array, 'type'))."<br>";
echo "FOUND ELEMENTS [input]: ".$basic->printAr(ArrayHandler::arraySearchRecursive('email', $test_array['input'], 'type'))."<br>";
echo "SOURCE ARRAY: ".DgS::printAr($test_array)."<br>";
// frist return
echo "ARRAYSEARCHRECURSIVE(email, [array], type): ".DgS::printAr(ArrayHandler::arraySearchRecursive('email', $test_array, 'type'))."<br>";
echo "ARRAYSEARCHRECURSIVE(email, [array]['input'], type): ".DgS::printAr(ArrayHandler::arraySearchRecursive('email', $test_array['input'], 'type'))."<br>";
// all return
echo "ARRAYSEARCHRECURSIVEALL(email, [array], type): ".Dgs::printAr((array)ArrayHandler::arraySearchRecursiveAll('email', $test_array, 'type'))."<br>";
// simple search
echo "ARRAYSEARCHSIMPLE([array], type, email): ".(string)ArrayHandler::arraySearchSimple($test_array, 'type', 'email')."<br>";
$array_1 = [
'foo' => 'bar'
@@ -67,10 +74,28 @@ $array_3 = [
'beta' => 4
]
];
print "ARRAYMERGERECURSIVE: ".$basic->printAr(ArrayHandler::arrayMergeRecursive($array_1, $array_2, $array_3))."<br>";
// recusrice merge
print "ARRAYMERGERECURSIVE: ".DgS::printAr(ArrayHandler::arrayMergeRecursive($array_1, $array_2, $array_3))."<br>";
// array difference
$array_left = [
'same' => 'data',
'left' => 'Has L'
];
$array_right = [
'same' => 'data',
'right' => 'has R'
];
print "ARRAYDIFF: ".DgS::printAr(ArrayHandler::arrayDiff($array_left, $array_right))."<br>";
// in array check
print "INARRAYANY([1,3], [array]): ".DgS::printAr(ArrayHandler::inArrayAny([1, 3], $array_2))."<br>";
// flatten array
print "FLATTENARRAY: ".DgS::printAr(ArrayHandler::flattenArray($test_array))."<br>";
print "FLATTENARRAYKEY: ".DgS::printAr(ArrayHandler::flattenArrayKey($test_array))."<br>";
// flatten for key set
print "ARRAYFLATFORKEY: ".DgS::printAr(ArrayHandler::arrayFlatForKey($test_array, 'type'))."<br>";
// DEPRECATED
// print "ARRAYMERGERECURSIVE: ".$basic->printAr($basic->arrayMergeRecursive($array_1, $array_2, $array_3))."<br>";
// print "ARRAYMERGERECURSIVE: ".DgS::printAr($basic->arrayMergeRecursive($array_1, $array_2, $array_3))."<br>";
// error message
print $basic->log->printErrorMsg();

View File

@@ -27,6 +27,7 @@ $LOG_FILE_ID = 'classTest-colors';
ob_end_flush();
use CoreLibs\Convert\Colors;
use CoreLibs\Debug\Support as DgS;
$basic = new CoreLibs\Basic();
$color_class = 'CoreLibs\Convert\Colors';
@@ -46,14 +47,14 @@ $hex = '#0a141e';
$hsb = [210, 67, 12];
$hsl = [210, 50, 7.8];
print "S::COLOR rgb->hex: $rgb[0], $rgb[1], $rgb[2]: ".Colors::rgb2hex($rgb[0], $rgb[1], $rgb[2])."<br>";
print "S::COLOR hex->rgb: $hex: ".$basic->printAr(Colors::hex2rgb($hex))."<br>";
print "C::S/COLOR rgb->hext: $hex: ".$basic->printAr(CoreLibs\Convert\Colors::hex2rgb($hex))."<br>";
print "S::COLOR hex->rgb: $hex: ".DgS::printAr(Colors::hex2rgb($hex))."<br>";
print "C::S/COLOR rgb->hext: $hex: ".DgS::printAr(CoreLibs\Convert\Colors::hex2rgb($hex))."<br>";
// C(to hsb/hsl)
print "S::COLOR rgb->hsb: $rgb[0], $rgb[1], $rgb[2]: ".$basic->printAr(Colors::rgb2hsb($rgb[0], $rgb[1], $rgb[2]))."<br>";
print "S::COLOR rgb->hsl: $rgb[0], $rgb[1], $rgb[2]: ".$basic->printAr(Colors::rgb2hsl($rgb[0], $rgb[1], $rgb[2]))."<br>";
print "S::COLOR rgb->hsb: $rgb[0], $rgb[1], $rgb[2]: ".DgS::printAr(Colors::rgb2hsb($rgb[0], $rgb[1], $rgb[2]))."<br>";
print "S::COLOR rgb->hsl: $rgb[0], $rgb[1], $rgb[2]: ".DgS::printAr(Colors::rgb2hsl($rgb[0], $rgb[1], $rgb[2]))."<br>";
// D(from hsb/hsl) Note that param 2 + 3 is always 0-100 divided
print "S::COLOR hsb->rgb: $hsb[0], $hsb[1], $hsb[2]: ".$basic->printAr(Colors::hsb2rgb($hsb[0], $hsb[1], $hsb[2]))."<br>";
print "S::COLOR hsl->rgb: $hsl[0], $hsl[1], $hsl[2]: ".$basic->printAr(Colors::hsl2rgb($hsl[0], $hsl[1], $hsl[2]))."<br>";
print "S::COLOR hsb->rgb: $hsb[0], $hsb[1], $hsb[2]: ".DgS::printAr(Colors::hsb2rgb($hsb[0], $hsb[1], $hsb[2]))."<br>";
print "S::COLOR hsl->rgb: $hsl[0], $hsl[1], $hsl[2]: ".DgS::printAr(Colors::hsl2rgb($hsl[0], $hsl[1], $hsl[2]))."<br>";
// TODO: run compare check input must match output

View File

@@ -27,6 +27,7 @@ $LOG_FILE_ID = 'classTest-datetime';
ob_end_flush();
use CoreLibs\Combined\DateTime;
use CoreLibs\Debug\Support as DgS;
$basic = new CoreLibs\Basic();
$datetime_class = 'CoreLibs\Combination\DateTime';
@@ -118,8 +119,8 @@ $compare_dates = [
[ '2021-05-02', '2021-05-02', ],
];
foreach ($compare_dates as $compare_date) {
print "CALCDAYSINTERVAL: $compare_date[0] = $compare_date[1]: ".$basic->printAr(DateTime::calcDaysInterval($compare_date[0], $compare_date[1]))."<br>";
print "CALCDAYSINTERVAL(named): $compare_date[0] = $compare_date[1]: ".$basic->printAr(DateTime::calcDaysInterval($compare_date[0], $compare_date[1], true))."<br>";
print "CALCDAYSINTERVAL: $compare_date[0] = $compare_date[1]: ".DgS::printAr(DateTime::calcDaysInterval($compare_date[0], $compare_date[1]))."<br>";
print "CALCDAYSINTERVAL(named): $compare_date[0] = $compare_date[1]: ".DgS::printAr(DateTime::calcDaysInterval($compare_date[0], $compare_date[1], true))."<br>";
}
// DEPRECATED
@@ -138,7 +139,7 @@ print "COMPAREDATE: $compare_date[0] = $compare_date[1]: ".(string)$basic->compa
$compare_datetime = ['2021-05-01 10:00:00', '2021-05-01 11:00:00'];
print "COMPAREDATE: $compare_datetime[0] = $compare_datetime[1]: ".(string)$basic->compareDateTime($compare_datetime[0], $compare_datetime[1])."<br>";
$compare_date = ['2021-05-01', '2021-05-10'];
print "CALCDAYSINTERVAL(named): $compare_date[0] = $compare_date[1]: ".$basic->printAr($basic->calcDaysInterval($compare_date[0], $compare_date[1], true))."<br>"; */
print "CALCDAYSINTERVAL(named): $compare_date[0] = $compare_date[1]: ".DgS::printAr($basic->calcDaysInterval($compare_date[0], $compare_date[1], true))."<br>"; */
// error message
print $basic->log->printErrorMsg();

View File

@@ -26,6 +26,8 @@ if (!defined('SET_SESSION_NAME')) {
$LOG_FILE_ID = 'classTest-db';
ob_end_flush();
use CoreLibs\Debug\Support as DgS;
$basic = new CoreLibs\Admin\Backend(DB_CONFIG);
print "<html><head><title>TEST CLASS: DB</title><head>";
@@ -105,7 +107,7 @@ if ($basic->dbPrepare('sel_foo', "SELECT foo_id, test, some_bool, string_a, numb
# db write class test
$table = 'foo';
print "TABLE META DATA: ".$basic->printAr($basic->dbShowTableMetaData($table))."<br>";
print "TABLE META DATA: ".DgS::printAr($basic->dbShowTableMetaData($table))."<br>";
$primary_key = ''; # unset
$db_write_table = array('test', 'string_a', 'number_a', 'some_bool');
// $db_write_table = array('test');
@@ -186,7 +188,7 @@ $q = "SHOW search_path";
$cursor = $basic->dbExec($q);
$data = $basic->dbFetchArray($cursor)['search_path'];
print "RETURN DATA FOR search_path: ".$data."<br>";
// print "RETURN DATA FOR search_path: ".$basic->printAr($data)."<br>";
// print "RETURN DATA FOR search_path: ".DgS::printAr($data)."<br>";
// insert something into test.schema_test and see if we get the PK back
$status = $basic->dbExec("INSERT INTO test.schema_test (contents, id) VALUES ('TIME: ".time()."', ".rand(1, 10).")");
print "OTHER SCHEMA INSERT STATUS: ".$status." | PK NAME: ".$basic->pk_name.", PRIMARY KEY: ".$basic->insert_id."<br>";
@@ -195,7 +197,7 @@ print "<b>NULL TEST DB READ</b><br>";
$q = "SELECT uid, null_varchar, null_int FROM test_null_data WHERE uid = 'A'";
$res = $basic->dbReturnRow($q);
var_dump($res);
print "RES: ".$basic->printAr($res)."<br>";
print "RES: ".DgS::printAr($res)."<br>";
print "ISSET: ".isset($res['null_varchar'])."<br>";
print "EMPTY: ".empty($res['null_varchar'])."<br>";

View File

@@ -30,7 +30,6 @@ ob_end_flush();
$ECHO_ALL = true;
use CoreLibs\Debug\Support as DebugSupport;
use CoreLibs\Debug\Logging;
use CoreLibs\Debug\FileWriter;
$basic = new CoreLibs\Basic();

View File

@@ -27,6 +27,7 @@ $LOG_FILE_ID = 'classTest-email';
ob_end_flush();
use CoreLibs\Check\Email;
use CoreLibs\Debug\Support as DgS;
$basic = new CoreLibs\Basic();
@@ -39,7 +40,7 @@ print "S::GETEMAILREGEX(0): ".Email::getEmailRegex(0)."<br>";
print "S::GETEMAILREGEX(2): ".Email::getEmailRegex(2)."<br>";
print "S::GETEMAILREGEX(7): ".Email::getEmailRegex(7)."<br>";
print "S::GETEMAILREGEX(8 invalid): ".Email::getEmailRegex(8)."<br>";
print "S::GETEMAILREGEXCHECK: ".$basic->printAr(Email::getEmailRegexCheck())."<br>";
print "S::GETEMAILREGEXCHECK: ".DgS::printAr(Email::getEmailRegexCheck())."<br>";
$email = [
'foo@bar.org',

View File

@@ -27,6 +27,7 @@ $LOG_FILE_ID = 'classTest-json';
ob_end_flush();
use CoreLibs\Check\Jason;
use CoreLibs\Debug\Support as DgS;
$basic = new CoreLibs\Basic();
$json_class = 'CoreLibs\Check\Jason';
@@ -39,29 +40,29 @@ print '<div><a href="class_test.php">Class Test Master</a></div>';
$json = '{"foo": "bar"}';
$output = Jason::jsonConvertToArray($json);
print "S::JSON: $json: ".$basic->printAr($output)."<br>";
print "S::JSON: $json: ".DgS::printAr($output)."<br>";
print "S::JSON ERROR: ".Jason::jsonGetLastError().": ".Jason::jsonGetLastError(true)."<br>";
$json = '["f: {b"""ar}]';
$output = Jason::jsonConvertToArray($json);
print "S::E-JSON: $json: ".$basic->printAr($output)."<br>";
print "S::E-JSON: $json: ".DgS::printAr($output)."<br>";
print "S::E-JSON ERROR: ".Jason::jsonGetLastError().": ".Jason::jsonGetLastError(true)."<br>";
// direct
$json = '{"direct": "static function call"}';
$output = $json_class::jsonConvertToArray($json);
print "J/S::JSON: $json: ".$basic->printAr($output)."<br>";
print "J/S::JSON: $json: ".DgS::printAr($output)."<br>";
print "J/S::JSON ERROR: ".$json_class::jsonGetLastError().": ".$json_class::jsonGetLastError(true)."<br>";
$json = '["f: {b"""ar}]';
$output = $json_class::jsonConvertToArray($json);
print "J/S::E-JSON: $json: ".$basic->printAr($output)."<br>";
print "J/S::E-JSON: $json: ".DgS::printAr($output)."<br>";
print "J/S::E-JSON ERROR: ".$json_class::jsonGetLastError().": ".$json_class::jsonGetLastError(true)."<br>";
// DEPRECATE TEST
/* $json = '["f: {b"""ar}]';
$output = $basic->jsonConvertToArray($json);
print "E-JSON: $json: ".$basic->printAr($output)."<br>";
print "E-JSON: $json: ".DgS::printAr($output)."<br>";
print "E-JSON ERROR: ".$basic->jsonGetLastError().": ".$basic->jsonGetLastError(true)."<br>"; */
// error message

View File

@@ -45,6 +45,12 @@ print "App for mime $mime: ".$_mime->mimeGetAppName($mime)."<br>";
$_mime->mimeSetAppName($mime, 'Microsoft (better) Excel');
print "App for mime changed $mime: ".$_mime->mimeGetAppName($mime)."<br>";
// static call test
$mime = 'application/x-indesign';
print "S::App for mime $mime: ".\CoreLibs\Convert\MimeAppName::mimeGetAppName($mime)."<br>";
$mime = 'application/vnd.ms-excel';
print "S::App for mime $mime: ".\CoreLibs\Convert\MimeAppName::mimeGetAppName($mime)."<br>";
// DEPRECATED
/* $mime = 'application/illustrator';
print "MIME $mime: ".$basic->mimeGetAppName($mime)."<br>";

View File

@@ -49,6 +49,8 @@ $enc_password = $password_class::passwordSet($password);
print "PASSWORD: $password: ".$enc_password."<br>";
print "S-PASSWORD VERIFY: ".(string)$password_class::passwordVerify($password, $enc_password)."<br>";
print "PASSWORD REHASH: ".(string)$password_class::passwordRehashCheck($enc_password)."<br>";
// direct static
print "S::PASSWORD VERFIY: ".(string)PwdChk::passwordVerify($password, $enc_password)."<br>";
// DEPRECATED
/* $password = 'deprecated4567';
@@ -58,7 +60,7 @@ print "PASSWORD VERIFY: ".(string)$basic->passwordVerify($password, $enc_passwor
print "PASSWORD REHASH: ".(string)$basic->passwordRehashCheck($enc_password)."<br>"; */
// error message
print $basic->printErrorMsg();
print $basic->log->printErrorMsg();
print "</body></html>";

View File

@@ -27,6 +27,7 @@ $LOG_FILE_ID = 'classTest-system';
ob_end_flush();
use CoreLibs\Get\System;
use CoreLibs\Debug\Support as DgS;
$basic = new CoreLibs\Basic();
@@ -34,7 +35,7 @@ print "<html><head><title>TEST CLASS: SYSTEM</title><head>";
print "<body>";
print '<div><a href="class_test.php">Class Test Master</a></div>';
print "GETHOSTNAME: ".$basic->printAr(System::getHostName())."<br>";
print "GETHOSTNAME: ".DgS::printAr(System::getHostName())."<br>";
print "GETPAGENAME(0): ".System::getPageName()."<br>";
print "GETPAGENAME(1): ".System::getPageName(1)."<br>";
print "GETPAGENAME(2): ".System::getPageName(2)."<br>";

View File

@@ -17,3 +17,5 @@ require(BASE.LIB."Error.Handling.php");
if ($var) {
echo "OUT<br>";
}
// this wll throw an error and also write
// asdfa(09);

View File

@@ -20,23 +20,22 @@ if ($base->getConnectionStatus()) {
die("Cannot connect to database");
}
print "Start time: ".$base->runningTime()."<br>";
print "HumanReadableByteFormat: ".$base->HumanReadableByteFormat(1234567.12)."<br>";
print "humanReadableByteFormat: ".$base->humanReadableByteFormat(1234567.12)."<br>";
// print "get_page_name [DEPRECATED]: ".$base->get_page_name()."<br>";
print "getPageName: ".$base->getPageName()."<br>";
print "Start time: ".\CoreLibs\Debug\RunningTime::runningTime()."<br>";
print "HumanReadableByteFormat: ".\CoreLibs\Convert\Byte::HumanReadableByteFormat(1234567.12)."<br>";
print "humanReadableByteFormat: ".\CoreLibs\Convert\Byte::humanReadableByteFormat(1234567.12)."<br>";
print "getPageName: ". \CoreLibs\Get\System::getPageName()."<br>";
print "DB Info: ".$base->dbInfo(true)."<br>";
print "End Time: ".$base->runningTime()."<br>";
print "Start Time: ".$base->runningTime()."<br>";
print "End Time: ".\CoreLibs\Debug\RunningTime::runningTime()."<br>";
print "Start Time: ".\CoreLibs\Debug\RunningTime::runningTime()."<br>";
print "Lang: ".$base->l->__getLang().", MO File: ".$base->l->__getMoFile()."<br>";
print "Translate test: Year -> ".$base->l->__('Year')."<br>";
print "End Time: ".$base->runningTime()."<br>";
print "End Time: ".\CoreLibs\Debug\RunningTime::runningTime()."<br>";
// end error print
print $base->printErrorMsg();
print $base->log->printErrorMsg();
# __END__

View File

@@ -27,8 +27,8 @@ line breaks
in there. Theis
is sucky';
print "LB remove: ".$base->removeLB($text)."<br>";
print "LB remove: ".$base->removeLB($text, '##BR##')."<br>";
print "LB remove: ".\CoreLibs\Convert\Html::removeLB($text)."<br>";
print "LB remove: ".\CoreLibs\Convert\Html::removeLB($text, '##BR##')."<br>";
// $test = array (
// 'A' => array (
@@ -47,7 +47,7 @@ print "LB remove: ".$base->removeLB($text, '##BR##')."<br>";
// )
// );
// $base->debug('ARRAY', $base->printAr($test));
// $base->log->debug('ARRAY', \CoreLibs\Debug\Support::printAr($test));
function rec($pre, $cur, $node = array ())
{
@@ -103,9 +103,9 @@ $test = rec('C', 'U', $test);
$test = rec('F', 'U', $test);
$test = rec('', 'Al', $test);
$test = rec('B', 'B1', $test);
$base->debug('REC', $base->printAr($test));
print "FLATTEN: ".$base->printAr(flattenArrayKey($test))."<br>";
$base->log->debug('REC', \CoreLibs\Debug\Support::printAr($test));
print "FLATTEN: ".\CoreLibs\Debug\Support::printAr(flattenArrayKey($test))."<br>";
print $base->printErrorMsg();
print $base->log->printErrorMsg();
// __END__

View File

@@ -80,12 +80,10 @@ if (!$login->login) {
// automatic hide for DEBUG messages on live server
// can be overridden when setting DEBUG_ALL_OVERRIDE on top of the script (for emergency debugging of one page only)
if ((TARGET == 'live' || TARGET == 'remote') && !$DEBUG_ALL_OVERRIDE) {
$login->debug_output_all = false;
$login->echo_output_all = false;
$login->print_output_all = false;
$cms->debug_output_all = false;
$cms->echo_output_all = false;
$cms->print_output_all = false;
foreach (['debug', 'echo', 'print'] as $target) {
$login->log->setLogLevelAll($type, false);
$cms->log->setLogLevelAll($type, false);
}
}
$smarty->DATA['JS_DEBUG'] = DEBUG;

View File

@@ -121,7 +121,7 @@ class Login extends \CoreLibs\DB\IO
public function __construct(array $db_config)
{
// log login data for this class only
$this->log_per_class = 1;
$this->log->setLogPer('class', true);
// create db connection and init base class
parent::__construct($db_config);
@@ -629,24 +629,6 @@ class Login extends \CoreLibs\DB\IO
}
}
// METHOD: loginSetAcl
// WAS : login_set_acl
// PARAMS: none
// RETURN: none
// DESC : sets all the basic ACLs
// init set the basic acl the user has, based on the following rules
// * init set from config DEFAULT ACL
// * if page ACL is set, it overrides the default ACL
// * if group ACL is set, it overrides the page ACL
// * if user ACL is set, it overrides the group ACL
// set the page ACL
// * default ACL set
// * set group ACL if not default overrides default ACL
// * set page ACL if not default overrides group ACL
// set edit access ACL and set default edit access group
// * if an account ACL is set, set this parallel, account ACL overrides user ACL if it applies
// * if edit access ACL level is set, use this, else use page
// set all base ACL levels as a list keyword -> ACL number
/**
* sets all the basic ACLs
* init set the basic acl the user has, based on the following rules

View File

@@ -65,8 +65,6 @@ class Basic
private $session_name = '';
private $session_id = '';
// form token (used for form validation)
// private $form_token = '';
// ajax flag
protected $ajax_page_flag = false;
@@ -75,11 +73,6 @@ class Basic
*/
public function __construct()
{
// set per run UID for logging
$this->running_uid = \CoreLibs\Create\Uids::uniqId();
// running time start for script
$this->script_starttime = microtime(true);
// TODO make check dynamic for entries we MUST have depending on load type
// before we start any work, we should check that all MUST constants are defined
$abort = false;
@@ -150,17 +143,13 @@ class Basic
}
}
// METHOD: __destruct
// PARAMS: none
// RETURN: if debug is on, return error data
// DESC : basic deconstructor (should be called from all deconstructors in higher classes)
// writes out $error_msg to global var
/**
* deconstructor
* basic deconstructor (should be called from all deconstructors in higher classes)
* writes out $error_msg to global var
*/
public function __destruct()
{
// this has to be changed, not returned here, this is the last class to close
// return $this->error_msg;
// close open file handles
// $this->fdebugFP('c');
}
// *************************************************************
@@ -243,7 +232,7 @@ class Basic
* writes a string to a file immediatly, for fast debug output
* @param string $string string to write to the file
* @param boolean $enter default true, if set adds a linebreak \n at the end
* @return void has no return
* @return bool True of False for success of writing
* @deprecated Use \CoreLibs\Debug\FileWriter::fdebug() instead
*/
public function fdebug(string $string, bool $enter = true): bool
@@ -267,6 +256,7 @@ class Basic
public function debugFor(string $type, string $flag): void
{
trigger_error('Method '.__METHOD__.' is deprecated, use $basic->log->debugFor() or use \CoreLibs\Debug\Logging() class', E_USER_DEPRECATED);
/** @phan-suppress-next-line PhanTypeMismatchArgumentReal */
$this->log->debugFor(...[func_get_args()]);
}
@@ -456,8 +446,8 @@ class Basic
* prints a html formatted (pre) array
* @param array $array any array
* @return string formatted array for output with <pre> tag added
* DEPRCATE LATER
* @_deprecated Use \CoreLibs\Debug\Support::printAr() instead
* DEPRCATE HARD LATER
* @deprecated Use \CoreLibs\Debug\Support::printAr() instead
*/
public static function printAr(array $array): string
{
@@ -1336,10 +1326,10 @@ class Basic
* 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
* @param int $red red 0-255
* @param int $green green 0-255
* @param int $blue blue 0-255
* @return array Hue, Sat, Brightness/Value
* @deprecated use \CoreLibs\Convert\Colors::rgb2hsb() instead
*/
public static function rgb2hsb(int $red, int $green, int $blue): array
@@ -1571,7 +1561,7 @@ class Basic
public function mimeSetAppName(string $mime, string $app): void
{
trigger_error('Method '.__METHOD__.' is deprecated, use \CoreLibs\Convert\MimeAppName()->mimeSetAppName()', E_USER_DEPRECATED);
$this->mime->mimeSetAppName($mime, $app);
\CoreLibs\Convert\MimeAppName::mimeSetAppName($mime, $app);
}
/**
@@ -1584,7 +1574,7 @@ class Basic
public function mimeGetAppName(string $mime): string
{
trigger_error('Method '.__METHOD__.' is deprecated, use \CoreLibs\Convert\MimeAppName()->mimeGetAppName()', E_USER_DEPRECATED);
return $this->mime->mimeGetAppName($mime);
return \CoreLibs\Convert\MimeAppName::mimeGetAppName($mime);
}
// *** MIME PARTS END ***

View File

@@ -19,9 +19,9 @@ class ArrayHandler
*/
public static function arraySearchRecursive($needle, array $haystack, ?string $key_lookin = null): array
{
$path = array();
$path = [];
if (!is_array($haystack)) {
$haystack = array();
$haystack = [];
}
if ($key_lookin != null &&
!empty($key_lookin) &&
@@ -72,21 +72,21 @@ class ArrayHandler
{
// init if not set on null
if ($path === null) {
$path = array(
$path = [
'level' => 0,
'work' => array()
);
'work' => []
];
}
// init sub sets if not set
if (!isset($path['level'])) {
$path['level'] = 0;
}
if (!isset($path['work'])) {
$path['work'] = array();
$path['work'] = [];
}
// should not be needed because it would trigger a php mehtod error
if (!is_array($haystack)) {
$haystack = array();
$haystack = [];
}
// @phan HACK
@@ -112,7 +112,7 @@ class ArrayHandler
}
// @phan HACK
$path['level'] = $path['level'] ?? 0;
$path['work'] = $path['work'] ?? array();
$path['work'] = $path['work'] ?? [];
// cut all that is >= level
array_splice($path['work'], $path['level']);
// step back a level
@@ -130,7 +130,7 @@ class ArrayHandler
public static function arraySearchSimple(array $array, $key, $value): bool
{
if (!is_array($array)) {
$array = array();
$array = [];
}
foreach ($array as $_key => $_value) {
// if value is an array, we search
@@ -177,7 +177,7 @@ class ArrayHandler
trigger_error(__FUNCTION__.' needs two or more array arguments', E_USER_WARNING);
return false;
}
$merged = array();
$merged = [];
while ($arrays) {
$array = array_shift($arrays);
if (!is_array($array)) {
@@ -234,7 +234,7 @@ class ArrayHandler
if (!is_array($haystack)) {
return false;
}
$found = array();
$found = [];
foreach ($needle as $element) {
if (in_array($element, $haystack)) {
$found[] = $element;
@@ -257,7 +257,7 @@ class ArrayHandler
*/
public static function genAssocArray(array $db_array, $key, $value, bool $set_only = false): array
{
$ret_array = array();
$ret_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
@@ -283,7 +283,7 @@ class ArrayHandler
*/
public static function flattenArray(array $array): array
{
$return = array();
$return = [];
array_walk_recursive(
$array,
function ($value) use (&$return) {
@@ -298,13 +298,13 @@ class ArrayHandler
* @param array $array multidemnsional array to flatten
* @return array flattened keys array
*/
public static function flattenArrayKey(array $array/*, array $return = array()*/): array
public static function flattenArrayKey(array $array): array
{
$return = array();
$return = [];
array_walk_recursive(
$array,
function ($value, $key) use (&$return) {
$return [] = $key;
$return[] = $key;
}
);
return $return;
@@ -320,7 +320,7 @@ class ArrayHandler
public static function arrayFlatForKey(array $array, $search): array
{
if (!is_array($array)) {
$array = array();
$array = [];
}
foreach ($array as $key => $value) {
// if it is not an array do just nothing

View File

@@ -42,7 +42,7 @@ class DateTime
if ((int)$timestamp < 0) {
$negative = true;
}
$timestamp = abs($timestamp);
$timestamp = abs((float)$timestamp);
$timegroups = [86400, 3600, 60, 1];
$labels = ['d', 'h', 'm', 's'];
$time_string = '';

View File

@@ -227,7 +227,7 @@ class Colors
} else {
$sat = $chroma / (1 - abs(2 * $lum - 1));
if ($max == $red) {
$hue = fmod((($green - $blue) / $chrome), 6);
$hue = fmod((($green - $blue) / $chroma), 6);
if ($hue < 0) {
$hue = (6 - fmod(abs($hue), 6));
}
@@ -248,10 +248,10 @@ class Colors
/**
* converts an HSL to RGB
* @param int $h hue: 0-360 (degrees)
* @param float $s saturation: 0-100
* @param float $l luminance: 0-100
* @return array red/blue/green 0-255 each
* @param int $hue hue: 0-360 (degrees)
* @param float $sat saturation: 0-100
* @param float $lum luminance: 0-100
* @return array red/blue/green 0-255 each
*/
public static function hsl2rgb(int $hue, float $sat, float $lum): array
{

View File

@@ -9,25 +9,14 @@ namespace CoreLibs\Convert;
class MimeAppName
{
private $mime_apps= [];
private static $mime_apps = [];
/**
* constructor: init mime list
*/
public function __construct()
{
$this->mimeInitApps();
}
/**
* init array for mime type to application name lookup
* @return void
*/
private function mimeInitApps(): void
{
// match mime type to some application description
// this is NOT translated
$this->mime_apps = [
self::$mime_apps = [
// zip
'application/zip' => 'Zip File',
// Powerpoint
@@ -67,9 +56,9 @@ class MimeAppName
* @param string $app Applicaiton name
* @return void
*/
public function mimeSetAppName(string $mime, string $app): void
public static function mimeSetAppName(string $mime, string $app): void
{
$this->mime_apps[$mime] = $app;
self::$mime_apps[$mime] = $app;
}
/**
@@ -78,9 +67,9 @@ class MimeAppName
* @param string $mime MIME Name
* @return string Application name matching
*/
public function mimeGetAppName(string $mime): string
public static function mimeGetAppName(string $mime): string
{
return $this->mime_apps[$mime] ?? 'Other file';
return self::$mime_apps[$mime] ?? 'Other file';
}
}

View File

@@ -10,14 +10,6 @@
* table from the connected DB.
* you don't have to write any SQL queries, worry over update/insert
*
* PUBLIC VARIABLES
*
* PRIVATE VARIABLES
*
* PUBLIC METHOD:S
*
* PRIVATE METHOD:S
*
* HISTORY:
* 2019/9/11 (cs) error string 21->91, 22->92 for not overlapping with IO
* 2005/07/07 (cs) updated array class for postgres: set 0 & NULL if int field given, insert uses () values () syntax
@@ -105,11 +97,6 @@ class ArrayIO extends \CoreLibs\DB\IO
return $text;
}
// METHOD: convertEntities
// WAS : convert_entities
// PARAMS: string -> string to be changed
// RETURN: string -> altered string
// DESC : changeds all HTML entities into non HTML ones
/**
* changeds all HTML entities into non HTML ones
* @param string $text encoded html string
@@ -139,7 +126,7 @@ class ArrayIO extends \CoreLibs\DB\IO
}
// add output to internal error_msg
if ($write === true) {
$this->error_msg['db'] .= $string;
$this->__dbDebug('dbArray', $string);
}
return $string;
}
@@ -188,7 +175,7 @@ class ArrayIO extends \CoreLibs\DB\IO
* set this as new table array too
* @return array returns the table array that was deleted
*/
public function dbDelete($table_array = array())
public function dbDelete($table_array = [])
{
// is array and has values, override set and set new
if (is_array($table_array) && count($table_array)) {
@@ -247,7 +234,7 @@ class ArrayIO extends \CoreLibs\DB\IO
* @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())
public function dbRead($edit = false, $table_array = [])
{
// if array give, overrules internal array
if (is_array($table_array) && count($table_array)) {
@@ -320,7 +307,7 @@ class ArrayIO extends \CoreLibs\DB\IO
* @param array $table_array optional table array, overwrites internal one
* @return array table array or null
*/
public function dbWrite($addslashes = false, $table_array = array())
public function dbWrite($addslashes = false, $table_array = [])
{
if (is_array($table_array) && count($table_array)) {
$this->table_array = $table_array;

View File

@@ -278,7 +278,7 @@ class IO extends \CoreLibs\Basic
// other vars
private $nbsp = ''; // used by print_array recursion function
// error & warning id
// not error_id is defined in \CoreLibs\Basic
protected $error_id;
private $had_error;
private $warning_id;
private $had_warning;
@@ -535,7 +535,7 @@ class IO extends \CoreLibs\Basic
* @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
protected function __dbDebug(string $debug_id, string $error_string, string $id = '', string $type = ''): void
{
$prefix = '';
if ($id) {
@@ -562,7 +562,7 @@ class IO extends \CoreLibs\Basic
public function __dbError($cursor = false, string $msg = ''): void
{
$pg_error_string = '';
$where_called = (string)$this->getCallerMethod();
$where_called = (string)\CoreLibs\Debug\Support::getCallerMethod();
if ($cursor) {
$pg_error_string = $this->db_functions->__dbPrintError($cursor);
}
@@ -1115,7 +1115,7 @@ class IO extends \CoreLibs\Basic
$md5 = md5($query);
// pre declare array
if (!isset($this->cursor_ext[$md5])) {
$this->cursor_ext[$md5] = array(
$this->cursor_ext[$md5] = [
'query' => '',
'pos' => 0,
'cursor' => 0,
@@ -1123,7 +1123,7 @@ class IO extends \CoreLibs\Basic
'num_rows' => 0,
'num_fields' => 0,
'read_rows' => 0
);
];
}
// set the query
$this->cursor_ext[$md5]['query'] = $query;
@@ -1624,7 +1624,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->printAr($data));
$this->debug('ExecuteData', 'ERROR in STM['.$stm_name.'|'.$this->prepare_cursor[$stm_name]['result'].']: '.\CoreLibs\Debug\Support::printAr($data));
$this->error_id = 22;
$this->__dbError($this->prepare_cursor[$stm_name]['result']);
$this->__dbDebug('db', '<span style="color: red;"><b>DB-Error</b> '.$stm_name.': Execution failed</span>', 'DB_ERROR');
@@ -1868,10 +1868,10 @@ class IO extends \CoreLibs\Basic
array $data = []
) {
if (!is_array($primary_key)) {
$primary_key = array(
$primary_key = [
'row' => $table.'_id',
'value' => $primary_key
);
];
} else {
if (!isset($primary_key['row'])) {
$primary_key['row'] = '';

View File

@@ -266,7 +266,7 @@ class PgSQL
if ($q = $this->__dbQuery($q)) {
list($id) = $this->__dbFetchArray($q);
} else {
$id = array(-1, $q);
$id = [-1, $q];
}
return $id;
}
@@ -444,7 +444,7 @@ class PgSQL
{
if (false === $limit) {
$limit = strlen($text) - 1;
$output = array();
$output = [];
}
if ('{}' != $text) {
do {

View File

@@ -308,12 +308,14 @@ class Logging
*/
public function debugFor(string $type, string $flag): void
{
/** @phan-suppress-next-line PhanTypeMismatchArgumentReal */
$this->setLogLevel(...[func_get_args()]);
}
/**
* passes list of level names, to turn on debug
* eg $foo->debugFor('print', 'on', ['LOG', 'DEBUG', 'INFO']);
* TODO: currently we can only turn ON
* @param string $type debug, echo, print
* @param string $flag on/off
* array $array of levels to turn on/off debug
@@ -342,13 +344,13 @@ class Logging
/**
* return the log level for the array type normal and not (disable)
* @param string $type debug, echo, print
* @param string $flag on/off
* @param string $level if not null then check if this array entry is set
* else return false
* @return bool|array if $level is null, return array, else boolean true/false
* @param string $type debug, echo, print
* @param string $flag on/off
* @param string|null $level if not null then check if this array entry is set
* else return false
* @return bool|array if $level is null, return array, else boolean true/false
*/
public function getLogLevel(string $type, string $flag, string $level = null)
public function getLogLevel(string $type, string $flag, ?string $level = null)
{
// abort if not valid type
if (!in_array($type, ['debug', 'echo', 'print'])) {
@@ -367,6 +369,37 @@ class Logging
return $this->{$switch};
}
/**
* set flags for per log level type
* - level: set per sub group level
* - class: split by class
* - page: split per page called
* - run: for each run
* @param string $type Type to get: level, class, page, run
* @param bool $set True or False
* @return void
*/
public function setLogPer(string $type, bool $set): void
{
if (!in_array($type, ['level', 'class', 'page', 'run'])) {
return;
}
$this->{'log_per'.$type} = $set;
}
/**
* return current set log per flag in bool
* @param string $type Type to get: level, class, page, run
* @return bool True of false for turned on or off
*/
public function getLogPer(string $type): bool
{
if (!in_array($type, ['level', 'class', 'page', 'run'])) {
return false;
}
return $this->{'log_per'.$type};
}
/**
* write debug data to error_msg array
* @param string $level id for error message, groups messages together

View File

@@ -1035,12 +1035,12 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
}
break;
case 'date': // YYYY-MM-DD
if (!$this->checkDate($this->table_array[$key]['value'])) {
if (!\CoreLibs\Combined\DateTime::checkDate($this->table_array[$key]['value'])) {
$this->msg .= sprintf($this->l->__('Please enter a vailid date (YYYY-MM-DD) for the <b>%s</b> Field!<br>'), $this->table_array[$key]['output_name']);
}
break;
case 'time': // HH:MM[:SS]
if (!$this->checkDateTime($this->table_array[$key]['value'])) {
if (!\CoreLibs\Combined\DateTime::checkDateTime($this->table_array[$key]['value'])) {
$this->msg .= sprintf($this->l->__('Please enter a vailid time (HH:MM[:SS]) for the <b>%s</b> Field!<br>'), $this->table_array[$key]['output_name']);
}
break;
@@ -1198,7 +1198,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
// $this->log->debug('edit_error_chk', 'KEY: $prfx$key | count: '.count($_POST[$prfx.$key]).' | M: $max');
// $this->log->debug('edit_error_chk', 'K: '.$_POST[$prfx.$key].' | '.$_POST[$prfx.$key][0]);
}
$this->log->debug('POST ARRAY', $this->printAr($_POST));
$this->log->debug('POST ARRAY', \CoreLibs\Debug\Support::printAr($_POST));
// init variables before inner loop run
$mand_okay = 0;
$mand_name = '';
@@ -1503,7 +1503,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
if (isset($this->table_array[$key]['type']) && $this->table_array[$key]['type'] == 'password') {
if ($this->table_array[$key]['value']) {
// use the better new passwordSet instead of crypt based
$this->table_array[$key]['value'] = $this->passwordSet($this->table_array[$key]['value']);
$this->table_array[$key]['value'] = \CoreLibs\Check\Password::passwordSet($this->table_array[$key]['value']);
$this->table_array[$key]['HIDDEN_value'] = $this->table_array[$key]['value'];
} else {
// $this->table_array[$key]['HIDDEN_value'] =
@@ -1715,11 +1715,10 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
$this->msg = $this->l->__('Dataset has been saved!<Br>');
}
// METHOD: formDeleteTableArray
// WAS : form_delete_table_array
// PARAMS: none
// RETURN: none
// DESC : delete a table and reference fields
/**
* delete a table and reference fields
* @return void
*/
public function formDeleteTableArray()
{
// remove any reference arrays
@@ -1759,12 +1758,12 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
$this->msg = $this->l->__('Dataset has been deleted!');
}
// METHOD: formCreateHiddenFields
// WAS : form_create_hidden_fields
// PARAMS: $hidden_array
// RETURN: the input fields (html)
// DESC : creates HTML hidden input fields out of an hash array
public function formCreateHiddenFields($hidden_array = [])
/**
* creates HTML hidden input fields out of an hash array
* @param array $hidden_array The list of fields to be added as hidden
* @return array key -> value list of hidden fileds data
*/
public function formCreateHiddenFields(array $hidden_array = []): array
{
$hidden = [];
if (!is_array($this->table_array)) {
@@ -1791,12 +1790,12 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
return $hidden;
}
// METHOD: formCreateElementReferenceTable
// WAS : form_create_element_reference_table
// PARAMS: show which reference table
// RETURN: array for output
// DESC : creates the multiple select part for a reference_table
public function formCreateElementReferenceTable($table_name)
/**
* creates the multiple select part for a reference_table
* @param string $table_name Table name for reference array lookup
* @return array Reference table output array
*/
public function formCreateElementReferenceTable(string $table_name): array
{
$data = [];
$output_name = $this->reference_array[$table_name]['output_name'];

View File

@@ -25,11 +25,22 @@ if (defined('BASE')) {
// RETURN: true, so cought errors do not get processed by the PHP error engine
// DESC: will catch any error except E_ERROR and try to write them to the log file in log/php_error-<DAY>.llog
// if this fails, it will print the data to the window via echo
function MyErrorHandler($type, $message, $file, $line, $context)
/**
* will catch any error except E_ERROR and try to write them to the log file
* in log/php_error-<DAY>.log
* if this fails, it will print the data to the window via echo
* @param int $type the error code from PHP
* @param string $message the error message from php
* @param string $file in which file the error happend. this is the source file (eg include)
* @param int $line in which line the error happened
* @param array $context array with all the variable
* @return bool true, so cought errors do not get processed by the PHP error engine
*/
function MyErrorHandler(int $type, string $message, string $file, int $line, array $context): bool
{
if (!(error_reporting() & $type) && !SHOW_ALL_ERRORS) {
// This error code is not included in error_reporting
return;
return false;
}
// ERROR LEVEL
$error_level = array(
@@ -52,7 +63,7 @@ function MyErrorHandler($type, $message, $file, $line, $context)
);
// get the current page name (strip path)
$page_temp = explode("/", $_SERVER["PHP_SELF"]);
$page_temp = explode(DIRECTORY_SEPARATOR, $_SERVER["PHP_SELF"]);
// the output string:
// [] current timestamp
// {} the current page name in which the error occured (running script)
@@ -63,7 +74,7 @@ function MyErrorHandler($type, $message, $file, $line, $context)
$output = '{'.array_pop($page_temp).'} ['.$file.'] <'.$line.'> ['.$error_level[$type].'|'.$type.']: '.$message;
# try to open file
$ROOT = CURRENT_WORKING_DIR;
$LOG = 'log/';
$LOG = 'log'.DIRECTORY_SEPARATOR;
// if the log folder is not found, try to create it
if (!is_dir($ROOT.$LOG) && !is_file($ROOT.LOG)) {
$ok = mkdir($ROOT.$LOG);