From 8de52623465245375075410e5c14e36c1df1f621 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Wed, 2 Dec 2020 04:12:48 +0100 Subject: [PATCH] Continued: - moved away from monolithic BaseFrameworkSystem to proper classes MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../classes/class_BaseFrameworkSystem.php | 49 ------------------- .../utils/number/class_NumberUtils.php | 28 +++++++++++ .../utils/string/class_StringUtils.php | 21 ++++++++ 3 files changed, 49 insertions(+), 49 deletions(-) diff --git a/framework/main/classes/class_BaseFrameworkSystem.php b/framework/main/classes/class_BaseFrameworkSystem.php index 5a5cb97a..43146fc0 100644 --- a/framework/main/classes/class_BaseFrameworkSystem.php +++ b/framework/main/classes/class_BaseFrameworkSystem.php @@ -1044,55 +1044,6 @@ Loaded includes: return self::$hashLength; } - /** - * Checks whether the given number is really a number (only chars 0-9). - * - * @param $num A string consisting only chars between 0 and 9 - * @param $castValue Whether to cast the value to double. Do only use this to secure numbers from Requestable classes. - * @param $assertMismatch Whether to assert mismatches - * @return $ret The (hopefully) secured numbered value - */ - public function bigintval ($num, $castValue = true, $assertMismatch = false) { - // Filter all numbers out - $ret = preg_replace('/[^0123456789]/', '', $num); - - // Shall we cast? - if ($castValue === true) { - // Cast to biggest numeric type - $ret = (double) $ret; - } - - // Assert only if requested - if ($assertMismatch === true) { - // Has the whole value changed? - assert(('' . $ret . '' != '' . $num . '') && (!is_null($num))); - } - - // Return result - return $ret; - } - - /** - * Checks whether the given hexadecimal number is really a hex-number (only chars 0-9,a-f). - * - * @param $num A string consisting only chars between 0 and 9 - * @param $assertMismatch Whether to assert mismatches - * @return $ret The (hopefully) secured hext-numbered value - */ - public function hexval ($num, $assertMismatch = false) { - // Filter all numbers out - $ret = preg_replace('/[^0123456789abcdefABCDEF]/', '', $num); - - // Assert only if requested - if ($assertMismatch === true) { - // Has the whole value changed? - assert(('' . $ret . '' != '' . $num . '') && (!is_null($num))); - } - - // Return result - return $ret; - } - /** * Determines if an element is set in the generic array * diff --git a/framework/main/classes/utils/number/class_NumberUtils.php b/framework/main/classes/utils/number/class_NumberUtils.php index 29afa81f..96d654aa 100644 --- a/framework/main/classes/utils/number/class_NumberUtils.php +++ b/framework/main/classes/utils/number/class_NumberUtils.php @@ -107,4 +107,32 @@ final class NumberUtils extends BaseFrameworkSystem { return $readable; } + /** + * Checks whether the given number is really a number (only chars 0-9). + * + * @param $num A string consisting only chars between 0 and 9 + * @param $castValue Whether to cast the value to double. Do only use this to secure numbers from Requestable classes. + * @param $assertMismatch Whether to assert mismatches + * @return $ret The (hopefully) secured numbered value + */ + public static function bigintval (string $num, bool $castValue = true, bool $assertMismatch = false) { + // Filter all numbers out + $ret = preg_replace('/[^0123456789]/', '', $num); + + // Shall we cast? + if ($castValue === true) { + // Cast to biggest numeric type + $ret = (double) $ret; + } + + // Assert only if requested + if ($assertMismatch === true) { + // Has the whole value changed? + assert(('' . $ret . '' != '' . $num . '') && (!is_null($num))); + } + + // Return result + return $ret; + } + } diff --git a/framework/main/classes/utils/string/class_StringUtils.php b/framework/main/classes/utils/string/class_StringUtils.php index d895d191..e6c4c738 100644 --- a/framework/main/classes/utils/string/class_StringUtils.php +++ b/framework/main/classes/utils/string/class_StringUtils.php @@ -422,4 +422,25 @@ final class StringUtils extends BaseFrameworkSystem { return $packed; } + /** + * Checks whether the given hexadecimal number is really a hex-number (only chars 0-9,a-f). + * + * @param $num A string consisting only chars between 0 and 9 + * @param $assertMismatch Whether to assert mismatches + * @return $ret The (hopefully) secured hext-numbered value + */ + public static function hexval (string $num, bool $assertMismatch = false) { + // Filter all numbers out + $ret = preg_replace('/[^0123456789abcdefABCDEF]/', '', $num); + + // Assert only if requested + if ($assertMismatch === true) { + // Has the whole value changed? + assert(('' . $ret . '' != '' . $num . '') && (!is_null($num))); + } + + // Return result + return $ret; + } + } -- 2.39.5