diff --git a/4dev/tests/CoreLibsCreateSessionTest.php b/4dev/tests/CoreLibsCreateSessionTest.php new file mode 100644 index 00000000..ed08531d --- /dev/null +++ b/4dev/tests/CoreLibsCreateSessionTest.php @@ -0,0 +1,104 @@ + [ + 'sessionNameParameter', + 'p', + 'sessionNameParameter', + '/^\w+$/' + ], + 'session globals' => [ + 'sessionNameGlobals', + 'g', + 'sessionNameGlobals', + '/^\w+$/' + ], + 'session constant' => [ + 'sessionNameConstant', + 'c', + 'sessionNameConstant', + '/^\w+$/' + ], + ]; + } + + /** + * Undocumented function + * + * @return void + */ + protected function setUp(): void + { + if (session_id()) { + session_destroy(); + } + } + + /** + * Undocumented function + * + * @dataProvider sessionProvider + * @testdox startSession $input name for $type will be $expected_n with $expected_i [$_dataName] + * + * @param string $input + * @param string $type + * @param string|bool $expected_n + * @param string|bool $expected_i + * @return void + */ + public function testStartSession(string $input, string $type, $expected_n, $expected_i): void + { + /* $session_id = ''; + switch ($type) { + case 'p': + $session_id = \CoreLibs\Create\Session::startSession($input); + break; + case 'g': + $GLOBALS['SET_SESSION_NAME'] = $input; + $session_id = \CoreLibs\Create\Session::startSession(); + break; + case 'c': + define('SET_SESSION_NAME', $input); + $session_id = \CoreLibs\Create\Session::startSession(); + break; + } + $this->assertMatchesRegularExpression( + $expected_i, + (string)$session_id + ); + $this->assertMatchesRegularExpression( + $expected_i, + (string)\CoreLibs\Create\Session::getSessionId() + ); + $this->assertEquals( + $expected_n, + \CoreLibs\Create\Session::getSessionName() + ); + if ($type == 'g') { + unset($GLOBALS['SET_SESSION_NAME']); + } */ + $this->markTestSkipped('No implementation for Create\Session. Cannot run session_start in CLI'); + } +} + +// __END__ diff --git a/4dev/tests/CoreLibsDebugLoggingTest.php b/4dev/tests/CoreLibsDebugLoggingTest.php index 949b5f14..39152527 100644 --- a/4dev/tests/CoreLibsDebugLoggingTest.php +++ b/4dev/tests/CoreLibsDebugLoggingTest.php @@ -23,21 +23,27 @@ final class CoreLibsDebugLoggingTest extends TestCase 'log_folder' => '/tmp' ], [ - 'log_folder' => '/tmp/' + 'log_folder' => '/tmp/', + 'debug_all' => false, + 'print_all' => false, ], [] ], 'nothing set' => [ null, [ - 'log_folder' => getcwd() . DIRECTORY_SEPARATOR + 'log_folder' => getcwd() . DIRECTORY_SEPARATOR, + 'debug_all' => false, + 'print_all' => false, ], [] ], 'no options set, constant set' => [ null, [ - 'log_folder' => '/tmp/' + 'log_folder' => '/tmp/', + 'debug_all' => false, + 'print_all' => false, ], [ 'constant' => [ @@ -46,6 +52,19 @@ final class CoreLibsDebugLoggingTest extends TestCase ] ] ], + 'standard test set' => [ + [ + 'log_folder' => '/tmp', + 'debug_all' => true, + 'print_all' => true, + ], + [ + 'log_folder' => '/tmp/', + 'debug_all' => true, + 'print_all' => true, + ], + [] + ] ]; } @@ -76,11 +95,21 @@ final class CoreLibsDebugLoggingTest extends TestCase $this->log = new \CoreLibs\Debug\Logging($options); } // check that settings match - // print "LOG: " . $this->log->getSetting('log_folder') . "\n"; $this->assertEquals( $expected['log_folder'], $this->log->getSetting('log_folder') ); + $this->assertEquals( + $expected['debug_all'], + $this->log->getSetting('debug_all') + ); + $this->assertEquals( + $expected['print_all'], + $this->log->getSetting('print_all') + ); + print "LOG: " . $this->log->getSetting('log_folder') . "\n"; + print "DEBUG: " . $this->log->getSetting('debug_all') . "\n"; + print "PRINT: " . $this->log->getSetting('print_all') . "\n"; } // setting tests diff --git a/4dev/tests/CoreLibsLanguageL10n.php b/4dev/tests/CoreLibsLanguageL10nTest.php similarity index 100% rename from 4dev/tests/CoreLibsLanguageL10n.php rename to 4dev/tests/CoreLibsLanguageL10nTest.php diff --git a/README.md b/README.md index 56934e00..b357e6d6 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,8 @@ There are three branches: ### master -The active branch, which is the namespace branch +The active branch, which is the namespace branch. +Currently compatible with PHP 7.4 and 8.0 ### legacy @@ -48,3 +49,38 @@ pslam is setup but not configured With phpunit (`4dev/checking/phpunit.sh`) `phpunit -c $phpunit.xml 4dev/tests/` + + +## Other Notes + +### Session used + +The following classes use _SESSION +The main one is ACL\Login, this class will fail without a session started + + * \CoreLibs\ACL\Login + * \CoreLibs\Admin\Backend + * \CoreLibs\Output\Form\Generate + * \CoreLibs\Output\Form\Token + * \CoreLibs\Template\SmartyExtend + +### Class extends + +The following classes extend these classes + + * \CoreLibs\ACL\Login extends \CoreLibs\DB\IO + * \CoreLibs\Admin\Backend extends \CoreLibs\DB\IO + * \CoreLibs\DB\Extended\ArrayIO extends \CoreLibs\DB\IO + * \CoreLibs\Output\Form\Generate extends \CoreLibs\DB\Extended\ArrayIO + * \CoreLibs\Template\SmartyExtend extends SmartyBC + +### Class used + +The following classes use the following classes + +* \CoreLibs\ACL\Login uses \CoreLibs\Debug\Logger, \CoreLibs\Language\L10n +* \CoreLibs\DB\IO uses \CoreLibs\Debug\Logger, \CoreLibs\DB\SQL\PgSQL +* \CoreLibs\Admin\Backend uses \CoreLibs\Debug\Logger, \CoreLibs\Language\L10n +* \CoreLibs\Output\Form\Generate uses \CoreLibs\Debug\Logger, \CoreLibs\Language\L10n +* \CoreLibs\Template\SmartyExtend uses \CoreLibs\Language\L10n +* \CoreLibs\Language\L10n uses FileReader, GetTextReader diff --git a/www/admin/class_test.admin.backend.php b/www/admin/class_test.admin.backend.php index 8eb97ff9..87140bca 100644 --- a/www/admin/class_test.admin.backend.php +++ b/www/admin/class_test.admin.backend.php @@ -31,8 +31,18 @@ if (!defined('SET_SESSION_NAME')) { $LOG_FILE_ID = 'classTest-admin'; ob_end_flush(); -$basic = new CoreLibs\Basic(); -$backend = new CoreLibs\Admin\Backend(DB_CONFIG); +$log = new CoreLibs\Debug\Logging([ + 'log_folder' => BASE . LOG, + 'file_id' => $LOG_FILE_ID, + // add file date + 'print_file_date' => true, + // set debug and print flags + 'debug_all' => $DEBUG_ALL ?? false, + 'echo_all' => $ECHO_ALL ?? false, + 'print_all' => $PRINT_ALL ?? false, +]); +$basic = new CoreLibs\Basic($log); +$backend = new CoreLibs\Admin\Backend(DB_CONFIG, $log); print "TEST CLASS: ADMIN BACKEND"; print ""; @@ -47,7 +57,7 @@ print "Messaes: " . \CoreLibs\Debug\Support::printAr($this->messages) . "
"; print "ADBPRINTDATETIME:
" . $backend->adbPrintDateTime(2021, 6, 21, 6, 38, '_test') . "
"; // error message -print $basic->log->printErrorMsg(); +print $log->printErrorMsg(); print ""; diff --git a/www/admin/class_test.array.php b/www/admin/class_test.array.php index 98524a19..192edf89 100644 --- a/www/admin/class_test.array.php +++ b/www/admin/class_test.array.php @@ -32,7 +32,17 @@ ob_end_flush(); use CoreLibs\Combined\ArrayHandler; use CoreLibs\Debug\Support as DgS; -$basic = new CoreLibs\Basic(); +$log = new CoreLibs\Debug\Logging([ + 'log_folder' => BASE . LOG, + 'file_id' => $LOG_FILE_ID, + // add file date + 'print_file_date' => true, + // set debug and print flags + 'debug_all' => $DEBUG_ALL ?? false, + 'echo_all' => $ECHO_ALL ?? false, + 'print_all' => $PRINT_ALL ?? false, +]); +$basic = new CoreLibs\Basic($log); // $_array = new CoreLibs\Combined\ArrayHandler(); // $array_class = 'CoreLibs\Combination\ArrayHandler'; @@ -207,7 +217,7 @@ $output = \CoreLibs\Combined\ArrayHandler::genAssocArray($db_array, $key, $value print "OUTPUT: " . \CoreLibs\Debug\Support::printAr($output) . "
"; // error message -print $basic->log->printErrorMsg(); +print $log->printErrorMsg(); print ""; diff --git a/www/admin/class_test.byte.php b/www/admin/class_test.byte.php index b255ebc3..f8ad47cf 100644 --- a/www/admin/class_test.byte.php +++ b/www/admin/class_test.byte.php @@ -31,7 +31,17 @@ ob_end_flush(); use CoreLibs\Convert\Byte; -$basic = new CoreLibs\Basic(); +$log = new CoreLibs\Debug\Logging([ + 'log_folder' => BASE . LOG, + 'file_id' => $LOG_FILE_ID, + // add file date + 'print_file_date' => true, + // set debug and print flags + 'debug_all' => $DEBUG_ALL ?? false, + 'echo_all' => $ECHO_ALL ?? false, + 'print_all' => $PRINT_ALL ?? false, +]); +$basic = new CoreLibs\Basic($log); $byte_class = 'CoreLibs\Convert\Byte'; print "TEST CLASS: BYTE CONVERT"; @@ -104,7 +114,7 @@ print "BYTE TO: $byte: ".$basic->humanReadableByteFormat($byte)."
"; print "BYTE FROM: $string: ".$basic->stringByteFormat($string)."
"; */ // error message -print $basic->log->printErrorMsg(); +print $log->printErrorMsg(); print ""; diff --git a/www/admin/class_test.colors.php b/www/admin/class_test.colors.php index d49f4071..d3a1b627 100644 --- a/www/admin/class_test.colors.php +++ b/www/admin/class_test.colors.php @@ -32,7 +32,17 @@ ob_end_flush(); use CoreLibs\Convert\Colors; use CoreLibs\Debug\Support as DgS; -$basic = new CoreLibs\Basic(); +$log = new CoreLibs\Debug\Logging([ + 'log_folder' => BASE . LOG, + 'file_id' => $LOG_FILE_ID, + // add file date + 'print_file_date' => true, + // set debug and print flags + 'debug_all' => $DEBUG_ALL ?? false, + 'echo_all' => $ECHO_ALL ?? false, + 'print_all' => $PRINT_ALL ?? false, +]); +$basic = new CoreLibs\Basic($log); $color_class = 'CoreLibs\Convert\Colors'; print "TEST CLASS: COLORS"; @@ -70,7 +80,7 @@ print "S::COLOR hsb->rgb: $hsb[0], $hsb[1], $hsb[2]: " // TODO: run compare check input must match output // error message -print $basic->log->printErrorMsg(); +print $log->printErrorMsg(); print ""; diff --git a/www/admin/class_test.datetime.php b/www/admin/class_test.datetime.php index 99114809..80ab868f 100644 --- a/www/admin/class_test.datetime.php +++ b/www/admin/class_test.datetime.php @@ -32,7 +32,17 @@ ob_end_flush(); use CoreLibs\Combined\DateTime; use CoreLibs\Debug\Support as DgS; -$basic = new CoreLibs\Basic(); +$log = new CoreLibs\Debug\Logging([ + 'log_folder' => BASE . LOG, + 'file_id' => $LOG_FILE_ID, + // add file date + 'print_file_date' => true, + // set debug and print flags + 'debug_all' => $DEBUG_ALL ?? false, + 'echo_all' => $ECHO_ALL ?? false, + 'print_all' => $PRINT_ALL ?? false, +]); +$basic = new CoreLibs\Basic($log); $datetime_class = 'CoreLibs\Combined\DateTime'; print "TEST CLASS: DATE/TIME"; @@ -152,7 +162,7 @@ print "CALCDAYSINTERVAL(named): $compare_date[0] = $compare_date[1]: " . DgS::printAr($basic->calcDaysInterval($compare_date[0], $compare_date[1], true))."
"; */ // error message -print $basic->log->printErrorMsg(); +print $log->printErrorMsg(); print ""; diff --git a/www/admin/class_test.db.php b/www/admin/class_test.db.php index 8dd5181c..154c55ef 100644 --- a/www/admin/class_test.db.php +++ b/www/admin/class_test.db.php @@ -32,8 +32,20 @@ $LOG_FILE_ID = 'classTest-db'; ob_end_flush(); use CoreLibs\Debug\Support as DgS; +use CoreLibs\DB\IO as DbIo; -$db = $basic = new CoreLibs\Admin\Backend(DB_CONFIG); +$log = new CoreLibs\Debug\Logging([ + 'log_folder' => BASE . LOG, + 'file_id' => $LOG_FILE_ID, + // add file date + 'print_file_date' => true, + // set debug and print flags + 'debug_all' => $DEBUG_ALL ?? false, + 'echo_all' => $ECHO_ALL ?? false, + 'print_all' => $PRINT_ALL ?? false, +]); +$basic = new CoreLibs\Basic($log); +$db = new CoreLibs\Admin\Backend(DB_CONFIG, $log); // NEXT STEP // $basic = new CoreLibs\Basic(); @@ -46,13 +58,15 @@ print "TEST CLASS: DB"; print ""; print '
Class Test Master
'; +print "LOGFILE NAME: " . $db->log->getSetting('log_file_name') . "
"; +print "LOGFILE ID: " . $db->log->getSetting('log_file_id') . "
"; print "DBINFO: " . $db->dbInfo() . "
"; echo "DB_CONFIG_SET constant:
" . print_r(DB_CONFIG, true) . "

