diff --git a/4dev/tests/CoreLibsCombinedDateTimeTest.php b/4dev/tests/CoreLibsCombinedDateTimeTest.php index 71fafcb3..67583a34 100644 --- a/4dev/tests/CoreLibsCombinedDateTimeTest.php +++ b/4dev/tests/CoreLibsCombinedDateTimeTest.php @@ -25,26 +25,43 @@ final class CoreLibsCombinedDateTimeTest extends TestCase 'valid timestamp no microtime' => [ 1641515890, false, + false, '2022-01-07 09:38:10', ], 'valid timestamp with microtime' => [ 1641515890, true, + false, + '2022-01-07 09:38:10', + ], + 'valid timestamp with microtime float' => [ + 1641515890, + true, + true, '2022-01-07 09:38:10', ], 'valid micro timestamp with microtime' => [ 1641515890.123456, true, + false, '2022-01-07 09:38:10 1235ms', ], + 'valid micro timestamp with microtime float' => [ + 1641515890.123456, + true, + true, + '2022-01-07 09:38:10.1235', + ], 'valid micro timestamp no microtime' => [ 1641515890.123456, false, + false, '2022-01-07 09:38:10', ], 'invalid timestamp' => [ -123123, false, + false, '1969-12-30 22:47:57', ], ]; @@ -454,11 +471,19 @@ final class CoreLibsCombinedDateTimeTest extends TestCase * @param string $expected * @return void */ - public function testDateStringFormat($input, bool $flag, string $expected): void - { + public function testDateStringFormat( + $input, + bool $flag_show_micro, + bool $flag_micro_as_float, + string $expected + ): void { $this->assertEquals( $expected, - \CoreLibs\Combined\DateTime::dateStringFormat($input, $flag) + \CoreLibs\Combined\DateTime::dateStringFormat( + $input, + $flag_show_micro, + $flag_micro_as_float + ) ); } diff --git a/4dev/tests/CoreLibsCreateUidsTest.php b/4dev/tests/CoreLibsCreateUidsTest.php index c6e12117..1a5fcd9f 100644 --- a/4dev/tests/CoreLibsCreateUidsTest.php +++ b/4dev/tests/CoreLibsCreateUidsTest.php @@ -24,7 +24,15 @@ final class CoreLibsCreateUidsTest extends TestCase 0 => 'sha256', 1 => 64 ], - 'default hash DEFAULT_HASH not set' => [ + 'ripemd160 hash' => [ + 0 => 'ripemd160', + 1 => 40 + ], + 'adler32 hash' => [ + 0 => 'adler32', + 1 => 8 + ], + 'default hash not set' => [ 0 => null, 1 => 64, ], diff --git a/4dev/tests/CoreLibsDebugSupportTest.php b/4dev/tests/CoreLibsDebugSupportTest.php index 069223cc..349ed94a 100644 --- a/4dev/tests/CoreLibsDebugSupportTest.php +++ b/4dev/tests/CoreLibsDebugSupportTest.php @@ -62,6 +62,11 @@ final class CoreLibsDebugSupportTest extends TestCase ]; } + /** + * Undocumented function + * + * @return array + */ public function printToStringProvider(): array { return [ @@ -246,6 +251,24 @@ final class CoreLibsDebugSupportTest extends TestCase ); } + /** + * Undocumented function + * + * @cover ::getCallerMethodList + * @testWith [["main", "run", "run", "run", "run", "run", "run", "runBare", "runTest", "testGetCallerMethodList"]] + * @testdox getCallerMethodList check if it returns $expected [$_dataName] + * + * @param array $expected + * @return void + */ + public function testGetCallerMethodList(array $expected): void + { + $this->assertEquals( + $expected, + \CoreLibs\Debug\Support::getCallerMethodList() + ); + } + /** * Undocumented function * diff --git a/www/admin/class_test.datetime.php b/www/admin/class_test.datetime.php index 80ab868f..23b1b0c1 100644 --- a/www/admin/class_test.datetime.php +++ b/www/admin/class_test.datetime.php @@ -74,8 +74,9 @@ $timestamps = [ -1622788315.456789 ]; foreach ($timestamps as $timestamp) { - print "DATESTRINGFORMAT(sm:0): $timestamp: " . DateTime::dateStringFormat($timestamp) . "
"; - print "DATESTRINGFORMAT(sm:1): $timestamp: " . DateTime::dateStringFormat($timestamp, true) . "
"; + print "DATESTRINGFORMAT(sm:0:0): $timestamp: " . DateTime::dateStringFormat($timestamp) . "
"; + print "DATESTRINGFORMAT(sm:1:0): $timestamp: " . DateTime::dateStringFormat($timestamp, true) . "
"; + print "DATESTRINGFORMAT(sm:1:1): $timestamp: " . DateTime::dateStringFormat($timestamp, true, true) . "
"; } $intervals = [ 788315.123456, diff --git a/www/admin/class_test.debug.php b/www/admin/class_test.debug.php index 340c2383..d5c64b0f 100644 --- a/www/admin/class_test.debug.php +++ b/www/admin/class_test.debug.php @@ -54,8 +54,14 @@ function test() return DebugSupport::getCallerMethod(1); } +function test2() +{ + return DebugSupport::getCallerMethodList(1); +} + print "S::GETCALLERMETHOD: " . DebugSupport::getCallerMethod(0) . "
"; print "S::GETCALLERMETHOD: " . test() . "
"; +print "S::GETCALLERMETHODLIST:
" . print_r(test2(), true) . "

"; print "S::PRINTAR: " . DebugSupport::printAr(['Foo', 'Bar']) . "
"; print "V-S::PRINTAR: " . $debug_support_class::printAr(['Foo', 'Bar']) . "
"; print "S::DEBUSTRING(s): " . DebugSupport::debugString('SET') . "
"; diff --git a/www/lib/CoreLibs/Combined/DateTime.php b/www/lib/CoreLibs/Combined/DateTime.php index ec0838b1..3e3174ce 100644 --- a/www/lib/CoreLibs/Combined/DateTime.php +++ b/www/lib/CoreLibs/Combined/DateTime.php @@ -15,18 +15,26 @@ class DateTime /** * a simple wrapper for the date format * if an invalid timestamp is give zero timestamp unix time is used - * @param int|float $timestamp unix timestamp - * @param bool $show_micro show the micro time (default false) - * @return string formated date+time in Y-M-D h:m:s ms + * @param int|float $timestamp unix timestamp + * @param bool $show_micro show the micro time (default false) + * @param bool $micro_as_float Add the micro time with . instead of ms (default false) + * @return string formated date+time in Y-M-D h:m:s ms */ - public static function dateStringFormat($timestamp, bool $show_micro = false): string - { + public static function dateStringFormat( + $timestamp, + bool $show_micro = false, + bool $micro_as_float = false + ): string { // split up the timestamp, assume . in timestamp // array pad $ms if no microtime list ($timestamp, $ms) = array_pad(explode('.', (string)round($timestamp, 4)), 2, null); $string = date("Y-m-d H:i:s", (int)$timestamp); if ($show_micro && $ms) { - $string .= ' ' . $ms . 'ms'; + if ($micro_as_float == false) { + $string .= ' ' . $ms . 'ms'; + } else { + $string .= '.' . $ms; + } } return $string; } diff --git a/www/lib/CoreLibs/Create/Uids.php b/www/lib/CoreLibs/Create/Uids.php index ef3b5a13..38c3354b 100644 --- a/www/lib/CoreLibs/Create/Uids.php +++ b/www/lib/CoreLibs/Create/Uids.php @@ -7,7 +7,7 @@ namespace CoreLibs\Create; class Uids { // what to use as a default hash if non ise set and no DEFAULT_HASH is defined - private const FALLBACK_HASH = 'sha256'; + public const FALLBACK_HASH = 'sha256'; /** * creates psuedo random uuid v4 @@ -56,15 +56,15 @@ class Uids case 'sha256': $uniq_id = hash('sha256', uniqid((string)rand(), true)); break; + case 'ripemd160': + $uniq_id = hash('ripemd160', uniqid((string)rand(), true)); + break; + case 'adler32': + $uniq_id = hash('adler32', uniqid((string)rand(), true)); + break; default: // fallback to this hash type $hash = self::FALLBACK_HASH; - if ( - defined('DEFAULT_HASH') && - in_array(DEFAULT_HASH, hash_algos()) - ) { - $hash = DEFAULT_HASH; - } $uniq_id = hash($hash, uniqid((string)rand(), true)); break; } diff --git a/www/lib/CoreLibs/Debug/Support.php b/www/lib/CoreLibs/Debug/Support.php index 36b02e6b..b0b02ad6 100644 --- a/www/lib/CoreLibs/Debug/Support.php +++ b/www/lib/CoreLibs/Debug/Support.php @@ -90,6 +90,29 @@ class Support return null; } + /** + * Returns array with all methods in the call stack in the order so that last + * called is last in order + * Will start with start_level to skip unwanted from stack + * Defaults to skip level 0 wich is this methid + * @param integer $start_level From what level on, as defaul starts with 1 + * to exclude self + * @return array All method names in list where max is last called + */ + public static function getCallerMethodList(int $start_level = 1): array + { + $traces = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); + $methods = []; + foreach ($traces as $level => $data) { + if ($level >= $start_level) { + if (!empty($data['function'])) { + array_unshift($methods, $data['function']); + } + } + } + return $methods; + } + /** * Get the current class where this function is called * Is mostly used in debug log statements to get the class where the debug