From 75c4c98de8426e64a3edb19eb90bf2652e410c61 Mon Sep 17 00:00:00 2001 From: Clemens Schwaighofer Date: Wed, 31 May 2023 15:58:06 +0900 Subject: [PATCH] Convert all classes to strict variable types All variable declarations in all classes have a strict type set Exception: constants (will be setable from PHP 8.3 on), resources (no type) Debug\LoggingLegacy is kept as is, will be deprecated --- 4dev/tests/Create/CoreLibsCreateUidsTest.php | 81 +++++++--- .../Logging/CoreLibsLoggingLoggingTest.php | 8 +- www/admin/class_test.hash.php | 9 +- www/admin/class_test.image.php | 2 +- www/admin/class_test.logging.php | 24 ++- www/admin/class_test.php | 95 ++++++------ www/admin/class_test.uids.php | 7 +- www/lib/CoreLibs/ACL/Login.php | 94 ++++++------ www/lib/CoreLibs/Admin/Backend.php | 70 ++++----- www/lib/CoreLibs/Admin/EditBase.php | 16 +- www/lib/CoreLibs/Basic.php | 18 +-- www/lib/CoreLibs/Check/Email.php | 8 +- www/lib/CoreLibs/Check/Encoding.php | 2 +- www/lib/CoreLibs/Convert/MimeAppName.php | 2 +- www/lib/CoreLibs/Create/Email.php | 4 +- www/lib/CoreLibs/Create/Hash.php | 15 +- www/lib/CoreLibs/Create/RandomKey.php | 12 +- www/lib/CoreLibs/Create/Session.php | 2 +- www/lib/CoreLibs/Create/Uids.php | 109 ++++++++++---- www/lib/CoreLibs/DB/Extended/ArrayIO.php | 10 +- www/lib/CoreLibs/DB/IO.php | 133 +++++++++-------- www/lib/CoreLibs/DB/SQL/PgSQL.php | 4 +- www/lib/CoreLibs/Debug/FileWriter.php | 4 +- www/lib/CoreLibs/Debug/MemoryUsage.php | 8 +- www/lib/CoreLibs/Debug/RunningTime.php | 18 +-- www/lib/CoreLibs/Debug/Support.php | 27 +++- www/lib/CoreLibs/Get/System.php | 9 +- .../Language/Core/CachedFileReader.php | 4 +- www/lib/CoreLibs/Language/Core/FileReader.php | 8 +- .../CoreLibs/Language/Core/GetTextReader.php | 24 +-- .../CoreLibs/Language/Core/StringReader.php | 4 +- www/lib/CoreLibs/Language/L10n.php | 37 +++-- www/lib/CoreLibs/Logging/Logging.php | 59 +++++--- www/lib/CoreLibs/Output/Form/Generate.php | 70 ++++----- .../Output/Form/TableArrays/EditAccess.php | 2 +- .../Output/Form/TableArrays/EditGroups.php | 2 +- .../Output/Form/TableArrays/EditLanguages.php | 2 +- .../Output/Form/TableArrays/EditMenuGroup.php | 2 +- .../Output/Form/TableArrays/EditPages.php | 2 +- .../Output/Form/TableArrays/EditSchemas.php | 2 +- .../Output/Form/TableArrays/EditUsers.php | 2 +- .../Form/TableArrays/EditVisibleGroup.php | 2 +- www/lib/CoreLibs/Output/ProgressBar.php | 44 +++--- .../CoreLibs/Security/SymmetricEncryption.php | 4 +- www/lib/CoreLibs/Template/SmartyExtend.php | 138 +++++++++--------- 45 files changed, 685 insertions(+), 514 deletions(-) diff --git a/4dev/tests/Create/CoreLibsCreateUidsTest.php b/4dev/tests/Create/CoreLibsCreateUidsTest.php index a914cb93..3612ee89 100644 --- a/4dev/tests/Create/CoreLibsCreateUidsTest.php +++ b/4dev/tests/Create/CoreLibsCreateUidsTest.php @@ -21,45 +21,83 @@ final class CoreLibsCreateUidsTest extends TestCase public function uniqIdProvider(): array { return [ + // number length + 'too short' => [ + 0 => 1, + 1 => 4, + 2 => null + ], + 'valid length: 10' => [ + 0 => 10, + 1 => 10, + 2 => null + ], + 'valid length: 9, auto length' => [ + 0 => 9, + 1 => 8, + 2 => null + ], + 'valid length: 9, force length' => [ + 0 => 9, + 1 => 9, + 2 => true, + ], + 'very long: 512' => [ + 0 => 512, + 1 => 512, + 2 => null + ], + // below is all legacy 'md5 hash' => [ 0 => 'md5', 1 => 32, + 2 => null ], 'sha256 hash' => [ 0 => 'sha256', - 1 => 64 + 1 => 64, + 2 => null ], 'ripemd160 hash' => [ 0 => 'ripemd160', - 1 => 40 + 1 => 40, + 2 => null ], 'adler32 hash' => [ 0 => 'adler32', - 1 => 8 + 1 => 8, + 2 => null ], - 'not in list hash but valid' => [ + 'not in list, set default length' => [ 0 => 'sha3-512', - 1 => strlen(hash('sha3-512', 'A')) + 1 => 64, + 2 => null ], 'default hash not set' => [ 0 => null, 1 => 64, + 2 => null ], 'invalid name' => [ 0 => 'iamnotavalidhash', 1 => 64, + 2 => null ], - 'auto: ' . \CoreLibs\Create\Uids::DEFAULT_HASH => [ - 0 => \CoreLibs\Create\Uids::DEFAULT_HASH, - 1 => strlen(hash(\CoreLibs\Create\Uids::DEFAULT_HASH, 'A')) + // auto calls + 'auto: ' . \CoreLibs\Create\Uids::DEFAULT_UNNIQ_ID_LENGTH => [ + 0 => \CoreLibs\Create\Uids::DEFAULT_UNNIQ_ID_LENGTH, + 1 => 64, + 2 => null ], 'auto: ' . \CoreLibs\Create\Uids::STANDARD_HASH_LONG => [ 0 => \CoreLibs\Create\Uids::STANDARD_HASH_LONG, - 1 => strlen(hash(\CoreLibs\Create\Uids::STANDARD_HASH_LONG, 'A')) + 1 => strlen(hash(\CoreLibs\Create\Uids::STANDARD_HASH_LONG, 'A')), + 2 => null ], 'auto: ' . \CoreLibs\Create\Uids::STANDARD_HASH_SHORT => [ 0 => \CoreLibs\Create\Uids::STANDARD_HASH_SHORT, - 1 => strlen(hash(\CoreLibs\Create\Uids::STANDARD_HASH_SHORT, 'A')) + 1 => strlen(hash(\CoreLibs\Create\Uids::STANDARD_HASH_SHORT, 'A')), + 2 => null ], ]; } @@ -105,25 +143,26 @@ final class CoreLibsCreateUidsTest extends TestCase * * @covers ::uniqId * @dataProvider uniqIdProvider - * @testdox uniqId $input will be length $expected [$_dataName] + * @testdox uniqId $input will be length $expected (Force $flag) [$_dataName] * - * @param string|null $input + * @param int|string|null $input * @param string $expected + * @param bool|null $flag * @return void */ - public function testUniqId(?string $input, int $expected): void + public function testUniqId(int|string|null $input, int $expected, ?bool $flag): void { if ($input === null) { - $this->assertEquals( - $expected, - strlen(\CoreLibs\Create\Uids::uniqId()) - ); + $uniq_id_length = strlen(\CoreLibs\Create\Uids::uniqId()); + } elseif ($flag === null) { + $uniq_id_length = strlen(\CoreLibs\Create\Uids::uniqId($input)); } else { - $this->assertEquals( - $expected, - strlen(\CoreLibs\Create\Uids::uniqId($input)) - ); + $uniq_id_length = strlen(\CoreLibs\Create\Uids::uniqId($input, $flag)); } + $this->assertEquals( + $expected, + $uniq_id_length + ); } /** diff --git a/4dev/tests/Logging/CoreLibsLoggingLoggingTest.php b/4dev/tests/Logging/CoreLibsLoggingLoggingTest.php index 9851722a..2b421802 100644 --- a/4dev/tests/Logging/CoreLibsLoggingLoggingTest.php +++ b/4dev/tests/Logging/CoreLibsLoggingLoggingTest.php @@ -92,15 +92,15 @@ final class CoreLibsLoggingLoggingTest extends TestCase 'override' => [], ], // no log file id set -> error, - /* 'nothing set' => [ + 'nothing set' => [ 'options' => [], 'expected' => [ 'log_folder' => getcwd() . DIRECTORY_SEPARATOR, 'log_level' => Level::Debug, - 'log_file_id' => 'NOHOST-NOPORT_PHPUnit-TextUI-Command', + 'log_file_id' => 'NOHOST-0_PHPUnit-TextUI-Command', ], 'override' => [] - ] */ + ] ]; } @@ -674,7 +674,7 @@ final class CoreLibsLoggingLoggingTest extends TestCase $log->getLogFolder() . $log->getLogFile() ) ?: ''; $log_level = $log->getLoggingLevel()->getName(); - // [2023-05-30 15:51:39.36128800] [NOHOST:NOPORT] + // [2023-05-30 15:51:39.36128800] [NOHOST:0] // [www/vendor/bin/phpunit] [7b9d0747] {PHPUnit\TextUI\Command} // D $this->assertMatchesRegularExpression( diff --git a/www/admin/class_test.hash.php b/www/admin/class_test.hash.php index 0c2d6aeb..0392ae09 100644 --- a/www/admin/class_test.hash.php +++ b/www/admin/class_test.hash.php @@ -43,12 +43,19 @@ print "S::__SHA1SHORT(off): $to_crc: " . $hash_class::__sha1short($to_crc) . ""; print "S::__hash(d): " . $to_crc . "/" . Hash::STANDARD_HASH_SHORT . ": " . $hash_class::__hash($to_crc) . "
"; -foreach (['adler32', 'fnv132', 'fnv1a32', 'joaat'] as $__hash_c) { +foreach (['adler32', 'fnv132', 'fnv1a32', 'joaat', 'sha512'] as $__hash_c) { print "S::__hash($__hash_c): $to_crc: " . $hash_class::__hash($to_crc, $__hash_c) . "
"; } // static use print "U-S::__CRC32B: $to_crc: " . Hash::__crc32b($to_crc) . "
"; +echo "
"; +$text = 'Some String Text'; +$type = 'crc32b'; +print "Hash: " . $type . ": " . hash($type, $text) . "
"; +print "Class: " . $type . ": " . Hash::__hash($text, $type) . "
"; + +echo "
"; print "
CURRENT STANDARD_HASH_SHORT: " . Hash::STANDARD_HASH_SHORT . "
"; print "
CURRENT STANDARD_HASH_LONG: " . Hash::STANDARD_HASH_LONG . "
"; print "HASH SHORT: " . $to_crc . ": " . Hash::__hash($to_crc) . "
"; diff --git a/www/admin/class_test.image.php b/www/admin/class_test.image.php index a773a5f5..cabc8814 100644 --- a/www/admin/class_test.image.php +++ b/www/admin/class_test.image.php @@ -85,7 +85,7 @@ foreach ($images as $image) { $image = BASE . LAYOUT . CONTENT_PATH . IMAGES . $image; list ($height, $width, $img_type) = \CoreLibs\Convert\SetVarType::setArray(getimagesize($image)); echo "
IMAGE INFO: " . $height . "x" . $width . ", TYPE: " - . \CoreLibs\Debug\Support::printArray($img_type) . " [" . $finfo->file($image) . "]
"; + . \CoreLibs\Debug\Support::dumpVar($img_type) . " [" . $finfo->file($image) . "]"; // rotate image first Image::correctImageOrientation($image); // thumbnail tests diff --git a/www/admin/class_test.logging.php b/www/admin/class_test.logging.php index 87f25ac9..7ac13765 100644 --- a/www/admin/class_test.logging.php +++ b/www/admin/class_test.logging.php @@ -1,4 +1,4 @@ -getName() . "
"; print "Flag: per_run getName(): " . Flag::per_class->getName() . "
"; print "Flag: per_run ->name: " . Flag::per_class->name . "
"; print "Flag: per_run ->value: " . Flag::per_class->value . "
"; +$log->setLogUniqueId(); +print "LogUniqId: " . $log->getLogUniqueId() . "
"; print "DUMP: " . $log->dV(['something' => 'error']) . "
"; @@ -82,6 +84,26 @@ try { 'log_file_id' => 'a', ]); */ +// @codingStandardsIgnoreLine +Class TestP +{ + /** @var \CoreLibs\Logging\Logging */ + public $log; + public function __construct( + \CoreLibs\Logging\Logging $log + ) { + $this->log = $log; + } + + public function test(): void + { + $this->log->info('TestL::test call'); + } +} + +$tl = new TestP($log); +$tl->test(); + print '
' . '
' // . '
'
diff --git a/www/admin/class_test.php b/www/admin/class_test.php
index cd3f45e3..8f0e58aa 100644
--- a/www/admin/class_test.php
+++ b/www/admin/class_test.php
@@ -66,49 +66,58 @@ print "";
 print "TEST CLASS";
 print "";
 
-print '';
-print '';
-print '';
-print '';
-print '';
-print '';
-print '';
-print '';
-print '';
-print '';
-print '';
-print '';
-print '';
-print '';
-print '';
-print '';
-print '';
-print '';
-print '';
-print '';
-print '';
-print '';
-print '';
-print '';
-print '';
-print '';
-print '';
-print '';
-print '';
-print '';
-print '';
-print '';
-print '';
-print '';
-print '';
-print '';
-print '';
-print '';
-print '';
-print '';
-print '';
-print '';
-print '';
+// key: file name, value; name
+$test_files = [
+	'class_test.db.php' => 'Class Test: DB',
+	'class_test.db.single.php' => 'Class Test: DB SINGLE',
+	'class_test.db.dbReturn.php' => 'Class Test: DB dbReturn',
+	'class_test.convert.colors.php' => 'Class Test: CONVERT COLORS',
+	'class_test.check.colors.php' => 'Class Test: CHECK COLORS',
+	'class_test.mime.php' => 'Class Test: MIME',
+	'class_test.json.php' => 'Class Test: JSON',
+	'class_test.token.php' => 'Class Test: FORM TOKEN',
+	'class_test.password.php' => 'Class Test: PASSWORD',
+	'class_test.encryption.php' => 'Class Test: ENCRYPTION',
+	'class_test.math.php' => 'Class Test: MATH',
+	'class_test.html.php' => 'Class Test: HTML/ELEMENTS',
+	'class_test.email.php' => 'Class Test: EMAIL',
+	'class_test.create_email.php' => 'Class Test: CREATE EMAIL',
+	'class_test.uids.php' => 'Class Test: UIDS',
+	'class_test.phpv.php' => 'Class Test: PHP VERSION',
+	'class_test.hash.php' => 'Class Test: HASH',
+	'class_test.encoding.php' => 'Class Test: ENCODING (CHECK/CONVERT/MIME)',
+	'class_test.image.php' => 'Class Test: IMAGE',
+	'class_test.byte.php' => 'Class Test: BYTE CONVERT',
+	'class_test.strings.php' => 'Class Test: STRING CONVERT',
+	'class_test.datetime.php' => 'Class Test: DATE/TIME',
+	'class_test.array.php' => 'Class Test: ARRAY HANDLER',
+	'class_test.file.php' => 'Class Test: FILE',
+	'class_test.randomkey.php' => 'Class Test: RANDOM KEY',
+	'class_test.system.php' => 'Class Test: SYSTEM',
+	'class_test.readenvfile.php' => 'Class Test: READ ENV FILE',
+	'class_test.runningtime.php' => 'Class Test: RUNNING TIME',
+	'class_test.memoryusage.php' => 'Class Test: MEMORY USAGE',
+	'class_test.debug.php' => 'Class Test: DEBUG',
+	'class_test.logging.php' => 'Class Test: LOGGING',
+	'class_test.output.form.php' => 'Class Test: OUTPUT FORM',
+	'class_test.admin.backend.php' => 'Class Test: BACKEND ADMIN CLASS',
+	'class_test.lang.php' => 'Class Test: LANG/L10n',
+	'class_test.varistype.php' => 'Class Test: SET VAR TYPE',
+	'class_test.session.php' => 'Class Test: SESSION',
+	'class_test.session.read.php' => 'Class Test: SESSION: READ',
+	'class_test.smarty.php' => 'Class Test: SMARTY',
+	'class_test.login.php' => 'Class Test: LOGIN',
+	'class_test.autoloader.php' => 'Class Test: AUTOLOADER',
+	'class_test.config.link.php' => 'Class Test: CONFIG LINK',
+	'class_test.config.direct.php' => 'Class Test: CONFIG DIRECT',
+	'subfolder/class_test.config.direct.php' => 'Class Test: CONFIG DIRECT SUB',
+];
+
+asort($test_files);
+
+foreach ($test_files as $file => $name) {
+	print '';
+}
 
 print "
"; print "L: " . Support::dumpVar($locale) . "
"; diff --git a/www/admin/class_test.uids.php b/www/admin/class_test.uids.php index 9aef4bdf..715f6df5 100644 --- a/www/admin/class_test.uids.php +++ b/www/admin/class_test.uids.php @@ -39,11 +39,16 @@ print "UUIDV4: " . $_uids->uuidv4() . "
"; print "UNIQID (d): " . $_uids->uniqId() . "
"; print "UNIQID (md5): " . $_uids->uniqId('md5') . "
"; print "UNIQID (sha256): " . $_uids->uniqId('sha256') . "
"; -// statc +// static print "S::UUIDV4: " . $uids_class::uuidv4() . "
"; print "S::UNIQID (d): " . $uids_class::uniqId() . "
"; print "S::UNIQID (md5): " . $uids_class::uniqId('md5') . "
"; print "S::UNIQID (sha256): " . $uids_class::uniqId('sha256') . "
"; +// with direct length +print "S:UNIQID (0->4): " . Uids::uniqId(0) . "
"; +print "S:UNIQID (9->8): " . Uids::uniqId(9) . "
"; +print "S:UNIQID (9,true): " . Uids::uniqId(9, true) . "
"; +print "S:UNIQID (512): " . Uids::uniqId(512) . "
"; // uniq ids print "UNIQU ID SHORT : " . Uids::uniqIdShort() . "
"; print "UNIQU ID LONG : " . Uids::uniqIdLong() . "
"; diff --git a/www/lib/CoreLibs/ACL/Login.php b/www/lib/CoreLibs/ACL/Login.php index 66fec3da..a3681bf8 100644 --- a/www/lib/CoreLibs/ACL/Login.php +++ b/www/lib/CoreLibs/ACL/Login.php @@ -73,65 +73,65 @@ use CoreLibs\Convert\Json; class Login { - /** @var string the user id var*/ - private $euid; + /** @var ?int the user id var*/ + private ?int $euid; /** @var string _GET/_POST loginUserId parameter for non password login */ - private $login_user_id = ''; + private string $login_user_id = ''; /** @var string source, either _GET or _POST or empty */ - private $login_user_id_source = ''; + private string $login_user_id_source = ''; /** @var bool set to true if illegal characters where found in the login user id string */ - private $login_user_id_unclear = false; + private bool $login_user_id_unclear = false; // is set to one if login okay, or EUID is set and user is okay to access this page /** @var bool */ - private $permission_okay = false; + private bool $permission_okay = false; /** @var string pressed login */ - private $login = ''; + private string $login = ''; /** @var string master action command */ - private $action; + private string $action; /** @var string login name */ - private $username; + private string $username; /** @var string login password */ - private $password; + private string $password; /** @var string logout button */ - private $logout; + private string $logout; /** @var bool if this is set to true, the user can change passwords */ - private $password_change = false; + private bool $password_change = false; /** @var bool password change was successful */ - private $password_change_ok = false; + private bool $password_change_ok = false; // can we reset password and mail to user with new password set screen /** @var bool */ - private $password_forgot = false; + private bool $password_forgot = false; /** @var bool password forgot mail send ok */ // private $password_forgot_ok = false; /** @var string */ - private $change_password; + private string $change_password; /** @var string */ - private $pw_username; + private string $pw_username; /** @var string */ - private $pw_old_password; + private string $pw_old_password; /** @var string */ - private $pw_new_password; + private string $pw_new_password; /** @var string */ - private $pw_new_password_confirm; + private string $pw_new_password_confirm; /** @var array array of users for which the password change is forbidden */ - private $pw_change_deny_users = []; + private array $pw_change_deny_users = []; /** @var string */ - private $logout_target = ''; + private string $logout_target = ''; /** @var int */ - private $max_login_error_count = -1; + private int $max_login_error_count = -1; /** @var array */ - private $lock_deny_users = []; + private array $lock_deny_users = []; /** @var string */ - private $page_name = ''; + private string $page_name = ''; /** @var int if we have password change we need to define some rules */ - private $password_min_length = 9; + private int $password_min_length = 9; /** @var int an true maxium min, can never be set below this */ - private $password_min_length_max = 9; + private int $password_min_length_max = 9; // max length is fixed as 255 (for input type max), if set highter // it will be set back to 255 /** @var int */ - private $password_max_length = 255; + private int $password_max_length = 255; /** @var int minum password length */ public const PASSWORD_MIN_LENGTH = 9; @@ -158,7 +158,7 @@ class Login . "$/"; /** @var array can have several regexes, if nothing set, all is ok */ - private $password_valid_chars = [ + private array $password_valid_chars = [ // '^(?=.*\d)(?=.*[A-Za-z])[0-9A-Za-z!@#$%]{8,}$', // '^(?.*(\pL)u)(?=.*(\pN)u)(?=.*([^\pL\pN])u).{8,}', ]; @@ -166,13 +166,13 @@ class Login // login error code, can be matched to the array login_error_msg, // which holds the string /** @var int */ - private $login_error = 0; + private int $login_error = 0; /** @var array all possible login error conditions */ - private $login_error_msg = []; + private array $login_error_msg = []; // this is an array holding all strings & templates passed // rom the outside (translation) /** @var array */ - private $login_template = [ + private array $login_template = [ 'strings' => [], 'password_change' => '', 'template' => '' @@ -180,24 +180,24 @@ class Login // acl vars /** @var array */ - private $acl = []; + private array $acl = []; /** @var array */ - private $default_acl_list = []; + private array $default_acl_list = []; /** @var array Reverse list to lookup level from type */ - private $default_acl_list_type = []; + private array $default_acl_list_type = []; /** @var int default ACL level to be based on if nothing set */ - private $default_acl_level = 0; + private int $default_acl_level = 0; // login html, if we are on an ajax page /** @var string|null */ - private $login_html = ''; + private ?string $login_html = ''; /** @var bool */ - private $login_is_ajax_page = false; + private bool $login_is_ajax_page = false; // settings /** @var array options */ - private $options = []; + private array $options = []; /** @var array locale options: locale, domain, encoding (opt), path */ - private $locale = [ + private array $locale = [ 'locale' => '', 'domain' => '', 'encoding' => '', @@ -205,13 +205,13 @@ class Login ]; /** @var \CoreLibs\Logging\Logging logger */ - public $log; + public \CoreLibs\Logging\Logging $log; /** @var \CoreLibs\DB\IO database */ - public $db; + public \CoreLibs\DB\IO $db; /** @var \CoreLibs\Language\L10n language */ - public $l; + public \CoreLibs\Language\L10n $l; /** @var \CoreLibs\Create\Session session class */ - public $session; + public \CoreLibs\Create\Session $session; /** * constructor, does ALL, opens db, works through connection checks, @@ -883,7 +883,7 @@ class Login } // normal user processing // set class var and session var - $_SESSION['EUID'] = $this->euid = $res['edit_user_id']; + $_SESSION['EUID'] = $this->euid = (int)$res['edit_user_id']; // check if user is okay $this->loginCheckPermissions(); if ($this->login_error == 0) { @@ -1048,7 +1048,7 @@ class Login } // build master unit array $unit_access[$res['edit_access_id']] = [ - 'id' => $res['edit_access_id'], + 'id' => (int)$res['edit_access_id'], 'acl_level' => $res['level'], 'acl_type' => $res['type'], 'name' => $res['name'], @@ -2110,7 +2110,7 @@ HTML; // unset session vars set/used in this login $this->session->sessionDestroy(); // unset euid - $this->euid = ''; + $this->euid = null; // then prints the login screen again $this->permission_okay = false; } @@ -2498,7 +2498,7 @@ HTML; */ public function loginGetEuid(): string { - return $this->euid; + return (string)$this->euid; } } diff --git a/www/lib/CoreLibs/Admin/Backend.php b/www/lib/CoreLibs/Admin/Backend.php index 09ab6a39..67f6659b 100644 --- a/www/lib/CoreLibs/Admin/Backend.php +++ b/www/lib/CoreLibs/Admin/Backend.php @@ -35,83 +35,83 @@ class Backend { // page name /** @var array */ - public $menu = []; + public array $menu = []; /** @var int|string */ - public $menu_show_flag = 0; // top menu flag (mostly string) + public int|string $menu_show_flag = 0; // top menu flag (mostly string) // action ids /** @var array */ - public $action_list = [ + public array $action_list = [ 'action', 'action_id', 'action_sub_id', 'action_yes', 'action_flag', 'action_menu', 'action_value', 'action_error', 'action_loaded' ]; /** @var string */ - public $action; + public string $action; /** @var string|int */ - public $action_id; + public string|int $action_id; /** @var string|int */ - public $action_sub_id; + public string|int $action_sub_id; /** @var string|int|bool */ - public $action_yes; + public string|int|bool $action_yes; /** @var string */ - public $action_flag; + public string $action_flag; /** @var string */ - public $action_menu; + public string $action_menu; /** @var string */ - public $action_loaded; + public string $action_loaded; /** @var string */ - public $action_value; + public string $action_value; /** @var string */ - public $action_error; + public string $action_error; // ACL array variable if we want to set acl data from outisde /** @var array */ - public $acl = []; + public array $acl = []; /** @var int */ - public $default_acl; + public int $default_acl; // queue key /** @var string */ - public $queue_key; + public string $queue_key; // the current active edit access id - /** @var int */ - public $edit_access_id; + /** @var int|null */ + public int|null $edit_access_id; /** @var string */ - public $page_name; + public string $page_name; // error/warning/info messages /** @var array */ - public $messages = []; + public array $messages = []; /** @var bool */ - public $error = false; + public bool $error = false; /** @var bool */ - public $warning = false; + public bool $warning = false; /** @var bool */ - public $info = false; + public bool $info = false; // internal lang & encoding vars /** @var string */ - public $lang_dir = ''; + public string $lang_dir = ''; /** @var string */ - public $lang; + public string $lang; /** @var string */ - public $lang_short; + public string $lang_short; /** @var string */ - public $domain; + public string $domain; /** @var string */ - public $encoding; + public string $encoding; /** @var \CoreLibs\Logging\Logging logger */ - public $log; + public \CoreLibs\Logging\Logging $log; /** @var \CoreLibs\DB\IO database */ - public $db; + public \CoreLibs\DB\IO $db; /** @var \CoreLibs\Language\L10n language */ - public $l; + public \CoreLibs\Language\L10n $l; /** @var \CoreLibs\Create\Session session class */ - public $session; + public \CoreLibs\Create\Session $session; // smarty publics [end processing in smarty class] /** @var array */ - public $DATA; + public array $DATA = []; /** @var array */ - public $HEADER; + public array $HEADER = []; /** @var array */ - public $DEBUG_DATA; + public array $DEBUG_DATA = []; /** @var array */ - public $CONTENT_DATA; + public array $CONTENT_DATA = []; // CONSTRUCTOR / DECONSTRUCTOR |====================================> /** diff --git a/www/lib/CoreLibs/Admin/EditBase.php b/www/lib/CoreLibs/Admin/EditBase.php index 6610c1df..6a18572b 100644 --- a/www/lib/CoreLibs/Admin/EditBase.php +++ b/www/lib/CoreLibs/Admin/EditBase.php @@ -20,23 +20,23 @@ use SmartyException; class EditBase { /** @var array */ - private $HEADER = []; + private array $HEADER = []; /** @var array */ - private $DATA = []; + private array $DATA = []; /** @var array */ - private $DEBUG_DATA = []; + private array $DEBUG_DATA = []; /** @var string the template name */ - private $EDIT_TEMPLATE = ''; + private string $EDIT_TEMPLATE = ''; /** @var \CoreLibs\Template\SmartyExtend smarty system */ - private $smarty; + private \CoreLibs\Template\SmartyExtend $smarty; /** @var \CoreLibs\Output\Form\Generate form generate system */ - private $form; + private \CoreLibs\Output\Form\Generate $form; /** @var \CoreLibs\Logging\Logging */ - public $log; + public \CoreLibs\Logging\Logging $log; /** @var \CoreLibs\ACL\Login */ - public $login; + public \CoreLibs\ACL\Login $login; /** * construct form generator diff --git a/www/lib/CoreLibs/Basic.php b/www/lib/CoreLibs/Basic.php index 5d291b8f..d0694868 100644 --- a/www/lib/CoreLibs/Basic.php +++ b/www/lib/CoreLibs/Basic.php @@ -58,30 +58,30 @@ class Basic { // page and host name /** @var string */ - public $page_name; + public string $page_name; /** @var string */ - public $host_name; + public string $host_name; /** @var int */ - public $host_port; + public int $host_port; // logging interface, Debug\Logging class /** @var \CoreLibs\Logging\Logging */ - public $log; + public \CoreLibs\Logging\Logging $log; /** @var \CoreLibs\Create\Session */ - public $session; + public \CoreLibs\Create\Session $session; // email valid checks /** @var array */ - public $email_regex_check = []; + public array $email_regex_check = []; /** @var string */ - public $email_regex; // regex var for email check + public string $email_regex; // regex var for email check // data path for files /** @var array */ - public $data_path = []; + public array $data_path = []; // ajax flag /** @var bool */ - protected $ajax_page_flag = false; + protected bool $ajax_page_flag = false; /** * main Basic constructor to init and check base settings diff --git a/www/lib/CoreLibs/Check/Email.php b/www/lib/CoreLibs/Check/Email.php index 8c8c8434..6e78beeb 100644 --- a/www/lib/CoreLibs/Check/Email.php +++ b/www/lib/CoreLibs/Check/Email.php @@ -8,7 +8,7 @@ class Email { // this is for error check parts in where the email regex failed /** @var array */ - private static $email_regex_check = [ + private static array $email_regex_check = [ 0 => "^[A-Za-z0-9!#$%&'*+\-\/=?^_`{|}~][A-Za-z0-9!#$%:\(\)&'*+\-\/=?^_`{|}~\.]{0,63}@" . "[a-zA-Z0-9\-]+(\.[a-zA-Z0-9\-]{1,})*\.([a-zA-Z]{2,}){1}$", // MASTER 1 => "@(.*)@(.*)", // double @ @@ -21,7 +21,7 @@ class Email ]; // for above position, description string below /** @var array */ - private static $email_regex_check_message = [ + private static array $email_regex_check_message = [ 0 => 'Invalid email address', 1 => 'Double @ mark in email address', 2 => 'Invalid email part before @ sign', @@ -33,7 +33,7 @@ class Email ]; // the array with the mobile types that are valid /** @var array */ - private static $mobile_email_type = [ + private static array $mobile_email_type = [ '.*@docomo\.ne\.jp$' => 'keitai_docomo', // correct are a[2-4], b2, c[1-9], e[2-9], h[2-4], t[1-9] '.*@([a-z0-9]{2}\.)?ezweb\.ne\.jp$' => 'keitai_kddi_ezweb', @@ -72,7 +72,7 @@ class Email ]; // short list for mobile email types /** @var array */ - private static $mobile_email_type_short = [ + private static array $mobile_email_type_short = [ 'keitai_docomo' => 'docomo', 'keitai_kddi_ezweb' => 'kddi', 'keitai_kddi' => 'kddi', diff --git a/www/lib/CoreLibs/Check/Encoding.php b/www/lib/CoreLibs/Check/Encoding.php index 782b479e..3141e432 100644 --- a/www/lib/CoreLibs/Check/Encoding.php +++ b/www/lib/CoreLibs/Check/Encoding.php @@ -11,7 +11,7 @@ namespace CoreLibs\Check; class Encoding { /** @var int|int<1, max>|string */ - private static $mb_error_char = ''; + private static int|string $mb_error_char = ''; /** * set error char diff --git a/www/lib/CoreLibs/Convert/MimeAppName.php b/www/lib/CoreLibs/Convert/MimeAppName.php index 07fc54bd..422ea4ad 100644 --- a/www/lib/CoreLibs/Convert/MimeAppName.php +++ b/www/lib/CoreLibs/Convert/MimeAppName.php @@ -12,7 +12,7 @@ namespace CoreLibs\Convert; class MimeAppName { /** @var array */ - private static $mime_apps = []; + private static array $mime_apps = []; /** * constructor: init mime list diff --git a/www/lib/CoreLibs/Create/Email.php b/www/lib/CoreLibs/Create/Email.php index 702978ad..5e0c6f72 100644 --- a/www/lib/CoreLibs/Create/Email.php +++ b/www/lib/CoreLibs/Create/Email.php @@ -14,7 +14,7 @@ namespace CoreLibs\Create; class Email { /** @var array allowed list for encodings that can do KV folding */ - private static $encoding_kv_allowed = [ + private static array $encoding_kv_allowed = [ 'UTF-8', 'EUC-JP', 'SJIS', @@ -25,7 +25,7 @@ class Email 'JIS-ms', ]; /** @var string normaly this does not need to be changed */ - private static $mb_convert_kana_mode = 'KV'; + private static string $mb_convert_kana_mode = 'KV'; /** * create mime encoded email part for to/from emails. diff --git a/www/lib/CoreLibs/Create/Hash.php b/www/lib/CoreLibs/Create/Hash.php index beadac67..bf83afeb 100644 --- a/www/lib/CoreLibs/Create/Hash.php +++ b/www/lib/CoreLibs/Create/Hash.php @@ -10,6 +10,7 @@ namespace CoreLibs\Create; class Hash { + public const DEFAULT_HASH = 'adler32'; public const STANDARD_HASH_LONG = 'ripemd160'; public const STANDARD_HASH_SHORT = 'adler32'; @@ -58,7 +59,7 @@ class Hash /** * replacemend for __crc32b call (alternate) * defaults to adler 32 - * allowed crc32b, adler32, fnv132, fnv1a32, joaat + * allowed: any in hash algos list, default to adler 32 * all that create 8 char long hashes * * @param string $string string to hash @@ -67,15 +68,15 @@ class Hash */ public static function __hash( string $string, - string $hash_type = self::STANDARD_HASH_SHORT + string $hash_type = self::DEFAULT_HASH ): string { + // if not empty, check if in valid list if ( - !in_array( - $hash_type, - ['crc32b', 'adler32', 'fnv132', 'fnv1a32', 'joaat'] - ) + empty($hash_type) || + !in_array($hash_type, hash_algos()) ) { - $hash_type = 'adler32'; + // fallback to default hash type if none set or invalid + $hash_type = self::DEFAULT_HASH; } return hash($hash_type, $string); } diff --git a/www/lib/CoreLibs/Create/RandomKey.php b/www/lib/CoreLibs/Create/RandomKey.php index 3d340799..6d57f754 100644 --- a/www/lib/CoreLibs/Create/RandomKey.php +++ b/www/lib/CoreLibs/Create/RandomKey.php @@ -12,13 +12,13 @@ class RandomKey { // key generation /** @var string */ - private static $key_range = ''; + private static string $key_range = ''; /** @var int */ - private static $one_key_length; + private static int $one_key_length; /** @var int */ - private static $key_length = 4; // default key length + private static int $key_length = 4; // default key length /** @var int */ - private static $max_key_length = 256; // max allowed length + private static int $max_key_length = 256; // max allowed length /** * if launched as class, init random key data first @@ -100,7 +100,9 @@ class RandomKey public static function randomKeyGen(int $key_length = -1): string { // init random key strings if not set - if (!is_numeric(self::$one_key_length)) { + if ( + !isset(self::$one_key_length) + ) { self::initRandomKeyData(); } $use_key_length = 0; diff --git a/www/lib/CoreLibs/Create/Session.php b/www/lib/CoreLibs/Create/Session.php index 46468cc8..f7a0f7f7 100644 --- a/www/lib/CoreLibs/Create/Session.php +++ b/www/lib/CoreLibs/Create/Session.php @@ -16,7 +16,7 @@ namespace CoreLibs\Create; class Session { /** @var string list for errors */ - private $session_intern_error_str = ''; + private string $session_intern_error_str = ''; /** * init a session, if array is empty or array does not have session_name set diff --git a/www/lib/CoreLibs/Create/Uids.php b/www/lib/CoreLibs/Create/Uids.php index a8b1bbac..47691338 100644 --- a/www/lib/CoreLibs/Create/Uids.php +++ b/www/lib/CoreLibs/Create/Uids.php @@ -1,5 +1,12 @@ 8) + * @param bool $force_length [default=false] if set to true and we have + * uneven length, then we shorten to this length + * @return string Uniq id + */ + private static function uniqIdL(int $length = 64, bool $force_length = false): string + { + $uniqid_length = ($length < 4) ? 4 : $length; + if ($force_length) { + $uniqid_length++; + } + /** @var int<1,max> make sure that internal this is correct */ + $random_bytes_length = ($uniqid_length - ($uniqid_length % 2)) / 2; + $uniqid = bin2hex(random_bytes($random_bytes_length)); + // if not forced shorten return next lower length + if (!$force_length) { + return $uniqid; + } + return substr($uniqid, 0, $length); + } + /** * creates psuedo random uuid v4 * Code take from class here: @@ -20,7 +56,7 @@ class Uids */ public static function uuidv4(): string { - return sprintf( + /* return sprintf( '%04x%04x-%04x-%04x-%04x-%04x%04x%04x', // 32 bits for "time_low" mt_rand(0, 0xffff), @@ -38,49 +74,62 @@ class Uids mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff) - ); + ); */ + + $data = random_bytes(16); + assert(strlen($data) == 16); + + // 0-1: 32 bits for "time_low" + // 2: 16 bits for "time_mid" + // 3: 16 bits for "time_hi_and_version", + // four most significant bits holds version number 4 + $data[6] = chr(ord($data[6]) & 0x0f | 0x40); // set version to 0100 + // 4: 16 bits, 8 bits for "clk_seq_hi_res", + // 8 bits for "clk_seq_low", + // two most significant bits holds zero and one for variant DCE1.1 + $data[8] = chr(ord($data[8]) & 0x3f | 0x80); // set bits 6-7 to 10 + // 5-7: 48 bits for "node" + + return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4)); } /** - * TODO: make this a proper uniq ID creation - * add uuidv4 subcall to the uuid function too - * creates a uniq id + * creates a uniq id based on lengths * - * @param string $type uniq id type, currently md5 or sha256 allowed - * if not set will use DEFAULT_HASH if set - * @return string uniq id + * @param int|string $length Either length in int, or fallback type for length + * for string type md5 (32), sha256 (64) + * STANDARD_HASH_LONG: ripemd160 (40) + * STANDARD_HASH_SHORT: adler32 (8) + * It is recommended to use the integer + * @param bool $force_length [default=false] if set to true and we have + * uneven length, then we shorten to this length + * @return string Uniq id */ - public static function uniqId(string $type = ''): string - { - $uniq_id = ''; - switch ($type) { + public static function uniqId( + int|string $length = self::DEFAULT_UNNIQ_ID_LENGTH, + bool $force_length = false + ): string { + if (is_int($length)) { + return self::uniqIdL($length, $force_length); + } + switch ($length) { case 'md5': - $uniq_id = md5(uniqid((string)rand(), true)); + $length = 32; break; - case self::DEFAULT_HASH: - $uniq_id = hash(self::DEFAULT_HASH, uniqid((string)rand(), true)); + case 'sha256': + $length = 64; break; case self::STANDARD_HASH_LONG: - $uniq_id = hash(self::STANDARD_HASH_LONG, uniqid((string)rand(), true)); + $length = 40; break; case self::STANDARD_HASH_SHORT: - $uniq_id = hash(self::STANDARD_HASH_SHORT, uniqid((string)rand(), true)); + $length = 8; break; default: - // if not empty, check if in valid list - if ( - !empty($type) && - in_array($type, hash_algos()) - ) { - $hash = $type; - } else { - // fallback to default hash type if none set or invalid - $hash = self::DEFAULT_HASH; - } - $uniq_id = hash($hash, uniqid((string)rand(), true)); + $length = 64; break; } - return $uniq_id; + return self::uniqIdL($length); } /** diff --git a/www/lib/CoreLibs/DB/Extended/ArrayIO.php b/www/lib/CoreLibs/DB/Extended/ArrayIO.php index 0fe847f6..2dce7bb7 100644 --- a/www/lib/CoreLibs/DB/Extended/ArrayIO.php +++ b/www/lib/CoreLibs/DB/Extended/ArrayIO.php @@ -39,16 +39,16 @@ class ArrayIO extends \CoreLibs\DB\IO { // main calss variables /** @var array */ - public $table_array; // the array from the table to work on + public array $table_array; // the array from the table to work on /** @var string */ - public $table_name; // the table_name + public string $table_name; // the table_name /** @var string */ - public $pk_name = ''; // the primary key from this table + public string $pk_name = ''; // the primary key from this table /** @var int|string|null */ - public $pk_id; // the PK id + public int|string|null $pk_id; // the PK id // security values /** @var int base acl for current page */ - private $base_acl_level = 0; + private int $base_acl_level = 0; /** * constructor for the array io class, set the diff --git a/www/lib/CoreLibs/DB/IO.php b/www/lib/CoreLibs/DB/IO.php index 396cea6f..a4ed7c8a 100644 --- a/www/lib/CoreLibs/DB/IO.php +++ b/www/lib/CoreLibs/DB/IO.php @@ -298,101 +298,98 @@ class IO // can bet set from outside // encoding to /** @var string */ - private $to_encoding = ''; - /** @var string */ - private $query; // the query string at the moment - /** @var array */ - private $params; // current params for query + private string $to_encoding = ''; + /** @var string the query string at the moment */ + private string $query; + /** @var array current params for query */ + private array $params; // only inside // basic vars - /** @var \PgSql\Connection|false|null */ // replace object with PgSql\Connection| - private $dbh; // the dbh handler, if disconnected by command is null, bool:false on error, - /** @var bool */ - private $db_debug = false; // DB_DEBUG ... (if set prints out debug msgs) - /** @var string */ - private $db_name; // the DB connected to - /** @var string */ - private $db_user; // the username used - /** @var string */ - private $db_pwd; // the password used - /** @var string */ - private $db_host; // the hostname - /** @var int */ - private $db_port; // default db port - /** @var string */ - private $db_schema; // optional DB schema, if not set uses public - /** @var string */ - private $db_encoding; // optional auto encoding convert, not used if not set - /** @var string */ - private $db_type; // type of db (mysql,postgres,...) - /** @var string */ - private $db_ssl; // ssl flag (for postgres only), disable, allow, prefer, require + // the dbh handler, if disconnected by command is null, bool:false on error, + /** @var \PgSql\Connection|false|null */ + private \PgSql\Connection|false|null $dbh; + /** @var bool DB_DEBUG ... (if set prints out debug msgs) */ + private bool $db_debug = false; + /** @var string the DB connected to */ + private string $db_name; + /** @var string the username used */ + private string $db_user; + /** @var string the password used*/ + private string $db_pwd; + /** @var string the hostname */ + private string $db_host; + /** @var int default db port */ + private int $db_port; + /** @var string optional DB schema, if not set uses public*/ + private string $db_schema; + /** @var string optional auto encoding convert, not used if not set */ + private string $db_encoding; + /** @var string type of db (mysql,postgres,...) */ + private string $db_type; + /** @var string ssl flag (for postgres only), disable, allow, prefer, require */ + private string $db_ssl; // FOR BELOW: (This should be private and only readable through some method) // cursor array for cached readings - /** @var array */ - private $cursor_ext; // hash of hashes + /** @var array extended cursoers string index with content */ + private array $cursor_ext; // per query vars - /** @var \PgSql\Result|false */ // replace object with PgSql\Result - private $cursor; // actual cursor (DBH) - /** @var int */ - private $num_rows; // how many rows have been found - /** @var int */ - private $num_fields; // how many fields has the query + /** @var \PgSql\Result|false actual cursor (DBH) */ + private \PgSql\Result|false $cursor; + /** @var int how many rows have been found */ + private int $num_rows; + /** @var int how many fields has the query */ + private int $num_fields; /** @var array array with the field names of the current query */ - private $field_names = []; + private array $field_names = []; /** @var array field type names */ - private $field_types = []; - /** @var array */ - private $insert_id_arr = []; // always return as array, even if only one - /** @var string */ - private $insert_id_pk_name; // primary key name for insert recovery from insert_id_arr + private array $field_types = []; + /** @var array always return as array, even if only one */ + private array $insert_id_arr = []; + /** @var string primary key name for insert recovery from insert_id_arr */ + private string $insert_id_pk_name; // other vars - /** @var string */ - private $nbsp = ''; // used by print_array recursion function + /** @var string used by print_array recursion function */ + private string $nbsp = ''; // error & warning id /** @var string */ - private $error_id; + private string $error_id; /** @var string */ - private $warning_id; + private string $warning_id; /** @var string */ - private $error_history_id; + private string $error_history_id; /** @var array Stores warning and errors combinded with detail info */ - private $error_history_long = []; - // error thrown on class init if we cannot connect to db - /** @var bool */ - protected $db_connection_closed = false; + private array $error_history_long = []; + /** @var bool error thrown on class init if we cannot connect to db */ + protected bool $db_connection_closed = false; // sub include with the database functions /** @var \CoreLibs\DB\SQL\PgSQL if we have other DB types we need to add them here */ - private $db_functions; + private \CoreLibs\DB\SQL\PgSQL $db_functions; // endless loop protection /** @var int */ - private $MAX_QUERY_CALL; - /** @var int */ - public const DEFAULT_MAX_QUERY_CALL = 20; // default + private int $MAX_QUERY_CALL; + /** @var int maxium query calls allowed in a dbReturnRow loop before we error out */ + public const DEFAULT_MAX_QUERY_CALL = 20; /** @var array */ - private $query_called = []; + private array $query_called = []; // error string /** @var array */ - protected $error_string = []; + protected array $error_string = []; // prepared list /** @var array */ - private $prepare_cursor = []; + private array $prepare_cursor = []; // primary key per table list // format is 'table' => 'pk_name' /** @var array */ - private $pk_name_table = []; - // internal primary key name, for cross calls in async - /** @var string */ - private $pk_name; - // if we use RETURNING in the INSERT call - /** @var bool */ - private $returning_id = false; - // if a sync is running holds the hash key of the query - /** @var string */ - private $async_running; + private array $pk_name_table = []; + /** @var string internal primary key name, for cross calls in async */ + private string $pk_name; + /** @var bool if we use RETURNING in the INSERT call */ + private bool $returning_id = false; + /** @var string if a sync is running holds the hash key of the query */ + private string $async_running; // logging class, must be public so settings can be changed /** @var \CoreLibs\Logging\Logging */ - public $log; + public \CoreLibs\Logging\Logging $log; /** * main DB concstructor with auto connection to DB and failure set on failed connection diff --git a/www/lib/CoreLibs/DB/SQL/PgSQL.php b/www/lib/CoreLibs/DB/SQL/PgSQL.php index 2d9b34eb..fa4c7e89 100644 --- a/www/lib/CoreLibs/DB/SQL/PgSQL.php +++ b/www/lib/CoreLibs/DB/SQL/PgSQL.php @@ -59,9 +59,9 @@ namespace CoreLibs\DB\SQL; class PgSQL implements Interface\SqlFunctions { /** @var string */ - private $last_error_query; + private string $last_error_query; /** @var \PgSql\Connection|false */ - private $dbh = false; + private \PgSql\Connection|false $dbh = false; /** * queries last error query and returns true or false if error was set diff --git a/www/lib/CoreLibs/Debug/FileWriter.php b/www/lib/CoreLibs/Debug/FileWriter.php index 35234f9a..c7105bbf 100644 --- a/www/lib/CoreLibs/Debug/FileWriter.php +++ b/www/lib/CoreLibs/Debug/FileWriter.php @@ -12,9 +12,9 @@ namespace CoreLibs\Debug; class FileWriter { /** @var string */ - private static $debug_filename = 'debug_file.log'; // where to write output + private static string $debug_filename = 'debug_file.log'; // where to write output /** @var string */ - private static $debug_folder; + private static string $debug_folder; /** * Set a debug log folder, if not set BASE+LOG folders are set diff --git a/www/lib/CoreLibs/Debug/MemoryUsage.php b/www/lib/CoreLibs/Debug/MemoryUsage.php index f6090b27..d1416eae 100644 --- a/www/lib/CoreLibs/Debug/MemoryUsage.php +++ b/www/lib/CoreLibs/Debug/MemoryUsage.php @@ -13,13 +13,13 @@ use CoreLibs\Convert\Byte; class MemoryUsage { /** @var int */ - private static $start_memory = 0; + private static int $start_memory = 0; /** @var int */ - private static $set_memory = 0; + private static int $set_memory = 0; /** @var int */ - private static $previous_memory = 0; + private static int $previous_memory = 0; /** @var bool */ - private static $debug_memory = false; + private static bool $debug_memory = false; /** * set memory flag, or return set memory flag diff --git a/www/lib/CoreLibs/Debug/RunningTime.php b/www/lib/CoreLibs/Debug/RunningTime.php index 7058ef11..25faa86b 100644 --- a/www/lib/CoreLibs/Debug/RunningTime.php +++ b/www/lib/CoreLibs/Debug/RunningTime.php @@ -12,18 +12,18 @@ class RunningTime { // hr /** @var float */ - private static $hr_start_time; + private static float $hr_start_time; /** @var float */ - private static $hr_end_time; + private static float $hr_end_time; /** @var float */ - private static $hr_last_time; + private static float $hr_last_time; // normal /** @var float */ - private static $start_time; + private static float $start_time; /** @var float */ - private static $end_time; + private static float $end_time; /** @var string */ - private static $running_time_string; + private static string $running_time_string; /** * sub calculation for running time based on out time. @@ -79,7 +79,7 @@ class RunningTime public static function hrRunningTime(string $out_time = 'ms'): float { // if start time not set, set start time - if (!self::$hr_start_time) { + if (empty(self::$hr_start_time)) { self::$hr_start_time = hrtime(true); self::$hr_last_time = self::$hr_start_time; $run_time = 0; @@ -137,7 +137,7 @@ class RunningTime list($micro, $timestamp) = explode(' ', microtime()); $running_time = 0; // set start & end time - if (!self::$start_time) { + if (empty(self::$start_time)) { // always reset running time string on first call self::$running_time_string = ''; self::$start_time = ((float)$micro + (float)$timestamp); @@ -149,7 +149,7 @@ class RunningTime self::$running_time_string .= date('Y-m-d H:i:s', (int)$timestamp); self::$running_time_string .= ' ' . $micro . ($simple ? ', ' : '
'); // if both are set - if (self::$start_time && self::$end_time) { + if (!empty(self::$start_time) && !empty(self::$end_time)) { $running_time = self::$end_time - self::$start_time; self::$running_time_string .= ($simple ? 'Run: ' : "Script running time: ") . $running_time . " s"; // reset start & end time after run diff --git a/www/lib/CoreLibs/Debug/Support.php b/www/lib/CoreLibs/Debug/Support.php index 7f43688b..ef492c02 100644 --- a/www/lib/CoreLibs/Debug/Support.php +++ b/www/lib/CoreLibs/Debug/Support.php @@ -21,7 +21,7 @@ class Support */ public static function printTime(int $set_microtime = -1): string { - list($microtime, $timestamp) = explode(' ', microtime()); + [$microtime, $timestamp] = explode(' ', microtime()); $string = date("Y-m-d H:i:s", (int)$timestamp); // if microtime flag is -1 no round, if 0, no microtime, if >= 1, round that size if ($set_microtime == -1) { @@ -158,19 +158,32 @@ class Support * var_dump based * Recommended debug output * - * @param mixed $data Anything - * @param bool $no_html If true strip all html tags (for text print) - * @return string A text string + * @param mixed $data Anything + * @param bool $no_html [default=false] If true strip all html tags + * (for text print) + * @return string A text string */ - public static function dumpVar(mixed $data, bool $no_html = false): string - { + public static function dumpVar( + mixed $data, + bool $no_html = false, + ): string { + // dump data ob_start(); var_dump($data); $debug_dump = ob_get_clean() ?: '[FAILED TO GET var_dump() data]'; + // check if the original caller is dV, if yes, up the caller level for + // the file line get by 1, so we get file + pos from the dV call and + // not this call + $caller_level = 1; + $caller_list = self::getCallerMethodList(); + if ($caller_list[0] == 'dV') { + echo "Raise caller level
: " . $caller_list[0] . "
"; + $caller_level = 2; + } // we need to strip the string in : // and replace it with the caller methods and location - $caller_file_number = self::getCallerFileLine(); + $caller_file_number = self::getCallerFileLine($caller_level); $debug_dump = preg_replace( '|(/.*:\d+:)|', '' . $caller_file_number . ':', diff --git a/www/lib/CoreLibs/Get/System.php b/www/lib/CoreLibs/Get/System.php index 4984564d..690b43b8 100644 --- a/www/lib/CoreLibs/Get/System.php +++ b/www/lib/CoreLibs/Get/System.php @@ -54,14 +54,15 @@ class System /** * get the host name without the port as given by the SELF var + * if no host name found will set to NOHOST:0 * - * @return array host name/port name + * @return array{string,int} host name/port number */ public static function getHostName(): array { - $host = $_SERVER['HTTP_HOST'] ?? 'NOHOST:NOPORT'; - list($host_name, $port) = array_pad(explode(':', $host), 2, self::DEFAULT_PORT); - return [$host_name, $port]; + $host = $_SERVER['HTTP_HOST'] ?? 'NOHOST:0'; + [$host_name, $port] = array_pad(explode(':', $host), 2, self::DEFAULT_PORT); + return [$host_name, (int)$port]; } /** diff --git a/www/lib/CoreLibs/Language/Core/CachedFileReader.php b/www/lib/CoreLibs/Language/Core/CachedFileReader.php index adcd535c..95721bbc 100644 --- a/www/lib/CoreLibs/Language/Core/CachedFileReader.php +++ b/www/lib/CoreLibs/Language/Core/CachedFileReader.php @@ -29,9 +29,9 @@ namespace CoreLibs\Language\Core; class CachedFileReader extends \CoreLibs\Language\Core\StringReader { /** @var int */ - public $error = 0; + public int $error = 0; /** @var string */ - public $fd_str = ''; + public string $fd_str = ''; /** * Undocumented function diff --git a/www/lib/CoreLibs/Language/Core/FileReader.php b/www/lib/CoreLibs/Language/Core/FileReader.php index 8488fa38..ae4f6e18 100644 --- a/www/lib/CoreLibs/Language/Core/FileReader.php +++ b/www/lib/CoreLibs/Language/Core/FileReader.php @@ -27,13 +27,13 @@ namespace CoreLibs\Language\Core; class FileReader { /** @var int */ - public $fr_pos; + public int $fr_pos; /** @var resource|bool */ - public $fr_fd; + public mixed $fr_fd; // no resource type yet /** @var int */ - public $fr_length; + public int $fr_length; /** @var int */ - public $error = 0; + public int $error = 0; /** * file read constructor diff --git a/www/lib/CoreLibs/Language/Core/GetTextReader.php b/www/lib/CoreLibs/Language/Core/GetTextReader.php index 3fa7404d..0a5715a7 100644 --- a/www/lib/CoreLibs/Language/Core/GetTextReader.php +++ b/www/lib/CoreLibs/Language/Core/GetTextReader.php @@ -41,31 +41,31 @@ class GetTextReader { // public: /** @var int */ - public $error = 0; // public variable that holds error code (0 if no error) + public int $error = 0; // public variable that holds error code (0 if no error) // private: /** @var int */ - private $BYTEORDER = 0; // 0: low endian, 1: big endian + private int $BYTEORDER = 0; // 0: low endian, 1: big endian /** @var FileReader */ - private $STREAM; + private FileReader $STREAM; /** @var bool */ - private $short_circuit = false; + private bool $short_circuit = false; /** @var bool */ - private $enable_cache = false; + private bool $enable_cache = false; /** @var int */ - private $originals = 0; // offset of original table + private int $originals = 0; // offset of original table /** @var int */ - private $translations = 0; // offset of translation table + private int $translations = 0; // offset of translation table /** @var string */ - private $pluralheader = ''; // cache header field for plural forms + private string $pluralheader = ''; // cache header field for plural forms /** @var int */ - private $total = 0; // total string count + private int $total = 0; // total string count /** @var array|null */ - private $table_originals = null; // table for original strings (offsets) + private array|null $table_originals = null; // table for original strings (offsets) /** @var array|null */ - private $table_translations = null; // table for translated strings (offsets) + private array|null $table_translations = null; // table for translated strings (offsets) /** @var array */ - private $cache_translations = []; // original -> translation mapping + private array $cache_translations = []; // original -> translation mapping /* Methods */ diff --git a/www/lib/CoreLibs/Language/Core/StringReader.php b/www/lib/CoreLibs/Language/Core/StringReader.php index 90766e9e..063647d3 100644 --- a/www/lib/CoreLibs/Language/Core/StringReader.php +++ b/www/lib/CoreLibs/Language/Core/StringReader.php @@ -27,9 +27,9 @@ namespace CoreLibs\Language\Core; class StringReader { /** @var int */ - public $sr_pos; + public int $sr_pos; /** @var string */ - public $sr_str; + public string $sr_str; /** * constructor for string reader diff --git a/www/lib/CoreLibs/Language/L10n.php b/www/lib/CoreLibs/Language/L10n.php index 75db228a..dcf97a74 100644 --- a/www/lib/CoreLibs/Language/L10n.php +++ b/www/lib/CoreLibs/Language/L10n.php @@ -35,42 +35,42 @@ class L10n /** @var string the default fallback encoding if nothing is set */ public const DEFAULT_CHARSET = 'UTF-8'; /** @var string the current locale */ - private $locale = ''; + private string $locale = ''; /** @var string the SET locale as WHERE the domain file is */ - private $locale_set = ''; + private string $locale_set = ''; /** @var string the default selected/active domain */ - private $domain = ''; + private string $domain = ''; /** @var string encoding, as from locale or set from outside */ - private $override_encoding = self::DEFAULT_CHARSET; + private string $override_encoding = self::DEFAULT_CHARSET; /** @var string encoding set during the parse Locale */ - private $encoding = ''; + private string $encoding = ''; /** @var array> locale > domain = translator */ - private $domains = []; + private array $domains = []; /** @var array bound paths for domains */ - private $paths = ['' => './']; + private array $paths = ['' => './']; // files /** @var string the full path to the mo file to loaded */ - private $mofile = ''; + private string $mofile = ''; /** @var string base path to search level */ - private $base_locale_path = ''; + private string $base_locale_path = ''; /** @var string dynamic set path to where the mo file is actually */ - private $base_content_path = ''; + private string $base_content_path = ''; // errors /** @var bool if load of mo file was unsuccessful */ - private $load_failure = false; + private bool $load_failure = false; // object holders /** @var FileReader|bool reader class for file reading, false for short circuit */ - private $input = false; + private FileReader|bool $input = false; /** @var GetTextReader reader class for MO data */ - private $l10n; + private GetTextReader|null $l10n = null; /** * @static * @var L10n self class */ - private static $instance; + private static L10n $instance; /** * class constructor call for language getstring @@ -124,7 +124,6 @@ class L10n */ public static function getInstance(): L10n { - /** @phpstan-ignore-next-line */ if (empty(self::$instance)) { self::$instance = new self(); } @@ -253,6 +252,13 @@ class L10n // dummy $this->l10n = new GetTextReader($this->input); } + // if this is still null here, we abort + if ($this->l10n === null) { + throw new \Exception( + "Could not create CoreLibs\Language\Core\GetTextReader object", + E_USER_ERROR + ); + } return $this->l10n; } @@ -673,6 +679,7 @@ class L10n // fallback passthrough if ($this->l10n === null) { echo $text; + return; } echo $this->l10n->translate($text); } diff --git a/www/lib/CoreLibs/Logging/Logging.php b/www/lib/CoreLibs/Logging/Logging.php index d7430ddf..81630a33 100644 --- a/www/lib/CoreLibs/Logging/Logging.php +++ b/www/lib/CoreLibs/Logging/Logging.php @@ -6,7 +6,12 @@ * DESCRIPTION: * Logging class * - * NOTE: This is Logging2 for testing simpler build + * Build on the old logging class but can no longer print to screen + * Adds all standard logging levels + * + * Will be superseeded or will be inbetween to Monolog: + * https://github.com/Seldaek/monolog + * CoreLibs\Logging\Logger\Level is a direct copy from Monolog */ declare(strict_types=1); @@ -81,38 +86,38 @@ class Logging // options /** @var array */ - private $options = []; + private array $options = []; /** @var Level set level */ - private $log_level; + private Level $log_level; // page and host name /** @var string */ - private $host_name; + private string $host_name; /** @var int */ - private $host_port; + private int $host_port; /** @var string unique ID set on class init and used in logging as prefix */ - private $running_uid = ''; + private string $running_uid = ''; // log file name /** @var string */ - private $log_folder = ''; + private string $log_folder = ''; /** @var string a alphanumeric name that has to be set as global definition */ - private $log_file_id = ''; + private string $log_file_id = ''; /** @var string log file name extension */ - private $log_file_name_ext = 'log'; + private string $log_file_name_ext = 'log'; /** @var string log file name with folder, for actual writing */ - private $log_file_name = ''; + private string $log_file_name = ''; /** @var int set in bytes */ - private $log_max_filesize = 0; + private int $log_max_filesize = 0; /** @var string used if no log id set or found */ - private $log_file_prefix = 'error_msg'; + private string $log_file_prefix = 'error_msg'; /** @var string */ - private $log_print_file = '{LOGID}{LEVEL}{GROUP}{CLASS}{PAGENAME}{DATE_RUNID}'; + private string $log_print_file = '{LOGID}{LEVEL}{GROUP}{CLASS}{PAGENAME}{DATE_RUNID}'; /** @var string a unique ID set only once for call derived from this class */ - private $log_file_unique_id = ''; + private string $log_file_unique_id = ''; /** @var string Y-m-d file in file name */ - private $log_file_date = ''; + private string $log_file_date = ''; /** * 1: create a new log file per run (time stamp + unique ID) @@ -123,9 +128,9 @@ class Logging * 32: split log per set log level */ /** @var int bitwise set for log flags */ - private $log_flags = 0; + private int $log_flags = 0; /** @var array valid log flag names */ - private $log_valid_flags = [ + private array $log_valid_flags = [ 'log_per_run' => Flag::per_run, 'log_per_date' => Flag::per_date, 'log_per_group' => Flag::per_group, @@ -323,10 +328,10 @@ class Logging private function initHostName(): void { // set host name - list($this->host_name , $this->host_port) = System::getHostName(); + [$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; + $this->host_name .= ':' . (string)$this->host_port; } } @@ -543,8 +548,16 @@ class Logging array $context = [], string $group_id = '', ): string { + // file + line: call not this but one before (the one that calls this) + $file_line = Support::getCallerFileLine(2) ?? + System::getPageName(System::FULL_PATH); // get the last class entry and wrie that $class = Support::getCallerClass(); + // method/function: prepareLog->(debug|info|...)->[THIS] + $method = Support::getCallerMethod(3); + if ($method !== null) { + $class .= '::' . $method; + } // get timestamp $timestamp = Support::printTime(); @@ -562,7 +575,7 @@ class Logging // build log string return '[' . $timestamp . '] ' . '[' . $this->host_name . '] ' - . '[' . System::getPageName(System::FULL_PATH) . '] ' + . '[' . $file_line . '] ' . '[' . $this->running_uid . '] ' . '{' . $class . '} ' . '<' . strtoupper($group_str) . '> ' @@ -598,7 +611,6 @@ class Logging . implode(', ', Level::NAMES + Level::VALUES) ); } - return $levelEnum; } @@ -710,7 +722,10 @@ class Logging if (empty($this->log_file_unique_id) || $override == true) { $this->log_file_unique_id = date('Y-m-d_His') . '_U_' - . substr(hash('sha1', uniqid((string)mt_rand(), true)), 0, 8); + . substr(hash( + 'sha1', + random_bytes(63) + ), 0, 8); } } diff --git a/www/lib/CoreLibs/Output/Form/Generate.php b/www/lib/CoreLibs/Output/Form/Generate.php index 8ae7c881..6e7e9dfc 100644 --- a/www/lib/CoreLibs/Output/Form/Generate.php +++ b/www/lib/CoreLibs/Output/Form/Generate.php @@ -226,84 +226,84 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO // for the load statetment describes which elements from // the load query should be shown and i which format /** @var array */ - public $field_array = []; + public array $field_array = []; /** @var string */ - public $load_query; // the query needed for loading a data set (one row in the table) + public string $load_query; // the query needed for loading a data set (one row in the table) /** @var string */ - public $col_name; // the name of the columen (before _) [used for order button] + public string $col_name; // the name of the columen (before _) [used for order button] /** @var int */ - public $yes; // the yes flag that triggers the template to show ALL and not only new/load + public int $yes; // the yes flag that triggers the template to show ALL and not only new/load /** @var string */ - public $msg; // the error msg + public string $msg; // the error msg /** @var int */ - public $error; // the error flag set for printing red error msg + public int $error; // the error flag set for printing red error msg /** @var int */ - public $warning; // warning flag, for information (saved, loaded, etc) + public int $warning; // warning flag, for information (saved, loaded, etc) /** @var string */ - public $archive_pk_name; // the pk name for the load select form + public string $archive_pk_name; // the pk name for the load select form /** @var string */ - private $int_pk_name; // primary key, only internal usage + private string $int_pk_name; // primary key, only internal usage /** @var array */ - public $reference_array = []; // reference arrays -> stored in $this->reference_array[$table_name] => []; + public array $reference_array = []; // reference arrays -> stored in $this->reference_array[$table_name] => []; // NOTE: should be changed to this @var mixed[] /** @var array */ - public $element_list; // element list for elements next to each other as a special sub group + public array $element_list; // element list for elements next to each other as a special sub group /** @var array */ - public $table_array = []; + public array $table_array = []; /** @var string */ - public $my_page_name; // the name of the page without .php extension + public string $my_page_name; // the name of the page without .php extension /** @var bool */ - public $mobile_phone = false; + public bool $mobile_phone = false; /** @var string */ - public $email_regex; + public string $email_regex; // buttons and checkboxes /** @var string */ - public $archive; + public string $archive; /** @var string */ - public $new; + public string $new; /** @var string */ - public $really_new; + public string $really_new; /** @var string */ - public $delete; + public string $delete; /** @var string */ - public $really_delete; + public string $really_delete; /** @var string */ - public $save; + public string $save; /** @var string */ - public $remove_button; + public string $remove_button; // security values /** @var int base acl for current page */ - private $base_acl_level = 0; + private int $base_acl_level = 0; /** @var int admin master flag (1/0) */ - private $acl_admin = 0; + private int $acl_admin = 0; /** @var array */ - public $security_level; + public array $security_level; /** @var array Login ACL */ - public $login_acl = []; + public array $login_acl = []; // layout publics /** @var int */ - public $table_width; + public int $table_width; // internal lang & encoding vars /** @var string */ - public $lang_dir = ''; + public string $lang_dir = ''; /** @var string */ - public $lang; + public string $lang; /** @var string */ - public $lang_short; + public string $lang_short; /** @var string */ - public $domain; + public string $domain; /** @var string */ - public $encoding; + public string $encoding; // language /** @var \CoreLibs\Language\L10n */ - public $l; + public \CoreLibs\Language\L10n $l; // log /** @var \CoreLibs\Logging\Logging */ - public $log; + public \CoreLibs\Logging\Logging $log; // now some default error msgs (english) /** @var array */ - public $language_array = []; + public array $language_array = []; /** * construct form generator diff --git a/www/lib/CoreLibs/Output/Form/TableArrays/EditAccess.php b/www/lib/CoreLibs/Output/Form/TableArrays/EditAccess.php index 3701e54c..53cad379 100644 --- a/www/lib/CoreLibs/Output/Form/TableArrays/EditAccess.php +++ b/www/lib/CoreLibs/Output/Form/TableArrays/EditAccess.php @@ -7,7 +7,7 @@ namespace CoreLibs\Output\Form\TableArrays; class EditAccess implements Interface\TableArraysInterface { /** @var \CoreLibs\Output\Form\Generate */ - private $form; + private \CoreLibs\Output\Form\Generate $form; /** * constructor diff --git a/www/lib/CoreLibs/Output/Form/TableArrays/EditGroups.php b/www/lib/CoreLibs/Output/Form/TableArrays/EditGroups.php index 0ff66ebc..9ad6413f 100644 --- a/www/lib/CoreLibs/Output/Form/TableArrays/EditGroups.php +++ b/www/lib/CoreLibs/Output/Form/TableArrays/EditGroups.php @@ -7,7 +7,7 @@ namespace CoreLibs\Output\Form\TableArrays; class EditGroups implements Interface\TableArraysInterface { /** @var \CoreLibs\Output\Form\Generate */ - private $form; + private \CoreLibs\Output\Form\Generate $form; /** * constructor diff --git a/www/lib/CoreLibs/Output/Form/TableArrays/EditLanguages.php b/www/lib/CoreLibs/Output/Form/TableArrays/EditLanguages.php index b2a3ba9b..0c4b1e08 100644 --- a/www/lib/CoreLibs/Output/Form/TableArrays/EditLanguages.php +++ b/www/lib/CoreLibs/Output/Form/TableArrays/EditLanguages.php @@ -7,7 +7,7 @@ namespace CoreLibs\Output\Form\TableArrays; class EditLanguages implements Interface\TableArraysInterface { /** @var \CoreLibs\Output\Form\Generate */ - private $form; + private \CoreLibs\Output\Form\Generate $form; /** * constructor diff --git a/www/lib/CoreLibs/Output/Form/TableArrays/EditMenuGroup.php b/www/lib/CoreLibs/Output/Form/TableArrays/EditMenuGroup.php index 48826bb8..e8945be4 100644 --- a/www/lib/CoreLibs/Output/Form/TableArrays/EditMenuGroup.php +++ b/www/lib/CoreLibs/Output/Form/TableArrays/EditMenuGroup.php @@ -7,7 +7,7 @@ namespace CoreLibs\Output\Form\TableArrays; class EditMenuGroup implements Interface\TableArraysInterface { /** @var \CoreLibs\Output\Form\Generate */ - private $form; + private \CoreLibs\Output\Form\Generate $form; /** * constructor diff --git a/www/lib/CoreLibs/Output/Form/TableArrays/EditPages.php b/www/lib/CoreLibs/Output/Form/TableArrays/EditPages.php index 6ecd26e5..1ac90390 100644 --- a/www/lib/CoreLibs/Output/Form/TableArrays/EditPages.php +++ b/www/lib/CoreLibs/Output/Form/TableArrays/EditPages.php @@ -7,7 +7,7 @@ namespace CoreLibs\Output\Form\TableArrays; class EditPages implements Interface\TableArraysInterface { /** @var \CoreLibs\Output\Form\Generate */ - private $form; + private \CoreLibs\Output\Form\Generate $form; /** * constructor diff --git a/www/lib/CoreLibs/Output/Form/TableArrays/EditSchemas.php b/www/lib/CoreLibs/Output/Form/TableArrays/EditSchemas.php index 8417ac1f..c81a0d1e 100644 --- a/www/lib/CoreLibs/Output/Form/TableArrays/EditSchemas.php +++ b/www/lib/CoreLibs/Output/Form/TableArrays/EditSchemas.php @@ -7,7 +7,7 @@ namespace CoreLibs\Output\Form\TableArrays; class EditSchemas implements Interface\TableArraysInterface { /** @var \CoreLibs\Output\Form\Generate */ - private $form; + private \CoreLibs\Output\Form\Generate $form; /** * constructor diff --git a/www/lib/CoreLibs/Output/Form/TableArrays/EditUsers.php b/www/lib/CoreLibs/Output/Form/TableArrays/EditUsers.php index a85cb0e9..6d87753a 100644 --- a/www/lib/CoreLibs/Output/Form/TableArrays/EditUsers.php +++ b/www/lib/CoreLibs/Output/Form/TableArrays/EditUsers.php @@ -7,7 +7,7 @@ namespace CoreLibs\Output\Form\TableArrays; class EditUsers implements Interface\TableArraysInterface { /** @var \CoreLibs\Output\Form\Generate */ - private $form; + private \CoreLibs\Output\Form\Generate $form; /** * constructor diff --git a/www/lib/CoreLibs/Output/Form/TableArrays/EditVisibleGroup.php b/www/lib/CoreLibs/Output/Form/TableArrays/EditVisibleGroup.php index 98a2f223..91da1cab 100644 --- a/www/lib/CoreLibs/Output/Form/TableArrays/EditVisibleGroup.php +++ b/www/lib/CoreLibs/Output/Form/TableArrays/EditVisibleGroup.php @@ -7,7 +7,7 @@ namespace CoreLibs\Output\Form\TableArrays; class EditVisibleGroup implements Interface\TableArraysInterface { /** @var \CoreLibs\Output\Form\Generate */ - private $form; + private \CoreLibs\Output\Form\Generate $form; /** * constructor diff --git a/www/lib/CoreLibs/Output/ProgressBar.php b/www/lib/CoreLibs/Output/ProgressBar.php index 03c09ef9..6affd992 100644 --- a/www/lib/CoreLibs/Output/ProgressBar.php +++ b/www/lib/CoreLibs/Output/ProgressBar.php @@ -23,13 +23,13 @@ class ProgressBar // private vars /** @var string */ - public $code; // unique code + public string $code; // unique code /** @var string */ - public $status = 'new'; // current status (new,show,hide) + public string $status = 'new'; // current status (new,show,hide) /** @var float|int */ - public $step = 0; // current step + public float|int $step = 0; // current step /** @var array */ - public $position = [ // current bar position + public array $position = [ // current bar position 'left' => null, 'top' => null, 'width' => null, @@ -37,43 +37,43 @@ class ProgressBar ]; /** @var int */ - public $clear_buffer_size = 1; // we need to send this before the lfush to get browser output + public int $clear_buffer_size = 1; // we need to send this before the lfush to get browser output /** @var int */ - public $clear_buffer_size_init = 1024 * 1024; // if I don't send that junk, it won't send anything + public int $clear_buffer_size_init = 1024 * 1024; // if I don't send that junk, it won't send anything // public vars /** @var int */ - public $min = 0; // minimal steps + public int $min = 0; // minimal steps /** @var int */ - public $max = 100; // maximal steps + public int $max = 100; // maximal steps /** @var int */ - public $left = 5; // bar position from left + public int $left = 5; // bar position from left /** @var int */ - public $top = 5; // bar position from top + public int $top = 5; // bar position from top /** @var int */ - public $width = 300; // bar width + public int $width = 300; // bar width /** @var int */ - public $height = 25; // bar height + public int $height = 25; // bar height /** @var int */ - public $pedding = 0; // bar pedding + public int $pedding = 0; // bar pedding /** @var string */ - public $color = '#0033ff'; // bar color + public string $color = '#0033ff'; // bar color /** @var string */ - public $bgr_color = '#c0c0c0'; // bar background color + public string $bgr_color = '#c0c0c0'; // bar background color /** @var string */ - public $bgr_color_master = '#ffffff'; // master div background color + public string $bgr_color_master = '#ffffff'; // master div background color /** @var int */ - public $border = 1; // bar border width + public int $border = 1; // bar border width /** @var string */ - public $brd_color = '#000000'; // bar border color + public string $brd_color = '#000000'; // bar border color /** @var string */ - public $direction = 'right'; // direction of motion (right,left,up,down) + public string $direction = 'right'; // direction of motion (right,left,up,down) /** @var array */ - public $frame = ['show' => false]; // ProgressBar Frame + public array $frame = ['show' => false]; // ProgressBar Frame /* 'show' => false, # frame show (true/false) 'left' => 200, # frame position from left 'top' => 100, # frame position from top @@ -86,7 +86,7 @@ class ProgressBar /** @#var array{string}{string: string|int} */ /** @var mixed[][] */ - public $label = []; // ProgressBar Labels + public array $label = []; // ProgressBar Labels /* 'name' => [ # label name 'type' => 'text', # label type (text,button,step,percent,crossbar) 'value' => 'Please wait ...', # label value @@ -105,7 +105,7 @@ class ProgressBar /** @var string */ // output strings - public $prefix_message = ''; + public string $prefix_message = ''; /** * progress bar constructor diff --git a/www/lib/CoreLibs/Security/SymmetricEncryption.php b/www/lib/CoreLibs/Security/SymmetricEncryption.php index cd99f584..b106cea1 100644 --- a/www/lib/CoreLibs/Security/SymmetricEncryption.php +++ b/www/lib/CoreLibs/Security/SymmetricEncryption.php @@ -2,7 +2,9 @@ /** * very simple symmetric encryption - * Better use: https://paragonie.com/project/halite + * Better use: + * https://paragonie.com/project/halite + * https://github.com/paragonie/halite * * current code is just to encrypt and decrypt * diff --git a/www/lib/CoreLibs/Template/SmartyExtend.php b/www/lib/CoreLibs/Template/SmartyExtend.php index 9b2d916d..3d926b1c 100644 --- a/www/lib/CoreLibs/Template/SmartyExtend.php +++ b/www/lib/CoreLibs/Template/SmartyExtend.php @@ -24,134 +24,132 @@ class SmartyExtend extends \Smarty { // internal translation engine /** @var \CoreLibs\Language\L10n */ - public $l10n; + public \CoreLibs\Language\L10n $l10n; // lang & encoding /** @var string */ - public $lang_dir = ''; + public string $lang_dir = ''; /** @var string */ - public $lang; + public string $lang; /** @var string */ - public $locale_set; + public string $lang_short; /** @var string */ - public $lang_short; + public string $domain; /** @var string */ - public $domain; - /** @var string */ - public $encoding; + public string $encoding; // page name /** @var string */ - public $page_name; + public string $page_name; // array for data parsing /** @var array */ - public $HEADER = []; + public array $HEADER = []; /** @var array */ - public $DATA = []; + public array $DATA = []; /** @var array */ - public $DEBUG_DATA = []; + public array $DEBUG_DATA = []; /** @var array */ - private $CONTENT_DATA = []; + private array $CONTENT_DATA = []; // control vars /** @var bool */ - public $USE_PROTOTYPE = USE_PROTOTYPE; + public bool $USE_PROTOTYPE = USE_PROTOTYPE; /** @var bool */ - public $USE_JQUERY = USE_JQUERY; + public bool $USE_JQUERY = USE_JQUERY; /** @var bool */ - public $USE_SCRIPTACULOUS = USE_SCRIPTACULOUS; + public bool $USE_SCRIPTACULOUS = USE_SCRIPTACULOUS; // sub content input vars /** @var bool */ - public $USE_TINY_MCE = false; + public bool $USE_TINY_MCE = false; /** @var bool */ - public $JS_DATEPICKR = false; + public bool $JS_DATEPICKR = false; /** @var bool */ - public $JS_FLATPICKR = false; + public bool $JS_FLATPICKR = false; /** @var bool */ - public $JS_FILE_UPLOADER = false; + public bool $JS_FILE_UPLOADER = false; /** @var bool */ - public $DEBUG_TMPL = false; + public bool $DEBUG_TMPL = false; /** @var bool */ - public $USE_INCLUDE_TEMPLATE = false; + public bool $USE_INCLUDE_TEMPLATE = false; // cache & compile /** @var string */ - public $CACHE_ID = ''; + public string $CACHE_ID = ''; /** @var string */ - public $COMPILE_ID = ''; + public string $COMPILE_ID = ''; // template vars /** @var string */ - public $MASTER_TEMPLATE_NAME; + public string $MASTER_TEMPLATE_NAME; /** @var string */ - public $PAGE_FILE_NAME; + public string $PAGE_FILE_NAME; /** @var string */ - public $CONTENT_INCLUDE; + public string $CONTENT_INCLUDE; /** @var string */ - public $FORM_NAME; + public string $FORM_NAME; /** @var string */ - public $FORM_ACTION; + public string $FORM_ACTION; /** @var string */ - public $L_TITLE; + public string $L_TITLE; /** @var string|int */ - public $PAGE_WIDTH; + public string|int $PAGE_WIDTH; // smarty include/set var /** @var string */ - public $TEMPLATE_PATH; + public string $TEMPLATE_PATH; /** @var string */ - public $TEMPLATE_NAME; + public string $TEMPLATE_NAME; /** @var string */ - public $INC_TEMPLATE_NAME; + public string $INC_TEMPLATE_NAME; /** @var string */ - public $JS_TEMPLATE_NAME; + public string $JS_TEMPLATE_NAME; /** @var string */ - public $CSS_TEMPLATE_NAME; + public string $CSS_TEMPLATE_NAME; /** @var string|null */ - public $TEMPLATE_TRANSLATE; + public string|null $TEMPLATE_TRANSLATE; /** @var string|null */ - public $JS_TRANSLATE; + public string|null $JS_TRANSLATE; // core group /** @var string */ - public $JS_CORE_TEMPLATE_NAME; + public string $JS_CORE_TEMPLATE_NAME; /** @var string */ - public $CSS_CORE_TEMPLATE_NAME; + public string $CSS_CORE_TEMPLATE_NAME; /** @var string */ - public $JS_CORE_INCLUDE; + public string $JS_CORE_INCLUDE; /** @var string */ - public $CSS_CORE_INCLUDE; + public string $CSS_CORE_INCLUDE; // local names /** @var string */ - public $JS_SPECIAL_TEMPLATE_NAME = ''; + public string $JS_SPECIAL_TEMPLATE_NAME = ''; /** @var string */ - public $CSS_SPECIAL_TEMPLATE_NAME = ''; + public string $CSS_SPECIAL_TEMPLATE_NAME = ''; /** @var string */ - public $JS_INCLUDE; + public string $JS_INCLUDE; /** @var string */ - public $CSS_INCLUDE; + public string $CSS_INCLUDE; /** @var string */ - public $JS_SPECIAL_INCLUDE; + public string $JS_SPECIAL_INCLUDE; /** @var string */ - public $CSS_SPECIAL_INCLUDE; + public string $CSS_SPECIAL_INCLUDE; /** @var string */ - public $ADMIN_JAVASCRIPT; + public string $ADMIN_JAVASCRIPT; /** @var string */ - public $ADMIN_STYLESHEET; + public string $ADMIN_STYLESHEET; /** @var string */ - public $FRONTEND_JAVASCRIPT; + public string $FRONTEND_JAVASCRIPT; /** @var string */ - public $FRONTEND_STYLESHEET; + public string $FRONTEND_STYLESHEET; // other smarty folder vars /** @var string */ - public $INCLUDES; + public string $INCLUDES; /** @var string */ - public $JAVASCRIPT; + public string $JAVASCRIPT; /** @var string */ - public $CSS; + public string $CSS; /** @var string */ - public $FONT; + public string $FONT; /** @var string */ - public $PICTURES; + public string $PICTURES; /** @var string */ - public $CACHE_PICTURES; + public string $CACHE_PICTURES; /** @var string */ - public $CACHE_PICTURES_ROOT; + public string $CACHE_PICTURES_ROOT; // constructor class, just sets the language stuff /** @@ -222,6 +220,7 @@ class SmartyExtend extends \Smarty // core CS $this->CSS_CORE_INCLUDE = ''; if ( + !empty($this->CSS_CORE_TEMPLATE_NAME) && file_exists($this->CSS . $this->CSS_CORE_TEMPLATE_NAME) && is_file($this->CSS . $this->CSS_CORE_TEMPLATE_NAME) ) { @@ -230,6 +229,7 @@ class SmartyExtend extends \Smarty // core JS $this->JS_CORE_INCLUDE = ''; if ( + !empty($this->JS_CORE_TEMPLATE_NAME) && file_exists($this->JAVASCRIPT . $this->JS_CORE_TEMPLATE_NAME) && is_file($this->JAVASCRIPT . $this->JS_CORE_TEMPLATE_NAME) ) { @@ -398,7 +398,7 @@ class SmartyExtend extends \Smarty // javascript translate data as template for auto translate if (empty($this->TEMPLATE_TRANSLATE)) { $this->TEMPLATE_TRANSLATE = 'jsTranslate-' - . $this->locale_set . '.' . $this->encoding + . $this->l10n->getLocaleSet() . '.' . $this->encoding . '.tpl'; } else { // we assume we have some fixed set @@ -408,12 +408,12 @@ class SmartyExtend extends \Smarty if (strpos($this->TEMPLATE_TRANSLATE, '.tpl')) { $this->TEMPLATE_TRANSLATE = str_replace( '.tpl', - '-' . $this->locale_set . '.' . $this->encoding . '.tpl', + '-' . $this->l10n->getLocaleSet() . '.' . $this->encoding . '.tpl', $this->TEMPLATE_TRANSLATE ); } else { $this->TEMPLATE_TRANSLATE .= '-' - . $this->locale_set . '.' . $this->encoding + . $this->l10n->getLocaleSet() . '.' . $this->encoding . '.tpl'; } } @@ -423,7 +423,7 @@ class SmartyExtend extends \Smarty } if (empty($this->JS_TRANSLATE)) { $this->JS_TRANSLATE = 'translate-' - . $this->locale_set . '.' . $this->encoding . '.js'; + . $this->l10n->getLocaleSet() . '.' . $this->encoding . '.js'; } else { // we assume we have some fixed set // we must add _. @@ -432,12 +432,12 @@ class SmartyExtend extends \Smarty if (strpos($this->JS_TRANSLATE, '.js')) { $this->JS_TRANSLATE = str_replace( '.js', - '-' . $this->locale_set . '.' . $this->encoding . '.js', + '-' . $this->l10n->getLocaleSet() . '.' . $this->encoding . '.js', $this->JS_TRANSLATE ); } else { $this->JS_TRANSLATE .= '-' - . $this->locale_set . '.' . $this->encoding + . $this->l10n->getLocaleSet() . '.' . $this->encoding . '.js'; } } @@ -675,10 +675,12 @@ class SmartyExtend extends \Smarty $this->HEADER['DEFAULT_ENCODING'] = $set_default_encoding; // form name - $this->DATA['FORM_NAME'] = !$this->FORM_NAME ? + $this->DATA['FORM_NAME'] = empty($this->FORM_NAME) ? str_replace('.php', '', $this->page_name) : $this->FORM_NAME; - $this->DATA['FORM_ACTION'] = $this->FORM_ACTION; + $this->DATA['FORM_ACTION'] = empty($this->FORM_ACTION) ? + '' : + $this->FORM_ACTION; // special for admin if ($admin_call === true) { // depreacte call globals cms on null 4mcs @@ -735,7 +737,7 @@ class SmartyExtend extends \Smarty } // html title // set local page title - $this->HEADER['HTML_TITLE'] = !$this->L_TITLE ? + $this->HEADER['HTML_TITLE'] = empty($this->L_TITLE) ? ucfirst(str_replace('_', ' ', \CoreLibs\Get\System::getPageName(1))) . (!empty($set_g_title) ? '-' . $this->l10n->__($set_g_title) : '') : $this->l10n->__($this->L_TITLE);