"; // DB client encoding print "DB Client encoding: " . $db->dbGetEncoding() . "
"; -while (is_array($res = $db->dbReturn("SELECT * FROM max_test", 0, true))) { +while (is_array($res = $db->dbReturn("SELECT * FROM max_test", DbIo::USE_CACHE, true))) { print "TIME: " . $res['time'] . "
"; } print "CACHED DATA:
" . print_r($db->cursor_ext, true) . "

"; @@ -324,7 +338,7 @@ print "ISSET: " . isset($res['null_varchar']) . "
"; print "EMPTY: " . empty($res['null_varchar']) . "
"; // error message -print $basic->log->printErrorMsg(); +print $log->printErrorMsg(); print ""; diff --git a/www/admin/class_test.debug.php b/www/admin/class_test.debug.php index f427aa7f..e477a516 100644 --- a/www/admin/class_test.debug.php +++ b/www/admin/class_test.debug.php @@ -63,6 +63,31 @@ print "C->DEBUG: " . $debug->debug('CLASS-TEST-DEBUG', 'Class Test Debug') . "DEBUG(html): " . $debug->debug('CLASS-TEST-DEBUG', 'HTML TAG
BOLD') . "
"; print "C->DEBUG(html,strip): " . $debug->debug('CLASS-TEST-DEBUG', 'HTML TAG
BOLD', true) . "
"; print "C->PRINTERRORMSG:
" . $debug->printErrorMsg() . "
"; + +echo "OPTIONS DEBUG CALL
"; + +// new log type with options +$new_log = new CoreLibs\Debug\Logging([ + 'log_folder' => '../log/', + 'file_id' => 'DebugTestNewLogger', + // add file date + 'print_file_date' => true, + // split into level (debug code) + 'per_level' => false, + // per class called + 'per_class' => false, + // per page + 'per_page' => false, + // for each page call + 'per_run' => false, + // set debug and print flags + 'debug_all' => true, + 'echo_all' => true, + 'print_all' => true, +]); +$new_log->debug('OPTIONS TYPE', 'New Type error'); +print "OPTIONS LOGGER:
" . $new_log->printErrorMsg(); + echo "CLASS DEBUG CALL
"; // @codingStandardsIgnoreLine diff --git a/www/admin/class_test.email.php b/www/admin/class_test.email.php index 451efad2..15efcb44 100644 --- a/www/admin/class_test.email.php +++ b/www/admin/class_test.email.php @@ -32,7 +32,17 @@ ob_end_flush(); use CoreLibs\Check\Email; use CoreLibs\Debug\Support as DgS; -$basic = new CoreLibs\Basic(); +$log = new CoreLibs\Debug\Logging([ + 'log_folder' => BASE . LOG, + 'file_id' => $LOG_FILE_ID, + // add file date + 'print_file_date' => true, + // set debug and print flags + 'debug_all' => $DEBUG_ALL ?? false, + 'echo_all' => $ECHO_ALL ?? false, + 'print_all' => $PRINT_ALL ?? false, +]); +$basic = new CoreLibs\Basic($log); print "TEST CLASS: HTML/ELEMENTS"; print ""; @@ -78,7 +88,7 @@ foreach ($email as $s_email) { } */ // error message -print $basic->log->printErrorMsg(); +print $log->printErrorMsg(); print ""; diff --git a/www/admin/class_test.encoding.php b/www/admin/class_test.encoding.php index 561d2ac7..6ef01c98 100644 --- a/www/admin/class_test.encoding.php +++ b/www/admin/class_test.encoding.php @@ -31,7 +31,17 @@ ob_end_flush(); use CoreLibs\Language\Encoding; -$basic = new CoreLibs\Basic(); +$log = new CoreLibs\Debug\Logging([ + 'log_folder' => BASE . LOG, + 'file_id' => $LOG_FILE_ID, + // add file date + 'print_file_date' => true, + // set debug and print flags + 'debug_all' => $DEBUG_ALL ?? false, + 'echo_all' => $ECHO_ALL ?? false, + 'print_all' => $PRINT_ALL ?? false, +]); +$basic = new CoreLibs\Basic($log); $_encoding = new CoreLibs\Language\Encoding(); $encoding_class = 'CoreLibs\Language\Encoding'; @@ -93,7 +103,7 @@ print "CONV ENCODING: $_string: ".$basic->convertEncoding($_string, 'ISO-2022-JP print "D/__MBMIMEENCODE: ".$basic->__mbMimeEncode('Some Text', 'UTF-8')."
"; */ // error message -print $basic->log->printErrorMsg(); +print $basic->printErrorMsg(); print ""; diff --git a/www/admin/class_test.file.php b/www/admin/class_test.file.php index 07f44833..cb0112d0 100644 --- a/www/admin/class_test.file.php +++ b/www/admin/class_test.file.php @@ -31,7 +31,17 @@ ob_end_flush(); use CoreLibs\Check\File; -$basic = new CoreLibs\Basic(); +$log = new CoreLibs\Debug\Logging([ + 'log_folder' => BASE . LOG, + 'file_id' => $LOG_FILE_ID, + // add file date + 'print_file_date' => true, + // set debug and print flags + 'debug_all' => $DEBUG_ALL ?? false, + 'echo_all' => $ECHO_ALL ?? false, + 'print_all' => $PRINT_ALL ?? false, +]); +$basic = new CoreLibs\Basic($log); print "TEST CLASS: FILE"; print ""; @@ -43,7 +53,7 @@ $file = getcwd() . DIRECTORY_SEPARATOR . 'class_test.file.php'; print "GETLINESFROMFILE: $file: " . File::getLinesFromFile($file) . "
"; // error message -print $basic->log->printErrorMsg(); +print $log->printErrorMsg(); print ""; diff --git a/www/admin/class_test.hash.php b/www/admin/class_test.hash.php index aec85b70..52c4c2b2 100644 --- a/www/admin/class_test.hash.php +++ b/www/admin/class_test.hash.php @@ -31,7 +31,17 @@ ob_end_flush(); use CoreLibs\Create\Hash; -$basic = new CoreLibs\Basic(); +$log = new CoreLibs\Debug\Logging([ + 'log_folder' => BASE . LOG, + 'file_id' => $LOG_FILE_ID, + // add file date + 'print_file_date' => true, + // set debug and print flags + 'debug_all' => $DEBUG_ALL ?? false, + 'echo_all' => $ECHO_ALL ?? false, + 'print_all' => $PRINT_ALL ?? false, +]); +$basic = new CoreLibs\Basic($log); $hash_class = 'CoreLibs\Create\Hash'; // define a list of from to color sets for conversion test @@ -58,7 +68,7 @@ print "D/__SHA1SHORT(off): $to_crc: ".$basic->__sha1short($to_crc)."
"; print "D/__hash(d): $to_crc: ".$basic->__hash($to_crc)."
"; */ // error message -print $basic->log->printErrorMsg(); +print $log->printErrorMsg(); print ""; diff --git a/www/admin/class_test.html.php b/www/admin/class_test.html.php index 10c6f663..23916d84 100644 --- a/www/admin/class_test.html.php +++ b/www/admin/class_test.html.php @@ -32,7 +32,17 @@ ob_end_flush(); use CoreLibs\Convert\Html; use CoreLibs\Output\Form\Elements; -$basic = new CoreLibs\Basic(); +$log = new CoreLibs\Debug\Logging([ + 'log_folder' => BASE . LOG, + 'file_id' => $LOG_FILE_ID, + // add file date + 'print_file_date' => true, + // set debug and print flags + 'debug_all' => $DEBUG_ALL ?? false, + 'echo_all' => $ECHO_ALL ?? false, + 'print_all' => $PRINT_ALL ?? false, +]); +$basic = new CoreLibs\Basic($log); $_html = new CoreLibs\Convert\Html(); $_elements = new CoreLibs\Output\Form\Elements(); $html_class = 'CoreLibs\Convert\Html'; @@ -109,7 +119,7 @@ print "LB remove: " . \CoreLibs\Convert\Html::removeLB($text) . "
"; print "LB remove: " . \CoreLibs\Convert\Html::removeLB($text, '##BR##') . "
"; // error message -print $basic->log->printErrorMsg(); +print $log->printErrorMsg(); print ""; diff --git a/www/admin/class_test.image.php b/www/admin/class_test.image.php index 61888392..7c18994f 100644 --- a/www/admin/class_test.image.php +++ b/www/admin/class_test.image.php @@ -31,7 +31,17 @@ ob_end_flush(); use CoreLibs\Output\Image; -$basic = new CoreLibs\Basic(); +$log = new CoreLibs\Debug\Logging([ + 'log_folder' => BASE . LOG, + 'file_id' => $LOG_FILE_ID, + // add file date + 'print_file_date' => true, + // set debug and print flags + 'debug_all' => $DEBUG_ALL ?? false, + 'echo_all' => $ECHO_ALL ?? false, + 'print_all' => $PRINT_ALL ?? false, +]); +$basic = new CoreLibs\Basic($log); $_image = new CoreLibs\Output\Image(); $image_class = 'CoreLibs\Output\Image'; @@ -112,7 +122,7 @@ echo "
S::CREATETHUMBNAILSIMPLE: ".basename($image).": WIDTH: $thumb_widthcreateThumbnailSimple($image, $thumb_width).">
"; */ // error message -print $basic->log->printErrorMsg(); +print $log->printErrorMsg(); print ""; diff --git a/www/admin/class_test.json.php b/www/admin/class_test.json.php index 15f93e20..04f753f0 100644 --- a/www/admin/class_test.json.php +++ b/www/admin/class_test.json.php @@ -32,7 +32,17 @@ ob_end_flush(); use CoreLibs\Convert\Json; use CoreLibs\Debug\Support as DgS; -$basic = new CoreLibs\Basic(); +$log = new CoreLibs\Debug\Logging([ + 'log_folder' => BASE . LOG, + 'file_id' => $LOG_FILE_ID, + // add file date + 'print_file_date' => true, + // set debug and print flags + 'debug_all' => $DEBUG_ALL ?? false, + 'echo_all' => $ECHO_ALL ?? false, + 'print_all' => $PRINT_ALL ?? false, +]); +$basic = new CoreLibs\Basic($log); $json_class = 'CoreLibs\Convert\Json'; // define a list of from to color sets for conversion test @@ -74,7 +84,7 @@ print "E-JSON ERROR: ".$basic->jsonGetLastError().": ".$basic->jsonGetLastError( // print "S::JSON ERROR: " . Jason::jsonGetLastError() . ": " . Jason::jsonGetLastError(true) . "
"; // error message -print $basic->log->printErrorMsg(); +print $log->printErrorMsg(); print ""; diff --git a/www/admin/class_test.math.php b/www/admin/class_test.math.php index b600474e..ea6141f0 100644 --- a/www/admin/class_test.math.php +++ b/www/admin/class_test.math.php @@ -29,7 +29,17 @@ if (!defined('SET_SESSION_NAME')) { $LOG_FILE_ID = 'classTest-math'; ob_end_flush(); -$basic = new CoreLibs\Basic(); +$log = new CoreLibs\Debug\Logging([ + 'log_folder' => BASE . LOG, + 'file_id' => $LOG_FILE_ID, + // add file date + 'print_file_date' => true, + // set debug and print flags + 'debug_all' => $DEBUG_ALL ?? false, + 'echo_all' => $ECHO_ALL ?? false, + 'print_all' => $PRINT_ALL ?? false, +]); +$basic = new CoreLibs\Basic($log); $_math = new CoreLibs\Convert\Math(); $math_class = 'CoreLibs\Convert\Math'; @@ -57,7 +67,7 @@ print "FLOORP: ".$basic->floorp(5123456, -3)."
"; print "INITNUMERIC: ".$basic->initNumeric('123')."
"; */ // error message -print $basic->log->printErrorMsg(); +print $log->printErrorMsg(); print ""; diff --git a/www/admin/class_test.mime.php b/www/admin/class_test.mime.php index e7726f12..6cb95f60 100644 --- a/www/admin/class_test.mime.php +++ b/www/admin/class_test.mime.php @@ -29,7 +29,17 @@ if (!defined('SET_SESSION_NAME')) { $LOG_FILE_ID = 'classTest-mime'; ob_end_flush(); -$basic = new CoreLibs\Basic(); +$log = new CoreLibs\Debug\Logging([ + 'log_folder' => BASE . LOG, + 'file_id' => $LOG_FILE_ID, + // add file date + 'print_file_date' => true, + // set debug and print flags + 'debug_all' => $DEBUG_ALL ?? false, + 'echo_all' => $ECHO_ALL ?? false, + 'print_all' => $PRINT_ALL ?? false, +]); +$basic = new CoreLibs\Basic($log); $_mime = new CoreLibs\Convert\MimeAppName(); print "TEST CLASS: MIME"; @@ -61,7 +71,7 @@ $mime = 'fake/mime'; $basic->mimeSetAppName($mime, 'This is a fake mime'); print "MIME $mime: ".$basic->mimeGetAppName($mime)."
"; */ -print $basic->log->printErrorMsg(); +print $log->printErrorMsg(); print ""; diff --git a/www/admin/class_test.output.form.php b/www/admin/class_test.output.form.php index 48767c31..123a5ac8 100644 --- a/www/admin/class_test.output.form.php +++ b/www/admin/class_test.output.form.php @@ -57,8 +57,18 @@ $table_arrays[\CoreLibs\Get\System::getPageName(1)] = [ ] ]; -$basic = new CoreLibs\Basic(); -$form = new CoreLibs\Output\Form\Generate(DB_CONFIG); +$log = new CoreLibs\Debug\Logging([ + 'log_folder' => BASE . LOG, + 'file_id' => $LOG_FILE_ID, + // add file date + 'print_file_date' => true, + // set debug and print flags + 'debug_all' => $DEBUG_ALL ?? false, + 'echo_all' => $ECHO_ALL ?? false, + 'print_all' => $PRINT_ALL ?? false, +]); +$basic = new CoreLibs\Basic($log); +$form = new CoreLibs\Output\Form\Generate(DB_CONFIG, $log); // $db = new CoreLibs\DB\IO(DB_CONFIG, $basic->log); print "TEST CLASS: FORM GENERATE"; @@ -70,7 +80,7 @@ print "MOBILE PHONE: " . $form->mobile_phone . "
"; print "MY PAGE NAME: " . $form->my_page_name . "
"; // error message -print $basic->log->printErrorMsg(); +print $log->printErrorMsg(); print ""; diff --git a/www/admin/class_test.password.php b/www/admin/class_test.password.php index 787e5a78..73f24a76 100644 --- a/www/admin/class_test.password.php +++ b/www/admin/class_test.password.php @@ -31,7 +31,17 @@ ob_end_flush(); use CoreLibs\Check\Password as PwdChk; -$basic = new CoreLibs\Basic(); +$log = new CoreLibs\Debug\Logging([ + 'log_folder' => BASE . LOG, + 'file_id' => $LOG_FILE_ID, + // add file date + 'print_file_date' => true, + // set debug and print flags + 'debug_all' => $DEBUG_ALL ?? false, + 'echo_all' => $ECHO_ALL ?? false, + 'print_all' => $PRINT_ALL ?? false, +]); +$basic = new CoreLibs\Basic($log); $_password = new CoreLibs\Check\Password(); $password_class = 'CoreLibs\Check\Password'; @@ -63,7 +73,7 @@ print "PASSWORD VERIFY: ".(string)$basic->passwordVerify($password, $enc_passwor print "PASSWORD REHASH: ".(string)$basic->passwordRehashCheck($enc_password)."
"; */ // error message -print $basic->log->printErrorMsg(); +print $log->printErrorMsg(); print ""; diff --git a/www/admin/class_test.php b/www/admin/class_test.php index 769f571f..64fbd4e7 100644 --- a/www/admin/class_test.php +++ b/www/admin/class_test.php @@ -29,8 +29,18 @@ if (!defined('SET_SESSION_NAME')) { $LOG_FILE_ID = 'classTest'; // init login & backend class -$login = new CoreLibs\ACL\Login(DB_CONFIG); -$basic = new CoreLibs\Admin\Backend(DB_CONFIG); +$log = new CoreLibs\Debug\Logging([ + 'log_folder' => BASE . LOG, + 'file_id' => $LOG_FILE_ID, + // add file date + 'print_file_date' => true, + // set debug and print flags + 'debug_all' => $DEBUG_ALL ?? false, + 'echo_all' => $ECHO_ALL ?? false, + 'print_all' => $PRINT_ALL ?? false, +]); +$login = new CoreLibs\ACL\Login(DB_CONFIG, $log); +$basic = new CoreLibs\Admin\Backend(DB_CONFIG, $log); $basic->dbInfo(true); ob_end_flush(); @@ -103,13 +113,13 @@ foreach (['debug', 'echo', 'print'] as $type) { print strtoupper($type) . ' OUT ALL: ' . $basic->log->getLogLevelAll($type) . '
'; } -$basic->log->debug('SOME MARK', 'Some error output'); +$log->debug('SOME MARK', 'Some error output'); // INTERNAL SET print "EDIT ACCESS ID: " . $basic->edit_access_id . "
"; if (is_object($login)) { // print "ACL:
".$basic->print_ar($login->acl)."
"; - $basic->log->debug('ACL', "ACL: " . \CoreLibs\Debug\Support::printAr($login->acl)); + $log->debug('ACL', "ACL: " . \CoreLibs\Debug\Support::printAr($login->acl)); // print "DEFAULT ACL:
".$basic->print_ar($login->default_acl_list)."
"; // print "DEFAULT ACL:
".$basic->print_ar($login->default_acl_list)."
"; // $result = array_flip( @@ -140,7 +150,7 @@ print "SERVER HOST: " . $_SERVER['HTTP_HOST'] . "
"; // print error messages // print $login->log->printErrorMsg(); -print $basic->log->printErrorMsg(); +print $log->printErrorMsg(); print ""; diff --git a/www/admin/class_test.phpv.php b/www/admin/class_test.phpv.php index 280432da..1a5275e1 100644 --- a/www/admin/class_test.phpv.php +++ b/www/admin/class_test.phpv.php @@ -31,7 +31,17 @@ ob_end_flush(); use CoreLibs\Check\PhpVersion; -$basic = new CoreLibs\Basic(); +$log = new CoreLibs\Debug\Logging([ + 'log_folder' => BASE . LOG, + 'file_id' => $LOG_FILE_ID, + // add file date + 'print_file_date' => true, + // set debug and print flags + 'debug_all' => $DEBUG_ALL ?? false, + 'echo_all' => $ECHO_ALL ?? false, + 'print_all' => $PRINT_ALL ?? false, +]); +$basic = new CoreLibs\Basic($log); $_phpv = new CoreLibs\Check\PhpVersion(); $phpv_class = 'CoreLibs\Check\PhpVersion'; @@ -63,7 +73,7 @@ print "U-S::MIN: $min_version: " . (string)PhpVersion::checkPHPVersion($min_vers // print "MIN: $min_version: ".(string)$basic->checkPHPVersion($min_version)."
"; // error message -print $basic->log->printErrorMsg(); +print $log->printErrorMsg(); print ""; diff --git a/www/admin/class_test.randomkey.php b/www/admin/class_test.randomkey.php index ef555541..de335b20 100644 --- a/www/admin/class_test.randomkey.php +++ b/www/admin/class_test.randomkey.php @@ -31,7 +31,17 @@ ob_end_flush(); use CoreLibs\Create\RandomKey; -$basic = new CoreLibs\Basic(); +$log = new CoreLibs\Debug\Logging([ + 'log_folder' => BASE . LOG, + 'file_id' => $LOG_FILE_ID, + // add file date + 'print_file_date' => true, + // set debug and print flags + 'debug_all' => $DEBUG_ALL ?? false, + 'echo_all' => $ECHO_ALL ?? false, + 'print_all' => $PRINT_ALL ?? false, +]); +$basic = new CoreLibs\Basic($log); $array_class = 'CoreLibs\Create\RandomKey'; print "TEST CLASS: RANDOM KEY"; @@ -51,7 +61,7 @@ print "C->RANDOMKEYGEN(auto): " . $_array->randomKeyGen() . "
"; // print "D\RANDOMKEYGEN(auto): ".$basic->randomKeyGen()."
"; // error message -print $basic->log->printErrorMsg(); +print $log->printErrorMsg(); print ""; diff --git a/www/admin/class_test.runningtime.php b/www/admin/class_test.runningtime.php index d4f265dd..549638ba 100644 --- a/www/admin/class_test.runningtime.php +++ b/www/admin/class_test.runningtime.php @@ -31,7 +31,17 @@ ob_end_flush(); use CoreLibs\Debug\RunningTime; -$basic = new CoreLibs\Basic(); +$log = new CoreLibs\Debug\Logging([ + 'log_folder' => BASE . LOG, + 'file_id' => $LOG_FILE_ID, + // add file date + 'print_file_date' => true, + // set debug and print flags + 'debug_all' => $DEBUG_ALL ?? false, + 'echo_all' => $ECHO_ALL ?? false, + 'print_all' => $PRINT_ALL ?? false, +]); +$basic = new CoreLibs\Basic($log); print "TEST CLASS: RUNNING IMTE"; print ""; @@ -59,7 +69,7 @@ echo "RANDOM KEY [default]: ".$basic->randomKeyGen()."
"; echo "TIMED [hr]: ".$basic->hrRunningTime()."
"; */ // error message -print $basic->log->printErrorMsg(); +print $log->printErrorMsg(); print ""; diff --git a/www/admin/class_test.smarty.php b/www/admin/class_test.smarty.php index a5eb892a..2c986a59 100644 --- a/www/admin/class_test.smarty.php +++ b/www/admin/class_test.smarty.php @@ -33,7 +33,17 @@ if (!defined('SET_SESSION_NAME')) { $LOG_FILE_ID = 'classTest-smarty'; ob_end_flush(); -$basic = new CoreLibs\Basic(); +$log = new CoreLibs\Debug\Logging([ + 'log_folder' => BASE . LOG, + 'file_id' => $LOG_FILE_ID, + // add file date + 'print_file_date' => true, + // set debug and print flags + 'debug_all' => $DEBUG_ALL ?? false, + 'echo_all' => $ECHO_ALL ?? false, + 'print_all' => $PRINT_ALL ?? false, +]); +$basic = new CoreLibs\Basic($log); $smarty = new CoreLibs\Template\SmartyExtend(); // for testing with or without CMS // $cms = new CoreLibs\Admin\Backend(DB_CONFIG); @@ -90,7 +100,7 @@ $smarty->DATA['loop_start'] = 2; $smarty->setSmartyVarsAdmin(); // error message -print $basic->log->printErrorMsg(); +print $log->printErrorMsg(); print ""; diff --git a/www/admin/class_test.system.php b/www/admin/class_test.system.php index 82adf93c..5bdd8945 100644 --- a/www/admin/class_test.system.php +++ b/www/admin/class_test.system.php @@ -32,7 +32,17 @@ ob_end_flush(); use CoreLibs\Get\System; use CoreLibs\Debug\Support as DgS; -$basic = new CoreLibs\Basic(); +$log = new CoreLibs\Debug\Logging([ + 'log_folder' => BASE . LOG, + 'file_id' => $LOG_FILE_ID, + // add file date + 'print_file_date' => true, + // set debug and print flags + 'debug_all' => $DEBUG_ALL ?? false, + 'echo_all' => $ECHO_ALL ?? false, + 'print_all' => $PRINT_ALL ?? false, +]); +$basic = new CoreLibs\Basic($log); print "TEST CLASS: SYSTEM"; print ""; @@ -49,6 +59,6 @@ print "FILEUPLOADERRORMESSAGE(UPLOAD_ERR_CANT_WRITE): " . System::fileUploadErrorMessage(UPLOAD_ERR_CANT_WRITE) . "
"; // error message -print $basic->log->printErrorMsg(); +print $log->printErrorMsg(); print ""; diff --git a/www/admin/class_test.token.php b/www/admin/class_test.token.php index 7d6e763a..fbf8f4ff 100644 --- a/www/admin/class_test.token.php +++ b/www/admin/class_test.token.php @@ -29,7 +29,17 @@ if (!defined('SET_SESSION_NAME')) { $LOG_FILE_ID = 'classTest-token'; ob_end_flush(); -$basic = new CoreLibs\Basic(); +$log = new CoreLibs\Debug\Logging([ + 'log_folder' => BASE . LOG, + 'file_id' => $LOG_FILE_ID, + // add file date + 'print_file_date' => true, + // set debug and print flags + 'debug_all' => $DEBUG_ALL ?? false, + 'echo_all' => $ECHO_ALL ?? false, + 'print_all' => $PRINT_ALL ?? false, +]); +$basic = new CoreLibs\Basic($log); $_token = new CoreLibs\Output\Form\Token(); $token_class = 'CoreLibs\Output\Form\Token'; @@ -54,7 +64,7 @@ print "TOKEN: $token: (ID) ".$token_id." => (S) ".$_SESSION[$token]."
"; print "VALIDATE: $token: ".(string)$basic->validateFormToken($token_id, $token)."
"; */ // error message -print $basic->log->printErrorMsg(); +print $log->printErrorMsg(); print ""; diff --git a/www/admin/class_test.uids.php b/www/admin/class_test.uids.php index f1f20b47..b3e3b06e 100644 --- a/www/admin/class_test.uids.php +++ b/www/admin/class_test.uids.php @@ -29,7 +29,17 @@ if (!defined('SET_SESSION_NAME')) { $LOG_FILE_ID = 'classTest-uids'; ob_end_flush(); -$basic = new CoreLibs\Basic(); +$log = new CoreLibs\Debug\Logging([ + 'log_folder' => BASE . LOG, + 'file_id' => $LOG_FILE_ID, + // add file date + 'print_file_date' => true, + // set debug and print flags + 'debug_all' => $DEBUG_ALL ?? false, + 'echo_all' => $ECHO_ALL ?? false, + 'print_all' => $PRINT_ALL ?? false, +]); +$basic = new CoreLibs\Basic($log); $_uids = new CoreLibs\Create\Uids(); $uids_class = 'CoreLibs\Create\Uids'; @@ -52,7 +62,7 @@ print "S::UNIQID (sha256): " . $uids_class::uniqId('sha256') . "
"; print "/DUNIQID (d): ".$basic->uniqId()."
"; */ // error message -print $basic->log->printErrorMsg(); +print $log->printErrorMsg(); print ""; diff --git a/www/configs/config.db.php b/www/configs/config.db.php index b3e094cd..0a5141f3 100755 --- a/www/configs/config.db.php +++ b/www/configs/config.db.php @@ -21,7 +21,8 @@ $DB_CONFIG = [ 'db_schema' => 'public', 'db_type' => 'pgsql', 'db_encoding' => '', - 'db_ssl' => 'allow' // allow, disable, require, prefer + 'db_ssl' => 'allow', // allow, disable, require, prefer + 'db_debug' => true, // turn on logging or not ], ]; diff --git a/www/includes/admin_header.php b/www/includes/admin_header.php index 2d72ed97..ccc90d9f 100644 --- a/www/includes/admin_header.php +++ b/www/includes/admin_header.php @@ -46,12 +46,33 @@ if ($AJAX_PAGE && !$ZIP_STREAM) { //------------------------------ basic variable settings start //------------------------------ class init start +// create logger +$log = new CoreLibs\Debug\Logging([ + 'log_folder' => BASE . LOG, + 'file_id' => LOG_FILE_ID, + 'print_file_date' => true, + 'per_class' => true, + 'debug_all' => $DEBUG_ALL, + 'echo_all' => $ECHO_ALL, + 'print_all' => $PRINT_ALL, +]); +// 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') && !empty($DEBUG_ALL_OVERRIDE)) { + foreach (['debug', 'echo', 'print'] as $target) { + $log->setLogLevelAll($target, false); + } +} +// start session +CoreLibs\Create\Session::startSession(); // login & page access check -$login = new CoreLibs\ACL\Login(DB_CONFIG); +$login = new CoreLibs\ACL\Login(DB_CONFIG, $log); // create smarty object $smarty = new CoreLibs\Template\SmartyExtend(); // create new DB class -$cms = new CoreLibs\Admin\Backend(DB_CONFIG); +$log->setLogPer('class', false); +$cms = new CoreLibs\Admin\Backend(DB_CONFIG, $log); // the menu show flag (what menu to show) $cms->menu_show_flag = 'main'; // db nfo @@ -65,12 +86,12 @@ ob_end_flush(); //------------------------------ logging start // log backend data // data part creation -$data = array( +$data = [ '_SESSION' => $_SESSION, '_GET' => $_GET, '_POST' => $_POST, '_FILES' => $_FILES -); +]; // log action // no log if login if (!$login->login) { @@ -78,14 +99,7 @@ if (!$login->login) { } //------------------------------ logging end -// 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') && !empty($DEBUG_ALL_OVERRIDE)) { - foreach (['debug', 'echo', 'print'] as $target) { - $login->log->setLogLevelAll($target, false); - $cms->log->setLogLevelAll($target, false); - } -} +// pass on DEBUG flag to JS via smarty variable $smarty->DATA['JS_DEBUG'] = DEBUG; // __END__ diff --git a/www/includes/edit_base.php b/www/includes/edit_base.php index f1b11b0f..a822c1e2 100644 --- a/www/includes/edit_base.php +++ b/www/includes/edit_base.php @@ -25,6 +25,7 @@ declare(strict_types=1); $DEBUG_ALL = true; $PRINT_ALL = true; +$ECHO_ALL = false; $DB_DEBUG = true; // TODO: only extract _POST data that is needed @@ -33,7 +34,7 @@ extract($_POST, EXTR_SKIP); ob_start(); require 'config.php'; // set session name here -$SET_SESSION_NAME = EDIT_SESSION_NAME; +// $SET_SESSION_NAME = EDIT_SESSION_NAME; // overrride debug flags if (!DEBUG) { $DEBUG_ALL = false; @@ -44,11 +45,26 @@ if (!DEBUG) { // should be utf8 header("Content-type: text/html; charset=" . DEFAULT_ENCODING); +// set session +\CoreLibs\Create\Session::startSession(EDIT_SESSION_NAME); +// init logger +$log = new CoreLibs\Debug\Logging([ + 'log_folder' => BASE . LOG, + 'file_id' => LOG_FILE_ID . 'EditBase', + 'print_file_date' => true, + 'per_class' => true, + 'debug_all' => $DEBUG_ALL, + 'echo_all' => $ECHO_ALL, + 'print_all' => $PRINT_ALL, +]); +// login page +$login = new CoreLibs\ACL\Login(DB_CONFIG, $log); +// flush and start ob_end_flush(); -$login = new CoreLibs\ACL\Login(DB_CONFIG); - +// turn off set log per class +$log->setLogPer('class', false); // create form class -$form = new CoreLibs\Output\Form\Generate(DB_CONFIG); +$form = new CoreLibs\Output\Form\Generate(DB_CONFIG, $log); if ($form->mobile_phone) { echo "I am sorry, but this page cannot be viewed by a mobile phone"; exit; diff --git a/www/lib/CoreLibs/ACL/Login.php b/www/lib/CoreLibs/ACL/Login.php index deb8b58c..8e5fe10a 100644 --- a/www/lib/CoreLibs/ACL/Login.php +++ b/www/lib/CoreLibs/ACL/Login.php @@ -117,6 +117,8 @@ class Login extends \CoreLibs\DB\IO private $max_login_error_count = -1; /** @var array */ private $lock_deny_users = []; + /** @var string */ + private $page_name; // if we have password change we need to define some rules /** @var int */ @@ -160,13 +162,20 @@ class Login extends \CoreLibs\DB\IO /** * constructor, does ALL, opens db, works through connection checks, closes itself * @param array $db_config db config array + * @param \CoreLibs\Debug\Logging|null $log Logging class, if null, auto set + * @param \CoreLibs\Language\L10n|null $l10n l10n language class, if null, auto set */ - public function __construct(array $db_config) - { + public function __construct( + array $db_config, + ?\CoreLibs\Debug\Logging $log = null, + ?\CoreLibs\Language\L10n $l10n = null + ) { // create db connection and init base class - parent::__construct($db_config); + parent::__construct($db_config, $log ?? new \CoreLibs\Debug\Logging()); // log login data for this class only $this->log->setLogPer('class', true); + // set internal page name + $this->page_name = \CoreLibs\Get\System::getPageName(); // set db special errors if ($this->db_init_error === true) { echo 'Could not connect to DB
'; @@ -174,7 +183,10 @@ class Login extends \CoreLibs\DB\IO exit; } - // no session could be found at all + // initial the session if there is no session running already + // TODO: move that to outside + \CoreLibs\Create\Session::startSession(); + // check if session exists if (!session_id()) { echo 'Session not started!
Use \'session_start();\'.
'; echo 'For less problems with other session, you can set a session name with \'session_name("name");\'.
'; @@ -202,7 +214,7 @@ class Login extends \CoreLibs\DB\IO } else { $lang = defined('SITE_LANG') ? SITE_LANG : DEFAULT_LANG; } - $this->l = new \CoreLibs\Language\L10n($lang); + $this->l = $l10n ?? new \CoreLibs\Language\L10n($lang); // if we have a search path we need to set it, to use the correct DB to login // check what schema to use. if there is a login schema use this, else check diff --git a/www/lib/CoreLibs/Admin/Backend.php b/www/lib/CoreLibs/Admin/Backend.php index f5c1fd3d..ad0649c8 100644 --- a/www/lib/CoreLibs/Admin/Backend.php +++ b/www/lib/CoreLibs/Admin/Backend.php @@ -73,6 +73,8 @@ class Backend extends \CoreLibs\DB\IO // the current active edit access id /** @var int */ public $edit_access_id; + /** @var string */ + public $page_name; // error/warning/info messages /** @var array */ public $messages = []; @@ -108,15 +110,25 @@ class Backend extends \CoreLibs\DB\IO /** * main class constructor * @param array $db_config db config array + * @param \CoreLibs\Debug\Logging|null $log Logging class, default set if not set */ - public function __construct(array $db_config) - { + public function __construct( + array $db_config, + ?\CoreLibs\Debug\Logging $log = null + ) { + // set to log not per class + if ($log !== null) { + $log->setLogPer('class', false); + } $this->setLangEncoding(); // get the language sub class & init it $this->l = new \CoreLibs\Language\L10n($this->lang); // init the database class - parent::__construct($db_config); + parent::__construct($db_config, $log ?? new \CoreLibs\Debug\Logging()); + + // set the page name + $this->page_name = \CoreLibs\Get\System::getPageName(); // set the action ids foreach ($this->action_list as $_action) { diff --git a/www/lib/CoreLibs/Basic.php b/www/lib/CoreLibs/Basic.php index 54aa4f6e..b99dedc3 100644 --- a/www/lib/CoreLibs/Basic.php +++ b/www/lib/CoreLibs/Basic.php @@ -77,21 +77,19 @@ class Basic /** @var array */ public $data_path = []; - // session name - /** @var string */ - private $session_name = ''; - /** @var string */ - private $session_id = ''; /** @phpstan-ignore-line */ - // ajax flag /** @var bool */ protected $ajax_page_flag = false; /** * main Basic constructor to init and check base settings + * @param \CoreLibs\Debug\Logging|null $log Logging class + * @param string|null $session_name Set session name */ - public function __construct() - { + public function __construct( + \CoreLibs\Debug\Logging $log = null, + ?string $session_name = null + ) { // 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; @@ -117,6 +115,9 @@ class Basic die('Core Constant missing. Check config file.'); } + // logging interface moved here (->debug is now ->log->debug) + $this->log = $log ?? new \CoreLibs\Debug\Logging(); + // set ajax page flag based on the AJAX_PAGE varaibles // convert to true/false so if AJAX_PAGE is 0 or false it is // always boolean false @@ -136,8 +137,6 @@ class Basic $this->page_name = \CoreLibs\Get\System::getPageName(); // set host name list($this->host_name , $this->host_port) = \CoreLibs\Get\System::getHostName(); - // logging interface moved here (->debug is now ->log->debug) - $this->log = new \CoreLibs\Debug\Logging(); // set the regex for checking emails /** @deprecated */ @@ -147,25 +146,7 @@ class Basic $this->email_regex_check = \CoreLibs\Check\Email::getEmailRegexCheck(); // initial the session if there is no session running already - if (!session_id()) { - // check if we have an external session name given, else skip this step - if (defined('SET_SESSION_NAME')) { - // set the session name for possible later check - $this->session_name = SET_SESSION_NAME; - } - // override with global if set - if (isset($GLOBALS['SET_SESSION_NAME'])) { - $this->session_name = $GLOBALS['SET_SESSION_NAME']; - } - // if set, set special session name - if ($this->session_name) { - session_name($this->session_name); - } - // start session - session_start(); - // set internal session id, we can use that later for protection check - $this->session_id = (string)session_id(); - } + \CoreLibs\Create\Session::startSession($session_name); } /** diff --git a/www/lib/CoreLibs/Create/Session.php b/www/lib/CoreLibs/Create/Session.php new file mode 100644 index 00000000..2318b4a9 --- /dev/null +++ b/www/lib/CoreLibs/Create/Session.php @@ -0,0 +1,74 @@ + $db_config db connection config * @param array $table_array table array config * @param string $table_name table name string + * @param \CoreLibs\Debug\Logging|null $log Logging class, default set if not set */ - public function __construct(array $db_config, array $table_array, string $table_name) - { + public function __construct( + array $db_config, + array $table_array, + string $table_name, + \CoreLibs\Debug\Logging $log = null + ) { // instance db_io class - parent::__construct($db_config); + parent::__construct($db_config, $log ?? new \CoreLibs\Debug\Logging()); // more error vars for this class $this->error_string['91'] = 'No Primary Key given'; $this->error_string['92'] = 'Could not run Array Query'; diff --git a/www/lib/CoreLibs/DB/IO.php b/www/lib/CoreLibs/DB/IO.php index 56376239..078e1e31 100644 --- a/www/lib/CoreLibs/DB/IO.php +++ b/www/lib/CoreLibs/DB/IO.php @@ -101,7 +101,7 @@ * - used for recursive function [var might disappear if I have time to recode the recursive function] * * PUBLIC METHODS -* $mixed db_return($query,$reset=0) +* $mixed db_return($query,$reset=self::USE_CACHE) * - executes query, returns data & caches it (1 = reset/destroy, 2 = reset/cache, 3 = reset/no cache) * 1/0 db_cache_reset($query) * - resets the cache for one query @@ -252,8 +252,21 @@ declare(strict_types=1); namespace CoreLibs\DB; -class IO extends \CoreLibs\Basic +class IO { + // 0: normal read, store in cache + // 1: read cache, clean at the end + // 2: read new, clean at end + // 3: never cache + /** @var int */ + public const USE_CACHE = 0; + /** @var int */ + public const CLEAR_CACHE = 1; + /** @var int */ + public const READ_NEW = 2; + /** @var int */ + public const NO_CACHE = 3; + // recommend to set private/protected and only allow setting via method // can bet set from outside // encoding to @@ -265,8 +278,8 @@ class IO extends \CoreLibs\Basic // basic vars /** @var resource|bool|int|null */ private $dbh; // the dbh handler, if disconnected by command is null, bool:false/int:-1 on error, - /** @var int|bool */ - public $db_debug; // DB_DEBUG ... (if set prints out debug msgs) [should be bool only] + /** @var bool */ + public $db_debug = false; // DB_DEBUG ... (if set prints out debug msgs) /** @var string */ private $db_name; // the DB connected to /** @var string */ @@ -320,12 +333,11 @@ class IO extends \CoreLibs\Basic // sub include with the database functions /** @var \CoreLibs\DB\SQL\PgSQL */ private $db_functions; - // endless loop protection /** @var int */ private $MAX_QUERY_CALL; /** @var int */ - private $DEFAULT_MAX_QUERY_CALL = 20; // default + private const DEFAULT_MAX_QUERY_CALL = 20; // default /** @var array */ private $query_called = []; // error string @@ -347,20 +359,21 @@ class IO extends \CoreLibs\Basic // if a sync is running holds the md5 key of the query /** @var string */ private $async_running; + // logging class, must be public so settings can be changed + /** @var \CoreLibs\Debug\Logging */ + public $log; /** * main DB concstructor with auto connection to DB and failure set on failed connection * @param array $db_config DB configuration array + * @param \CoreLibs\Debug\Logging|null $log Logging class */ - public function __construct(array $db_config) - { - // start basic class - parent::__construct(); - // dummy init array for db config if not array - if (!is_array($db_config)) { - $db_config = []; - } - // TODO: check must set CONSTANTS + public function __construct( + array $db_config, + ?\CoreLibs\Debug\Logging $log = null + ) { + // attach logger + $this->log = $log ?? new \CoreLibs\Debug\Logging(); // sets the names (for connect/reconnect) $this->db_name = $db_config['db_name'] ?? ''; $this->db_user = $db_config['db_user'] ?? ''; @@ -372,12 +385,14 @@ class IO extends \CoreLibs\Basic $this->db_encoding = !empty($db_config['db_encoding']) ? $db_config['db_encoding'] : ''; $this->db_type = $db_config['db_type'] ?? ''; $this->db_ssl = !empty($db_config['db_ssl']) ? $db_config['db_ssl'] : 'allow'; + // set debug, either via global var, or from config, else set to false + $this->dbSetDebug($GLOBALS['DB_DEBUG'] ?? $db_config['db_debug'] ?? false); // set the target encoding to the DEFAULT_ENCODING if it is one of them: EUC, Shift_JIS, UTF-8 // @ the moment set only from outside // set loop protection max count - $this->MAX_QUERY_CALL = 20; + $this->MAX_QUERY_CALL = self::DEFAULT_MAX_QUERY_CALL; // error & debug stuff, error & warning ids are the same, its just in which var they get written $this->error_string['10'] = 'Could not load DB interface functions'; @@ -409,13 +424,6 @@ class IO extends \CoreLibs\Basic $this->error_string['50'] = 'Setting max query call to -1 will disable loop protection for all subsequent runs'; $this->error_string['51'] = 'Max query call needs to be set to at least 1'; - // set debug, either via global var, or debug var during call - $this->db_debug = false; - // global overrules local - if (isset($GLOBALS['DB_DEBUG'])) { - $this->db_debug = $GLOBALS['DB_DEBUG']; - } - // based on $this->db_type // here we need to load the db pgsql include one // How can we do this dynamic? eg for non PgSQL @@ -444,7 +452,6 @@ class IO extends \CoreLibs\Basic public function __destruct() { $this->__closeDB(); - // parent::__destruct(); } // ************************************************************* @@ -982,18 +989,16 @@ class IO extends \CoreLibs\Basic * 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 + * @return bool debug flag in int */ - public function dbSetDebug($debug = null): int + public function dbSetDebug($debug = null): bool { if ($debug === true) { - $this->db_debug = 1; + $this->db_debug = true; } elseif ($debug === false) { - $this->db_debug = 0; - } elseif ($this->db_debug) { - $this->db_debug = 0; - } else { - $this->db_debug = 1; + $this->db_debug = false; + } elseif ($this->db_debug === null) { + $this->db_debug = false; } return $this->db_debug; } @@ -1006,7 +1011,7 @@ class IO extends \CoreLibs\Basic * @param bool|null $debug Flag to turn debug on off * @return bool True for debug is on, False for off */ - public function dbToggleDebug(?bool $debug = null) + public function dbToggleDebug(?bool $debug = null): bool { if ($debug !== null) { $this->db_debug = $debug; @@ -1028,7 +1033,7 @@ class IO extends \CoreLibs\Basic $success = false; // if null then reset to default if ($max_calls === null) { - $max_calls = $this->DEFAULT_MAX_QUERY_CALL; + $max_calls = self::DEFAULT_MAX_QUERY_CALL; } // if -1 then disable loop check // DANGEROUS, WARN USER @@ -1272,17 +1277,18 @@ class IO extends \CoreLibs\Basic * (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 + * @param string $query Query string + * @param int $reset reset status: + * USE_CACHE/0: normal read from cache on second run + * CLEAR_CACHE/1: read cache, clean at the end + * READ_NEW/2: read new, clean at end + * NO_CACHE/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(string $query, int $reset = 0, bool $assoc_only = false) + public function dbReturn(string $query, int $reset = self::USE_CACHE, bool $assoc_only = false) { if (!$query) { $this->error_id = 11; @@ -1445,11 +1451,18 @@ class IO extends \CoreLibs\Basic } } else { // return row, if last && reset, then unset the hole md5 array - if (!$return && ($reset == 1 || $reset == 3) && $this->cursor_ext[$md5]['pos']) { + if ( + !$return && + ($reset == self::CLEAR_CACHE || $reset == self::NO_CACHE) && + $this->cursor_ext[$md5]['pos'] + ) { // unset only the field names here of course $this->cursor_ext[$md5]['field_names'] = null; $this->cursor_ext[$md5]['pos'] = 0; - } elseif (!$return && $reset == 2 && $this->cursor_ext[$md5]['pos']) { + } elseif ( + !$return && $reset == self::READ_NEW && + $this->cursor_ext[$md5]['pos'] + ) { // at end of read reset pos & set cursor to 1 (so it does not get lost in session transfer) $this->cursor_ext[$md5]['pos'] = 0; $this->cursor_ext[$md5]['cursor'] = 1; @@ -1461,7 +1474,7 @@ class IO extends \CoreLibs\Basic $this->cursor_ext[$md5]['pos'] ++; $this->cursor_ext[$md5]['read_rows'] ++; // if reset is <3 caching is done, else no - if ($reset < 3) { + if ($reset < self::NO_CACHE) { $temp = []; foreach ($return as $field_name => $data) { $temp[$field_name] = $data; diff --git a/www/lib/CoreLibs/Debug/Logging.php b/www/lib/CoreLibs/Debug/Logging.php index f95aa8ad..b11c0c4d 100644 --- a/www/lib/CoreLibs/Debug/Logging.php +++ b/www/lib/CoreLibs/Debug/Logging.php @@ -24,8 +24,16 @@ declare(strict_types=1); namespace CoreLibs\Debug; +use CoreLibs\Debug\Support; +use CoreLibs\Create\Hash; +use CoreLibs\Get\System; +use CoreLibs\Convert\Html; + class Logging { + // options + /** @var array */ + private $options = []; // page and host name /** @var string */ private $page_name; @@ -66,12 +74,16 @@ class Logging private $log_folder = ''; /** @var string */ private $log_file_name_ext = 'log'; // use this for date rotate + /** @var string */ + private $log_file_name = ''; /** @var int */ private $log_max_filesize = 0; // set in kilobytes /** @var string */ private $log_print_file = 'error_msg##LOGID####LEVEL####CLASS####PAGENAME####DATE##'; /** @var string */ private $log_file_unique_id; // a unique ID set only once for call derived from this class + /** @var string */ + private $log_file_date = ''; // Y-m-d file in file name /** @var bool */ private $log_print_file_date = true; // if set add Y-m-d and do automatic daily rotation /** @var string */ @@ -88,30 +100,82 @@ class Logging /** @var float */ private $script_starttime; - public function __construct() + /** + * Init logger + * + * global vars that can be used + * - BASE + * - LOG + * - LOG_FILE_ID + * options array layout + * - log_folder: + * - print_file_date: + * - file_id: + * - unique_id: + * - log_per_level: + * - log_per_class: + * - log_per_page: + * - log_per_run: + * - debug_all: + * - echo_all: + * - print_all: + * - debug (array): + * - echo (array): + * - print (array): + * - debug_not (array): + * - echo_not (array): + * - print_not (array): + * + * @param array $options Array with settings options + */ + public function __construct(array $options = []) { - // check must set constants - if (defined('BASE') && defined('LOG')) { + // copy the options over + $this->options = $options; + // set log folder from options + $this->log_folder = $this->options['log_folder'] ?? ''; + // legacy flow, check must set constants + if (empty($this->log_folder) && defined('BASE') && defined('LOG')) { + // make sure this is writeable, else skip $this->log_folder = BASE . LOG; - } else { - // fallback + warning - trigger_error('constant BASE or LOG are not defined, fallback to getcwd()', E_USER_WARNING); - $this->log_folder = getcwd() . DS; + } + // fallback + notice + if (empty($this->log_folder)) { + /* trigger_error( + 'options or constant not set or folder not writable. fallback to: ' . getcwd(), + E_USER_NOTICE + ); */ + $this->log_folder = getcwd() . DIRECTORY_SEPARATOR; + } + // if folder is not writeable, abort + if (!is_writeable($this->log_folder)) { + trigger_error( + 'Folder: ' . $this->log_folder . ' is not writeable for logging', + E_USER_ERROR + ); + } + // check if log_folder has a trailing / + if (substr($this->log_folder, -1, 1) != DIRECTORY_SEPARATOR) { + $this->log_folder .= DIRECTORY_SEPARATOR; } // running time start for script $this->script_starttime = microtime(true); // set per run UID for logging - $this->running_uid = \CoreLibs\Create\Hash::__uniqId(); + $this->running_uid = Hash::__uniqId(); // set the page name - $this->page_name = \CoreLibs\Get\System::getPageName(); + $this->page_name = System::getPageName(); // set host name - list($this->host_name , $this->host_port) = \CoreLibs\Get\System::getHostName(); + list($this->host_name , $this->host_port) = System::getHostName(); // add port to host name if not port 80 if ($this->host_port != 80) { $this->host_name .= ':' . $this->host_port; } - // can be overridden with basicSetLogFileId - if (isset($GLOBALS['LOG_FILE_ID'])) { + + // can be overridden with basicSetLogFileId later + if (!empty($this->options['file_id'])) { + $this->basicSetLogId($this->options['file_id'] ?? ''); + } elseif (!empty($GLOBALS['LOG_FILE_ID'])) { + // legacy flow, should be removed and only set via options $this->basicSetLogId($GLOBALS['LOG_FILE_ID']); } elseif (defined('LOG_FILE_ID')) { $this->basicSetLogId(LOG_FILE_ID); @@ -132,38 +196,90 @@ class Logging { // if given via parameters, only for all // globals overrule given settings, for one (array), eg $ECHO['db'] = 1; - if (isset($GLOBALS['DEBUG']) && is_array($GLOBALS['DEBUG'])) { + if (isset($this->options['debug']) && is_array($this->options['debug'])) { + $this->debug_output = $this->options['debug']; + } elseif (isset($GLOBALS['DEBUG']) && is_array($GLOBALS['DEBUG'])) { $this->debug_output = $GLOBALS['DEBUG']; } - if (isset($GLOBALS['ECHO']) && is_array($GLOBALS['ECHO'])) { + if (isset($this->options['echo']) && is_array($this->options['echo'])) { + $this->debug_output = $this->options['echo']; + } elseif (isset($GLOBALS['ECHO']) && is_array($GLOBALS['ECHO'])) { $this->echo_output = $GLOBALS['ECHO']; } - if (isset($GLOBALS['PRINT']) && is_array($GLOBALS['PRINT'])) { + if (isset($this->options['print']) && is_array($this->options['print'])) { + $this->debug_output = $this->options['print']; + } elseif (isset($GLOBALS['PRINT']) && is_array($GLOBALS['PRINT'])) { $this->print_output = $GLOBALS['PRINT']; } // exclude these ones from output - if (isset($GLOBALS['DEBUG_NOT']) && is_array($GLOBALS['DEBUG_NOT'])) { + if (isset($this->options['debug_not']) && is_array($this->options['debug_not'])) { + $this->debug_output = $this->options['debug_not']; + } elseif (isset($GLOBALS['DEBUG_NOT']) && is_array($GLOBALS['DEBUG_NOT'])) { $this->debug_output_not = $GLOBALS['DEBUG_NOT']; } - if (isset($GLOBALS['ECHO_NOT']) && is_array($GLOBALS['ECHO_NOT'])) { + if (isset($this->options['echo_not']) && is_array($this->options['echo_not'])) { + $this->debug_output = $this->options['echo_not']; + } elseif (isset($GLOBALS['ECHO_NOT']) && is_array($GLOBALS['ECHO_NOT'])) { $this->echo_output_not = $GLOBALS['ECHO_NOT']; } - if (isset($GLOBALS['PRINT_NOT']) && is_array($GLOBALS['PRINT_NOT'])) { + if (isset($this->options['print_not']) && is_array($this->options['print_not'])) { + $this->debug_output = $this->options['print_not']; + } elseif (isset($GLOBALS['PRINT_NOT']) && is_array($GLOBALS['PRINT_NOT'])) { $this->print_output_not = $GLOBALS['PRINT_NOT']; } // all overrule - $this->debug_output_all = $GLOBALS['DEBUG_ALL'] ?? false; - $this->echo_output_all = $GLOBALS['ECHO_ALL'] ?? false; - $this->print_output_all = $GLOBALS['PRINT_ALL'] ?? false; + $this->debug_output_all = + $this->options['debug_all'] ?? + $GLOBALS['DEBUG_ALL'] ?? + false; + $this->echo_output_all = + $this->options['echo_all'] ?? + $GLOBALS['ECHO_ALL'] ?? + false; + $this->print_output_all = + $this->options['print_all'] ?? + $GLOBALS['PRINT_ALL'] ?? + false; // GLOBAL rules for log writing - $this->log_print_file_date = $GLOBALS['LOG_PRINT_FILE_DATE'] ?? true; - $this->log_per_level = $GLOBALS['LOG_PER_LEVEL'] ?? false; - $this->log_per_class = $GLOBALS['LOG_PER_CLASS'] ?? false; - $this->log_per_page = $GLOBALS['LOG_PER_PAGE'] ?? false; - $this->log_per_run = $GLOBALS['LOG_PER_RUN'] ?? false; + $this->log_print_file_date = + $this->options['print_file_date'] ?? + $GLOBALS['LOG_PRINT_FILE_DATE'] ?? + true; + $this->log_per_level = + $this->options['per_level'] ?? + $GLOBALS['LOG_PER_LEVEL'] ?? + false; + $this->log_per_class = + $this->options['per_class'] ?? + $GLOBALS['LOG_PER_CLASS'] ?? + false; + $this->log_per_page = + $this->options['per_page'] ?? + $GLOBALS['LOG_PER_PAGE'] ?? + false; + $this->log_per_run = + $this->options['per_run'] ?? + $GLOBALS['LOG_PER_RUN'] ?? + false; + // set log per date + if ($this->log_print_file_date) { + $this->log_file_date = date('Y-m-d'); + } + // set per run ID + if ($this->log_per_run) { + /* if (isset($GLOBALS['LOG_FILE_UNIQUE_ID'])) { + $this->log_file_unique_id = $GLOBALS['LOG_FILE_UNIQUE_ID']; + } */ + if (!$this->log_file_unique_id) { + // $GLOBALS['LOG_FILE_UNIQUE_ID'] = + $this->log_file_unique_id = + date('Y-m-d_His') . '_U_' + . substr(hash('sha1', uniqid((string)mt_rand(), true)), 0, 8); + } + } } /** @@ -238,18 +354,13 @@ class Logging ) { return false; } - // replace all html tags - // $error_string = preg_replace("/(<\/?)(\w+)([^>]*>)/", "##\\2##", $error_string); - // $error_string = preg_replace("/(<\/?)(\w+)([^>]*>)/", "", $error_string); - // replace special line break tag - // $error_string = str_replace('', "\n", $error_string); // init output variable $output = $error_string; // output formated error string to output file // init base file path $fn = $this->log_folder . $this->log_print_file . '.' . $this->log_file_name_ext; // log ID prefix settings, if not valid, replace with empty - if (preg_match("/^[A-Za-z0-9]+$/", $this->log_file_id)) { + if (!empty($this->log_file_id)) { $rpl_string = '_' . $this->log_file_id; } else { $rpl_string = ''; @@ -257,17 +368,9 @@ class Logging $fn = str_replace('##LOGID##', $rpl_string, $fn); // log id (like a log file prefix) if ($this->log_per_run) { - if (isset($GLOBALS['LOG_FILE_UNIQUE_ID'])) { - $this->log_file_unique_id = $GLOBALS['LOG_FILE_UNIQUE_ID']; - } - if (!$this->log_file_unique_id) { - $GLOBALS['LOG_FILE_UNIQUE_ID'] = $this->log_file_unique_id = - date('Y-m-d_His') . '_U_' - . substr(hash('sha1', uniqid((string)mt_rand(), true)), 0, 8); - } $rpl_string = '_' . $this->log_file_unique_id; // add 8 char unique string - } else { - $rpl_string = !$this->log_print_file_date ? '' : '_' . date('Y-m-d'); // add date to file + } elseif ($this->log_print_file_date) { + $rpl_string = '_' . $this->log_file_date; // add date to file } $fn = str_replace('##DATE##', $rpl_string, $fn); // create output filename @@ -276,11 +379,13 @@ class Logging // set per class, but don't use get_class as we will only get self $rpl_string = !$this->log_per_class ? '' : '_' // set sub class settings - . str_replace('\\', '-', \CoreLibs\Debug\Support::getCallerClass()); + . str_replace('\\', '-', Support::getCallerClass()); $fn = str_replace('##CLASS##', $rpl_string, $fn); // create output filename // if request to write to one file - $rpl_string = !$this->log_per_page ? '' : '_' . \CoreLibs\Get\System::getPageName(1); + $rpl_string = !$this->log_per_page ? + '' : + '_' . System::getPageName(System::NO_EXTENSION); $fn = str_replace('##PAGENAME##', $rpl_string, $fn); // create output filename // write to file @@ -289,32 +394,30 @@ class Logging // for easy purpose, rename file only to attach timestamp, nur sequence numbering rename($fn, $fn . '.' . date("YmdHis")); } - $fp = fopen($fn, 'a'); + $this->log_file_name = $fn; + $fp = fopen($this->log_file_name, 'a'); if ($fp !== false) { fwrite($fp, $output); fclose($fp); } else { - echo ""; + echo ""; } return true; } - /** - * Superseeded by \CoreLibs\Debug\Support::getCallerClass() calls - * - * @return string Class name where called - * @deprecated Use \CoreLibs\Debug\Support::getCallerClass() insteader - */ - private function getCallerClass(): string - { - // get the last class entry and wrie that - $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); - // make sure if false it is an array and then check if not class set return empty string - return (end($backtrace) ?: [])['class'] ?? ''; - } - // *** PUBLIC *** + /** + * Temporary method to read all class variables for testing purpose + * @param string $name + * @return mixed can be anything, bool, string, int, array + */ + public function getSetting(string $name): mixed + { + // for debug purpose only + return $this->{$name}; + } + /** * sets the internal log file prefix id * string must be a alphanumeric string @@ -324,12 +427,51 @@ class Logging */ public function basicSetLogId(string $string): string { - if (preg_match("/^\w+$/", $string)) { + if (preg_match("/^[\w\-]+$/", $string)) { $this->log_file_id = $string; } return $this->log_file_id; } + /** + * return current set log file id + * @return string + */ + public function getLogId(): string + { + return $this->log_file_id; + } + + /** + * old name for setLogLevel + * @param string $type debug, echo, print + * @param string $flag on/off + * array $array of levels to turn on/off debug + * @return bool Return false if type or flag is invalid + */ + public function debugFor(string $type, string $flag): bool + { + /** @phan-suppress-next-line PhanTypeMismatchArgumentReal, PhanParamTooFew @phpstan-ignore-next-line */ + return $this->setLogLevel(...[func_get_args()]); + } + + /** + * set log level settings for All types + * if invalid type, skip + * @param string $type Type to get: debug, echo, print + * @param bool $set True or False + * @return bool Return false if type invalid + */ + public function setLogLevelAll(string $type, bool $set): bool + { + // skip set if not valid + if (!in_array($type, ['debug', 'echo', 'print'])) { + return false; + } + $this->{$type . '_output_all'} = $set; + return true; + } + /** * get the current log level setting for All level blocks * @param string $type Type to get: debug, echo, print @@ -344,35 +486,6 @@ class Logging return $this->{$type . '_output_all'}; } - /** - * set log level settings for All types - * if invalid type, skip - * @param string $type Type to get: debug, echo, print - * @param bool $set True or False - * @return void No return - */ - public function setLogLevelAll(string $type, bool $set): void - { - // skip set if not valid - if (!in_array($type, ['debug', 'echo', 'print'])) { - return; - } - $this->{$type . '_output_all'} = $set; - } - - /** - * old name for setLogLevel - * @param string $type debug, echo, print - * @param string $flag on/off - * array $array of levels to turn on/off debug - * @return void has no return - */ - public function debugFor(string $type, string $flag): void - { - /** @phan-suppress-next-line PhanTypeMismatchArgumentReal, PhanParamTooFew @phpstan-ignore-next-line */ - $this->setLogLevel(...[func_get_args()]); - } - /** * passes list of level names, to turn on debug * eg $foo->debugFor('print', 'on', ['LOG', 'DEBUG', 'INFO']); @@ -380,17 +493,17 @@ class Logging * @param string $type debug, echo, print * @param string $flag on/off * array $array of levels to turn on/off debug - * @return void has no return + * @return bool Return false if type or falg invalid */ - public function setLogLevel(string $type, string $flag): void + public function setLogLevel(string $type, string $flag): bool { // abort if not valid type if (!in_array($type, ['debug', 'echo', 'print'])) { - return; + return false; } // invalid flag type if (!in_array($flag, ['on', 'off'])) { - return; + return false; } $debug_on = func_get_args(); array_shift($debug_on); // kick out type @@ -401,6 +514,7 @@ class Logging $this->{$switch}[$level] = true; } } + return true; } /** @@ -438,14 +552,15 @@ class Logging * - run: for each run * @param string $type Type to get: level, class, page, run * @param bool $set True or False - * @return void + * @return bool Return false if type invalid */ - public function setLogPer(string $type, bool $set): void + public function setLogPer(string $type, bool $set): bool { if (!in_array($type, ['level', 'class', 'page', 'run'])) { - return; + return false; } $this->{'log_per_' . $type} = $set; + return true; } /** @@ -493,16 +608,16 @@ class Logging return false; } // get the last class entry and wrie that - $class = \CoreLibs\Debug\Support::getCallerClass(); + $class = Support::getCallerClass(); // get timestamp - $timestamp = \CoreLibs\Debug\Support::printTime(); + $timestamp = Support::printTime(); // same string put for print (no html data inside) // write to file if set $this->writeErrorMsg( $level, '[' . $timestamp . '] ' . '[' . $this->host_name . '] ' - . '[' . \CoreLibs\Get\System::getPageName(2) . '] ' + . '[' . System::getPageName(System::FULL_PATH) . '] ' . '[' . $this->running_uid . '] ' . '{' . $class . '} ' . '<' . $level . '> - ' @@ -544,7 +659,7 @@ class Logging . str_replace( ['##HTMLPRE##', '##/HTMLPRE##'], ['
', '
'], - \CoreLibs\Convert\Html::htmlent($string) + Html::htmlent($string) ) . ""; } @@ -583,7 +698,7 @@ class Logging if ($this->doDebugTrigger('echo', $level)) { $string_output .= '
' . '[' . $level . '] ' - . ($string ? "**** " . \CoreLibs\Convert\Html::htmlent($string) . " ****
\n" : "") + . ($string ? "**** " . Html::htmlent($string) . " ****
\n" : "") . '
' . join('', $temp_debug_output); } // echo it out @@ -596,7 +711,7 @@ class Logging . 'border-bottom: 1px solid black; margin: 10px 0 10px 0; ' . 'background-color: white; color: black;">' . '
{' - . \CoreLibs\Debug\Support::getCallerClass() . '}
'; + . Support::getCallerClass() . '}'; $string_output = $string_prefix . $string_output . '
Script Run Time: ' . $script_end . '
' diff --git a/www/lib/CoreLibs/Language/L10n.php b/www/lib/CoreLibs/Language/L10n.php index 300a6787..8a47b0bc 100644 --- a/www/lib/CoreLibs/Language/L10n.php +++ b/www/lib/CoreLibs/Language/L10n.php @@ -49,7 +49,6 @@ class L10n */ public function __construct(string $lang = '', string $path = '') { - // parent::__construct(); if (!$lang) { $this->lang = 'en'; } else { diff --git a/www/lib/CoreLibs/Output/Form/Generate.php b/www/lib/CoreLibs/Output/Form/Generate.php index fd129a6c..147c749a 100644 --- a/www/lib/CoreLibs/Output/Form/Generate.php +++ b/www/lib/CoreLibs/Output/Form/Generate.php @@ -218,6 +218,8 @@ declare(strict_types=1); namespace CoreLibs\Output\Form; +use CoreLibs\Get\System; + class Generate extends \CoreLibs\DB\Extended\ArrayIO { // for the load statetment describes which elements from @@ -251,6 +253,8 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO public $my_page_name; // the name of the page without .php extension /** @var bool */ public $mobile_phone = false; + /** @var string */ + public $email_regex; // buttons and checkboxes /** @var string */ public $archive; @@ -294,14 +298,16 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO /** * construct form generator * @param array $db_config db config array - * @param int|integer $table_width table/div width (default 750) + * @param \CoreLibs\Debug\Logging|null $log Logging class */ - public function __construct(array $db_config, int $table_width = 750) - { + public function __construct( + array $db_config, + \CoreLibs\Debug\Logging $log = null + ) { global $table_arrays; // replace any non valid variable names - // TODO extracft only alphanumeric and _ after . to _ replacement - $this->my_page_name = str_replace(['.'], '_', \CoreLibs\Get\System::getPageName(1)); + // TODO extract only alphanumeric and _ after . to _ replacement + $this->my_page_name = str_replace(['.'], '_', System::getPageName(System::NO_EXTENSION)); $this->setLangEncoding(); // init the language class $this->l = new \CoreLibs\Language\L10n($this->lang); @@ -312,13 +318,13 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO if ( /* isset($GLOBALS['table_arrays']) && is_array($GLOBALS['table_arrays']) && - isset($GLOBALS['table_arrays'][\CoreLibs\Get\System::getPageName(1)]) && - is_array($GLOBALS['table_arrays'][\CoreLibs\Get\System::getPageName(1)]) */ - isset($table_arrays[\CoreLibs\Get\System::getPageName(1)]) && - is_array($table_arrays[\CoreLibs\Get\System::getPageName(1)]) + isset($GLOBALS['table_arrays'][System::getPageName(System::NO_EXTENSION)]) && + is_array($GLOBALS['table_arrays'][System::getPageName(System::NO_EXTENSION)]) */ + isset($table_arrays[System::getPageName(System::NO_EXTENSION)]) && + is_array($table_arrays[System::getPageName(System::NO_EXTENSION)]) ) { - // $config_array = $GLOBALS['table_arrays'][\CoreLibs\Get\System::getPageName(1)]; - $config_array = $table_arrays[\CoreLibs\Get\System::getPageName(1)]; + // $config_array = $GLOBALS['table_arrays'][System::getPageName(1)]; + $config_array = $table_arrays[System::getPageName(1)]; } else { // WARNING: auto spl load does not work with this as it is an array and not a function/object // check if this is the old path or the new path @@ -346,9 +352,17 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO ]; } } - + // don't log per class + if ($log !== null) { + $log->setLogPer('class', false); + } // start the array_io class which will start db_io ... - parent::__construct($db_config, $config_array['table_array'], $config_array['table_name']); + parent::__construct( + $db_config, + $config_array['table_array'], + $config_array['table_name'], + $log ?? new \CoreLibs\Debug\Logging() + ); // here should be a check if the config_array is correct ... if (isset($config_array['show_fields']) && is_array($config_array['show_fields'])) { $this->field_array = $config_array['show_fields']; @@ -371,9 +385,6 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO } } - // layout - $this->table_width = $table_width; - // set button vars $this->archive = $_POST['archive'] ?? ''; $this->new = $_POST['new'] ?? ''; @@ -411,6 +422,9 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO 'delete' => 100 ]; } + + // set email regex + $this->email_regex = \CoreLibs\Check\Email::getEmailRegex(); } /** diff --git a/www/lib/CoreLibs/Output/Form/Token.php b/www/lib/CoreLibs/Output/Form/Token.php index 923a0cad..2e79743b 100644 --- a/www/lib/CoreLibs/Output/Form/Token.php +++ b/www/lib/CoreLibs/Output/Form/Token.php @@ -2,6 +2,7 @@ /* * sets a form token in the _SESSION variable + * session must be started for this to work */ declare(strict_types=1); diff --git a/www/vendor/composer/autoload_classmap.php b/www/vendor/composer/autoload_classmap.php index 52545be2..60832c79 100644 --- a/www/vendor/composer/autoload_classmap.php +++ b/www/vendor/composer/autoload_classmap.php @@ -26,6 +26,7 @@ return array( 'CoreLibs\\Convert\\MimeAppName' => $baseDir . '/lib/CoreLibs/Convert/MimeAppName.php', 'CoreLibs\\Create\\Hash' => $baseDir . '/lib/CoreLibs/Create/Hash.php', 'CoreLibs\\Create\\RandomKey' => $baseDir . '/lib/CoreLibs/Create/RandomKey.php', + 'CoreLibs\\Create\\Session' => $baseDir . '/lib/CoreLibs/Create/Session.php', 'CoreLibs\\Create\\Uids' => $baseDir . '/lib/CoreLibs/Create/Uids.php', 'CoreLibs\\DB\\Extended\\ArrayIO' => $baseDir . '/lib/CoreLibs/DB/Extended/ArrayIO.php', 'CoreLibs\\DB\\IO' => $baseDir . '/lib/CoreLibs/DB/IO.php', diff --git a/www/vendor/composer/autoload_static.php b/www/vendor/composer/autoload_static.php index 1f79a8dc..2cd09afe 100644 --- a/www/vendor/composer/autoload_static.php +++ b/www/vendor/composer/autoload_static.php @@ -91,6 +91,7 @@ class ComposerStaticInit10fe8fe2ec4017b8644d2b64bcf398b9 'CoreLibs\\Convert\\MimeAppName' => __DIR__ . '/../..' . '/lib/CoreLibs/Convert/MimeAppName.php', 'CoreLibs\\Create\\Hash' => __DIR__ . '/../..' . '/lib/CoreLibs/Create/Hash.php', 'CoreLibs\\Create\\RandomKey' => __DIR__ . '/../..' . '/lib/CoreLibs/Create/RandomKey.php', + 'CoreLibs\\Create\\Session' => __DIR__ . '/../..' . '/lib/CoreLibs/Create/Session.php', 'CoreLibs\\Create\\Uids' => __DIR__ . '/../..' . '/lib/CoreLibs/Create/Uids.php', 'CoreLibs\\DB\\Extended\\ArrayIO' => __DIR__ . '/../..' . '/lib/CoreLibs/DB/Extended/ArrayIO.php', 'CoreLibs\\DB\\IO' => __DIR__ . '/../..' . '/lib/CoreLibs/DB/IO.php',