diff --git a/src/bootstrap/main.php b/src/bootstrap/main.php index 1a96c66..4937de6 100644 --- a/src/bootstrap/main.php +++ b/src/bootstrap/main.php @@ -10,13 +10,6 @@ declare(strict_types=1); namespace CodeHydrater\bootstrap; -// Polyfill for PHP 4 to 7 -if (!function_exists('str_contains')) { - function str_contains($haystack, $needle) { - return $needle !== '' && mb_strpos($haystack, $needle) !== false; - } -} - $mem_baseline = memory_get_usage(); require_once CodeHydrater_FRAMEWORK . 'bootstrap/errors.php'; @@ -120,9 +113,9 @@ final class configure { return; } if ($key === false) { - common::wipe(self::$config[strtolower($name)]); + \CodeHydrater\common::wipe(self::$config[strtolower($name)]); } - common::wipe(self::$config[strtolower($name)][strtolower($key)]); + \CodeHydrater\common::wipe(self::$config[strtolower($name)][strtolower($key)]); } public static function load_array(array $a): void { @@ -268,7 +261,6 @@ final class di { // Initialize our Dependency Injector registry::set('di', new di()); -require_once CodeHydrater_FRAMEWORK . 'bootstrap/common.php'; require_once CodeHydrater_FRAMEWORK . 'bootstrap/requires.php'; require_once CodeHydrater_FRAMEWORK . 'bootstrap/auto_loader.php'; diff --git a/src/bootstrap/requires.php b/src/bootstrap/requires.php index 857dd38..13810b4 100644 --- a/src/bootstrap/requires.php +++ b/src/bootstrap/requires.php @@ -10,8 +10,6 @@ declare(strict_types=1); namespace CodeHydrater\bootstrap; -use CodeHydrater\bootstrap\common; - enum UseDir: string { case FIXED = "Fixed"; case FRAMEWORK = "Framework"; @@ -94,7 +92,19 @@ final class requires { $dir = escapeshellcmd($realpath); return (file_exists($dir)) ? $dir : false; } - + + private static function string_last_position(string $string, string $needle, int $offset = 0, $encoding = null) { + return (extension_loaded('mbstring')) ? mb_strrpos($string, $needle, $offset, $encoding) : strrpos($string, $needle, $offset); + } + + private static function string_sub_part(string $string, int $offset = 0, int $length = null, $encoding = null) { + if ($length === null) { + return (extension_loaded('mbstring')) ? mb_substr($string, $offset,mb_strlen($string), $encoding) : substr($string, $offset, strlen($string)); + } else { + return (extension_loaded('mbstring')) ? mb_substr($string, $offset, $length, $encoding) : substr($string, $offset, $length); + } + } + /** * @return Cleaned FileName or False */ @@ -108,14 +118,14 @@ final class requires { if (empty($file)) { return false; } - - $pos = common::string_last_position($file, "."); - if ($pos === false) { + $pos_last_occurrence = self::string_last_position($file, "."); + if ($pos_last_occurrence === false) { $file_type = ".php"; $file_name = $file; } else { - $file_name = common::get_string_left($file, $pos); - $file_kind = common::get_string_right($file, common::string_length($file) - $pos); + $file_name = self::string_sub_part($file, 0, $pos_last_occurrence); + // Keep offset negitive, to get file kind... + $file_kind = self::string_sub_part($file, -(strlen($file) - $pos_last_occurrence)); $file_type = match ($file_kind) { ".twig" => ".twig", ".tpl" => ".tpl", diff --git a/src/bootstrap/safer_io.php b/src/bootstrap/safer_io.php index 5fe86e3..e2b9307 100644 --- a/src/bootstrap/safer_io.php +++ b/src/bootstrap/safer_io.php @@ -94,6 +94,10 @@ final class safer_io { self::$DATA_INPUTS[$var_name] : null; } + private static function get_count($i): int { + return (is_array($i) || is_object($i)) ? count($i) : 0; + } + public static function grab_all_post_data( int $bytes_limit = 650000, int $max_params = 400 @@ -276,7 +280,7 @@ final class safer_io { if (is_string($item)) { return trim($item); } - if (\bs_tts\common::get_count($data)) { + if (self::get_count($data)) { $ret = []; foreach($data as $text) { if (is_bool($text) || is_int($text)) { @@ -396,7 +400,7 @@ final class safer_io { private static function get_safer_html($data, use_io $a) { if (is_string($data)) { return self::get_safer_string($data, $a); - } else if (common::get_count($data)) { + } else if (self::get_count($data)) { $ret = []; foreach($data as $text) { if (is_bool($text) || is_int($text)) { @@ -492,7 +496,7 @@ final class safer_io { if ($field_type == FIELD_FILTER::raw_string || $field_type == FIELD_FILTER::raw ) { - if (common::get_count($safer_data)) { + if (self::get_count($safer_data)) { $safer_data = $safer_data[0]; } } diff --git a/src/classes/app.php b/src/classes/app.php index c07262e..7ace2c6 100644 --- a/src/classes/app.php +++ b/src/classes/app.php @@ -22,7 +22,7 @@ class app { $dot_position = strpos($route, '.'); if ($dot_position !== false) { $offset = strlen($route) - $dot_position; - $ext = \CodeHydrater\bootstrap\common::get_string_right($route, $offset); + $ext = common::get_string_right($route, $offset); if ($ext === ".php") { $this->local404(); } diff --git a/src/classes/arrays/mocking/phone.php b/src/classes/arrays/mocking/phone.php index c74d34c..02be232 100644 --- a/src/classes/arrays/mocking/phone.php +++ b/src/classes/arrays/mocking/phone.php @@ -10,7 +10,7 @@ class phone { const AREACODES = [201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 212, 213, 214, 215, 216, 217, 218, 219, 220, 224, 225, 226, 228, 229, 231, 234, 236, 239, 240, 242, 246, 248, 249, 250, 251, 252, 253, 254, 256, 260, 262, 264, 267, 268, 269, 270, 272, 276, 281, 284, 289, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 312, 313, 314, 315, 316, 317, 318, 319, 320, 321, 323, 325, 330, 331, 334, 336, 337, 339, 340, 343, 345, 346, 347, 351, 352, 360, 361, 364, 365, 380, 385, 386, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 412, 413, 414, 415, 416, 417, 418, 419, 423, 424, 425, 430, 431, 432, 434, 435, 437, 438, 440, 441, 442, 443, 450, 458, 469, 470, 473, 475, 478, 479, 480, 484, 501, 502, 503, 504, 505, 506, 507, 508, 509, 510, 512, 513, 514, 515, 516, 517, 518, 519, 520, 530, 531, 534, 539, 540, 541, 548, 551, 559, 561, 562, 563, 567, 570, 571, 573, 574, 575, 579, 580, 581, 585, 586, 587, 601, 602, 603, 604, 605, 606, 607, 608, 609, 610, 612, 613, 614, 615, 616, 617, 618, 619, 620, 623, 626, 628, 629, 630, 631, 636, 639, 641, 646, 647, 649, 650, 651, 657, 660, 661, 662, 664, 667, 669, 670, 671, 678, 681, 682, 684, 701, 702, 703, 704, 705, 706, 707, 708, 709, 712, 713, 714, 715, 716, 717, 718, 719, 720, 721, 724, 725, 727, 731, 732, 734, 737, 740, 743, 747, 754, 757, 758, 760, 762, 763, 765, 767, 769, 770, 772, 773, 774, 775, 778, 779, 780, 781, 782, 784, 785, 786, 787, 801, 802, 803, 804, 805, 806, 807, 808, 809, 810, 812, 813, 814, 815, 816, 817, 818, 819, 825, 828, 829, 830, 831, 832, 843, 845, 847, 848, 849, 850, 854, 856, 857, 858, 859, 860, 862, 863, 864, 865, 867, 868, 869, 870, 872, 873, 876, 878, 901, 902, 903, 904, 905, 906, 907, 908, 909, 910, 912, 913, 914, 915, 916, 917, 918, 919, 920, 925, 928, 929, 930, 931, 934, 936, 937, 938, 939, 940, 941, 947, 949, 951, 952, 954, 956, 959, 970, 971, 972, 973, 978, 979, 980, 984, 985, 989]; private static function rnd_a(array $a) { - $array_count = \CodeHydrater\bootstrap\common::get_count($a); + $array_count = \CodeHydrater\common::get_count($a); return $a[rand(0, $array_count - 1)]; } diff --git a/src/classes/assets.php b/src/classes/assets.php index 48b6e9b..6723cc1 100644 --- a/src/classes/assets.php +++ b/src/classes/assets.php @@ -35,10 +35,10 @@ final class assets { if ($path === null || $path === '') { return false; } - if (bootstrap\common::get_string_left($path, strlen($open_base_dir_path)) == $open_base_dir_path) { + if (common::get_string_left($path, strlen($open_base_dir_path)) == $open_base_dir_path) { return false; } - if (bootstrap\common::get_string_left($path, 1) == '/') { + if (common::get_string_left($path, 1) == '/') { return true; } return false; @@ -100,7 +100,7 @@ final class assets { * @retval boolean|string false is not found, else Asset REF */ public static function wrap_asset(string $file, string $scope = 'project') { - $scope = bootstrap\common::string_to_lowercase($scope); + $scope = \CodeHydrater\strings\string_facade::strtolower($scope); if ($scope === 'cdn') { $proto = bootstrap\safer_io::get_clean_server_var('SERVER_PROTOCOL'); if ($proto === null) { @@ -108,7 +108,7 @@ final class assets { } else { $protocol = strtolower(substr($proto, 0, strpos($proto, '/'))) . '://'; } - return (bootstrap\common::is_string_found($file, '://') === true) ? $file : $protocol . $file; + return (common::is_string_found($file, '://') === true) ? $file : $protocol . $file; } if ($scope === 'project' || $scope === 'app') { $path = PROJECT_ASSETS_DIR . "/"; @@ -129,7 +129,7 @@ final class assets { * @return string|bool */ private static function project_paths(string $file, string $scope = 'project'): string | bool { - $scope = bootstrap\common::string_to_lowercase($scope); + $scope = \CodeHydrater\strings\string_facade::strtolower($scope); if ($scope === 'cdn') { return ""; } else if ($scope === 'project' || $scope === 'app') { @@ -214,7 +214,7 @@ final class assets { $safe_path = security::filter_uri($path); $safe_file = security::filter_uri($file); - if (bootstrap\common::is_string_found($safe_file, '.auto.js')) { + if (common::is_string_found($safe_file, '.auto.js')) { $production = (bootstrap\is_live()); $safe_file = str_replace('.auto.js', '', $safe_file); if ( $production && file_exists($safe_path . $safe_file . '.min.js') ) { @@ -223,7 +223,7 @@ final class assets { return (file_exists($safe_path . $safe_file . '.js')) ? $safe_file . '.js' : false; } - if (bootstrap\common::is_string_found($safe_file, '.auto.css')) { + if (common::is_string_found($safe_file, '.auto.css')) { $production = (bootstrap\is_live()); $safe_file = str_replace('.auto.css', '', $safe_file); if ( $production && file_exists($safe_path . $safe_file . '.min.css') ) { diff --git a/src/bootstrap/common.php b/src/classes/common.php similarity index 74% rename from src/bootstrap/common.php rename to src/classes/common.php index dc7b464..287c010 100644 --- a/src/bootstrap/common.php +++ b/src/classes/common.php @@ -8,7 +8,8 @@ declare(strict_types=1); * @license MIT */ -namespace CodeHydrater\bootstrap; +namespace CodeHydrater; +use CodeHydrater\strings\string_facade as F; final class common { @@ -21,32 +22,39 @@ final class common { } /** - * + * @todo add object checking... * @param type $ret option to check for false error condition * @return bool true if false/error found */ public static function is_error($ret): bool { - $lr = self::string_to_lowercase(trim($ret)); - return ($ret === false || $lr === 'false') ? true : false; + if ($ret === false) { + return true; + } + if (is_string($ret)) { + $lr = F::strtolower(F::trim($ret)); + return ($lr === 'false') ? true : false; + } + throw new \Exception("Unknown state of on error"); } public static function return_bool_as_yes_no(bool $b_data): string { return ($b_data) ? 'y' : 'n'; // if true=y, else =n } - public static function get_bool($bool, $throw = true): bool { + public static function get_bool($bool, $throw = true): ?bool { if (is_bool($bool)) { return $bool; } if (is_string($bool)) { - $bool = self::string_to_lowercase(trim($bool)); + $bool = F::strtolower(F::trim($bool)); } switch ($bool) { + case ':null': + case null: + return null; case '0': case 'false': case ':false': - case ':null': - case null: case 'no': case 'n': case 'disable': @@ -74,50 +82,17 @@ final class common { } // Begin Strings Functions here:: - - public static function string_to_lowercase(string $string, $encoding = null): string { - if (null === $encoding) { - $encoding = mb_internal_encoding(); - } - - return (extension_loaded('mbstring')) ? mb_strtolower($string, $encoding) : strtolower($string); - } - - public static function string_to_uppercase(string $string, $encoding = null): string { - if (null === $encoding) { - $encoding = mb_internal_encoding(); - } - - return (extension_loaded('mbstring')) ? mb_strtoupper($string, $encoding) : strtoupper($string); - } - - public static function string_length(string $string, $encoding = null) { - if (null === $encoding) { - $encoding = mb_internal_encoding(); - } - - return (extension_loaded('mbstring')) ? mb_strlen($string, $encoding) : strlen($string); - } - public static function string_position(string $string, string $needle, int $offset = 0, $encoding = null) { - if (null === $encoding) { - $encoding = mb_internal_encoding(); - } - - return (extension_loaded('mbstring')) ? mb_strpos($string, $needle, $offset, $encoding) : strpos($string, $needle, $offset); + return F::strpos($string, $needle, $offset); } public static function string_last_position(string $string, string $needle, int $offset = 0, $encoding = null) { - if (null === $encoding) { - $encoding = mb_internal_encoding(); - } - - return (extension_loaded('mbstring')) ? mb_strrpos($string, $needle, $offset, $encoding) : strrpos($string, $needle, $offset); + return F::strrpos($string, $needle, $offset); } public static function string_trim($string, $charlist = null) { if (is_null($charlist)) { - return trim($string); + return F::trim($string); } else { $charlist = preg_quote($charlist, '/'); return preg_replace("/(^[$charlist]+)|([$charlist]+$)/us", '', $string); @@ -126,7 +101,7 @@ final class common { public static function string_rtrim($string, $charlist = null) { if (is_null($charlist)) { - return rtrim($string); + return F::rtrim($string); } else { $charlist = preg_quote($charlist, '/'); return preg_replace("/([$charlist]+$)/us", '', $string); @@ -135,7 +110,7 @@ final class common { public static function string_ltrim($string, $charlist = null) { if (is_null($charlist)) { - return ltrim($string); + return F::ltrim($string); } else { $charlist = preg_quote($charlist, '/'); return preg_replace("/(^[$charlist]+)/us", '', $string); @@ -143,10 +118,7 @@ final class common { } public static function string_cmp($str1, $str2, $encoding = null) { - if (null === $encoding) { - $encoding = mb_internal_encoding(); - } - return strcmp(mb_strtoupper($str1, $encoding), mb_strtoupper($str2, $encoding)); + return strcmp(F::strtoupper($str1, $encoding), F::strtoupper($str2, $encoding)); } /* @@ -154,22 +126,14 @@ final class common { */ public static function string_first_position(string $string, string $needle, int $offset = 0, $encoding = null) { - if (null === $encoding) { - $encoding = mb_internal_encoding(); - } - - return (extension_loaded('mbstring')) ? mb_stripos($string, $needle, $offset, $encoding) : stripos($string, $needle, $offset); + return F::stripos($string, $needle, $offset); } public static function string_sub_part(string $string, int $offset = 0, int $length = null, $encoding = null) { - if (null === $encoding) { - $encoding = mb_internal_encoding(); - } - if ($length === null) { - return (extension_loaded('mbstring')) ? mb_substr($string, $offset, self::string_length($string), $encoding) : substr($string, $offset, strlen($string)); + return F::substr($string, $offset, strlen($string)); } else { - return (extension_loaded('mbstring')) ? mb_substr($string, $offset, $length, $encoding) : substr($string, $offset, $length); + return F::substr($string, $offset, $length); } } @@ -204,7 +168,7 @@ final class common { } } - /** + /** * Will get only the right part of string by length. * @param string $str * @param int $length diff --git a/src/classes/database/model.php b/src/classes/database/model.php index 5de15dd..400190c 100644 --- a/src/classes/database/model.php +++ b/src/classes/database/model.php @@ -88,12 +88,12 @@ class model { foreach(SafeIO::db_sanitize($input) as $data) { $key = $data['name'] ?? false; $value = $data['db'] ?? null; - $error_count = (isset($data['errors'])) ? \CodeHydrater\bootstrap\common::get_count($data['errors']) : 0; + $error_count = (isset($data['errors'])) ? \CodeHydrater\common::get_count($data['errors']) : 0; if ($error_count) { return false; } - if (isset($data['meta']['missing']) && \CodeHydrater\bootstrap\common::get_count($data['meta']['missing'])) { + if (isset($data['meta']['missing']) && \CodeHydrater\common::get_count($data['meta']['missing'])) { $this->missing = $data['meta']['missing']; } @@ -362,11 +362,11 @@ class model { $safe_key = addslashes($key); $parm = ($bind) ? ":{$safe_text}" : "'{$safe_text}'"; $ret = "HEX(AES_ENCRYPT($parm},'{$safe_key}'))"; - \CodeHydrater\bootstrap\common::wipe($key); - \CodeHydrater\bootstrap\common::wipe($safe_key); - \CodeHydrater\bootstrap\common::wipe($data); - \CodeHydrater\bootstrap\common::wipe($safe_text); - \CodeHydrater\bootstrap\common::wipe($parm); + \CodeHydrater\common::wipe($key); + \CodeHydrater\common::wipe($safe_key); + \CodeHydrater\common::wipe($data); + \CodeHydrater\common::wipe($safe_text); + \CodeHydrater\scommon::wipe($parm); return $ret; } diff --git a/src/classes/html_document.php b/src/classes/html_document.php index f70ef9a..bd6920e 100644 --- a/src/classes/html_document.php +++ b/src/classes/html_document.php @@ -38,7 +38,7 @@ class html_document { $this->description = bootstrap\configure::get('html', 'description') ?? ''; $this->robots = bootstrap\configure::get('html', 'robots'); $css = bootstrap\configure::get('html', 'css'); - if (bootstrap\common::get_count($css) > 0) { + if (common::get_count($css) > 0) { foreach($css as $file=>$path) { if (is_array($file)) continue; if (is_array($path)) { @@ -55,7 +55,7 @@ class html_document { } } $js = bootstrap\configure::get('html', 'javascript'); - if (bootstrap\common::get_count($js) >0) { + if (common::get_count($js) >0) { foreach($js as $file=>$path) { if (is_array($file)) continue; if (is_array($path)) { diff --git a/src/classes/memory_usage.php b/src/classes/memory_usage.php index 4703d36..b7978ef 100644 --- a/src/classes/memory_usage.php +++ b/src/classes/memory_usage.php @@ -29,7 +29,7 @@ final class memory_usage { public static function get_memory_stats($echo = true) { global $mem_baseline; - $check = bootstrap\common::get_bool(misc::request_var('debug')); + $check = common::get_bool(misc::request_var('debug')); if ($check || defined('DEBUG') && DEBUG === true) { $now_mem = memory_get_usage(); diff --git a/src/classes/misc.php b/src/classes/misc.php index 7b13fc9..bc90cb8 100644 --- a/src/classes/misc.php +++ b/src/classes/misc.php @@ -50,7 +50,7 @@ final class misc { if ($var === null || $var2 === null) { return false; } - return (bootstrap\common::string_to_lowercase(trim($var)) === bootstrap\common::string_to_lowercase(trim($var2))); + return (\CodeHydrater\strings\string_facade::strtolower(\CodeHydrater\strings\string_facade::trim($var)) === \CodeHydrater\strings\string_facade::strtolower(\CodeHydrater\strings\string_facade::trim($var2))); } /** @@ -59,7 +59,7 @@ final class misc { * @retval string */ public static function safe_lowercase_trim(string $var): string { - return (bootstrap\common::string_to_lowercase(trim($var))); + return (\CodeHydrater\strings\string_facade::strtolower(\CodeHydrater\strings\string_facade::trim($var))); } /** @@ -284,8 +284,8 @@ final class misc { $dot_position = strpos($method, '.'); if ($dot_position !== false) { $offset = strlen($method) - $dot_position; - $ext = \CodeHydrater\bootstrap\common::get_string_right($method, $offset); - $method = \CodeHydrater\bootstrap\common::get_string_left($method, $dot_position); + $ext = \CodeHydrater\common::get_string_right($method, $offset); + $method = \CodeHydrater\common::get_string_left($method, $dot_position); } else { $ext = ".html"; } diff --git a/src/classes/random_engine.php b/src/classes/random_engine.php index 1681977..5e3f3ed 100644 --- a/src/classes/random_engine.php +++ b/src/classes/random_engine.php @@ -61,7 +61,7 @@ class random_engine { } private function select_from_array(array $a, int $num ): array { - $array_count = \CodeHydrater\bootstrap\common::get_count($a) - 1; + $array_count = \CodeHydrater\common::get_count($a) - 1; if ($array_count < 1) { return []; } diff --git a/src/classes/services/emailer.php b/src/classes/services/emailer.php index 4200edf..0ae8ff1 100644 --- a/src/classes/services/emailer.php +++ b/src/classes/services/emailer.php @@ -48,7 +48,7 @@ class emailer { $default = (isset($value[0])) ? $value[0] : null; - switch (\CodeHydrater\bootstrap\common::string_to_lowercase($key)) { + switch (strtolower($key)) { case 'to': if (is_array($value)) { $mto = (isset($value['addresses']) && is_array($value['addresses'])) ? $value['addresses'] : false; diff --git a/src/classes/services/encryption.php b/src/classes/services/encryption.php index c1aa907..fffb1c1 100644 --- a/src/classes/services/encryption.php +++ b/src/classes/services/encryption.php @@ -269,11 +269,11 @@ md5-128 0.77 OPENSSL_RAW_DATA, $iv ); - \CodeHydrater\bootstrap\common::wipe($text); - \CodeHydrater\bootstrap\common::wipe($key); - \CodeHydrater\bootstrap\common::wipe($encKey); + \CodeHydrater\common::wipe($text); + \CodeHydrater\common::wipe($key); + \CodeHydrater\common::wipe($encKey); $hmac = hash_hmac($this->default_hash, $iv . $ciphertext, $hmacKey); - \CodeHydrater\bootstrap\common::wipe($hmacKey); + \CodeHydrater\common::wipe($hmacKey); if (! $this->binary) { return (! $this->url_encode) ? base64_encode($hmac . $iv . $ciphertext) : \CodeHydrater\misc::base64url_encode($hmac . $iv . $ciphertext); } else { @@ -312,10 +312,10 @@ md5-128 0.77 OPENSSL_RAW_DATA, $iv ); - \CodeHydrater\bootstrap\common::wipe($ciphertext); - \CodeHydrater\bootstrap\common::wipe($key); - \CodeHydrater\bootstrap\common::wipe($encKey); - \CodeHydrater\bootstrap\common::wipe($keys); + \CodeHydrater\common::wipe($ciphertext); + \CodeHydrater\common::wipe($key); + \CodeHydrater\common::wipe($encKey); + \CodeHydrater\common::wipe($keys); return $ret; } @@ -339,7 +339,7 @@ md5-128 0.77 } $ret = bin2hex(pack('H*', $key)); - \CodeHydrater\bootstrap\common::wipe($key); + \CodeHydrater\common::wipe($key); return $ret; } diff --git a/src/classes/services/log.php b/src/classes/services/log.php index 33204c9..50f160d 100644 --- a/src/classes/services/log.php +++ b/src/classes/services/log.php @@ -43,7 +43,7 @@ final class log { // $success = @touch($file); if ($success === false) { $this->handle = false; - \CodeHydrater\bootstrap\common::dump($file); + \CodeHydrater\common::dump($file); return false; } diff --git a/src/classes/session_management.php b/src/classes/session_management.php index e492546..9837512 100644 --- a/src/classes/session_management.php +++ b/src/classes/session_management.php @@ -68,7 +68,7 @@ final class session_management { if ($rights === false) { return false; } - if (! bootstrap\common::is_json($right)) { + if (! common::is_json($right)) { return false; } $assoc = true; // Use Array format diff --git a/src/classes/strings/mb_string_fns.php b/src/classes/strings/mb_string_fns.php index f303fff..97359ea 100644 --- a/src/classes/strings/mb_string_fns.php +++ b/src/classes/strings/mb_string_fns.php @@ -21,6 +21,10 @@ class mb_string_fns { return strlen($string) !== mb_strlen($string, 'UTF-8'); } + public static function str_contains(string $haystack, string $needle) { + return $needle !== '' && mb_strpos($haystack, $needle) !== false; + } + // Return character by Unicode code point value public static function chr(int $codepoint, ?string $encoding = null): string|false { return mb_chr($codepoint, $encoding); diff --git a/src/classes/strings/string_fns.php b/src/classes/strings/string_fns.php index fb78f8a..bda1753 100644 --- a/src/classes/strings/string_fns.php +++ b/src/classes/strings/string_fns.php @@ -69,8 +69,13 @@ class string_fns { // Check if string contains multibyte characters public static function has_multibyte_chars(string $string) { return (bool) preg_match('/[\xC2-\xDF][\x80-\xBF]|\xE0[\xA0-\xBF][\x80-\xBF]|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}|\xED[\x80-\x9F][\x80-\xBF]|\xF0[\x90-\xBF][\x80-\xBF]{2}|[\xF1-\xF3][\x80-\xBF]{3}|\xF4[\x80-\x8F][\x80-\xBF]{2}/', $string); - } -// Return character by Unicode code point value + } + + public static function str_contains(string $haystack, string $needle) { + return $needle !== '' && strpos($haystack, $needle) !== false; + } + + // Return character by Unicode code point value public static function chr(int $codepoint): string|false { return chr($codepoint); } diff --git a/src/classes/tag_matches.php b/src/classes/tag_matches.php index 20e3a59..1c81130 100644 --- a/src/classes/tag_matches.php +++ b/src/classes/tag_matches.php @@ -23,7 +23,7 @@ const tags_to_check = array('div', 'span', 'form', 'i*', 'a*', 'h1', 'p*'); public static function check_tags(string $page): array { $alert = ''; $output = ''; - $l_page = bootstrap\common::string_to_lowercase($page); + $l_page = \CodeHydrater\strings\string_facade::strtolower($page); unset($page); $assets = "/assets/uikit/css/uikit.gradient.min.css"; @@ -32,7 +32,7 @@ public static function check_tags(string $page): array { $ui_end = ''; foreach (self::tags_to_check as $tag_name) { - if (bootstrap\common::is_string_found($tag_name, '*')) { + if (common::is_string_found($tag_name, '*')) { $tag_name = str_replace('*', '', $tag_name); $otag = "<{$tag_name}>"; // Open Tag $open = substr_count($l_page, $otag); // Count open tags in page diff --git a/src/classes/time_zones.php b/src/classes/time_zones.php index 175ccf2..766193f 100644 --- a/src/classes/time_zones.php +++ b/src/classes/time_zones.php @@ -46,7 +46,7 @@ final class time_zones { } private static function mdy($userTime, $format) { - switch (bootstrap\common::string_to_lowercase($format)) { + switch (\CodeHydrater\strings\string_facade::strtolower($format)) { case 'actions': return $userTime->format('m-d-Y / h:iA'); case 'report': @@ -74,7 +74,7 @@ final class time_zones { } private static function dmy($userTime, $format) { - switch (bootstrap\common::string_to_lowercase($format)) { + switch (\CodeHydrater\strings\string_facade::strtolower($format)) { case 'actions': return $userTime->format('d-m-Y / h:iA'); case 'report': @@ -102,7 +102,7 @@ final class time_zones { } private static function ymd($userTime, $format) { - switch (bootstrap\common::string_to_lowercase($format)) { + switch (\CodeHydrater\strings\string_facade::strtolower($format)) { case 'actions': return $userTime->format('Y-m-d / h:iA'); case 'report': @@ -130,7 +130,7 @@ final class time_zones { } public static function dt_format($userTime, $format, $country) { - switch (bootstrap\common::string_to_lowercase($format)) { + switch (\CodeHydrater\strings\string_facade::strtolower($format)) { case 'object': return $userTime; case 'unix': @@ -171,7 +171,7 @@ final class time_zones { return $userTime->format('Y-m-d H:i:s'); } - switch (bootstrap\common::string_to_lowercase($country)) { + switch (\CodeHydrater\strings\string_facade::strtolower($country)) { case 'china': return self::ymd($userTime, $format); case 'int': diff --git a/src/classes/traits/database/run_sql.php b/src/classes/traits/database/run_sql.php index 87e017c..3bfb2bd 100644 --- a/src/classes/traits/database/run_sql.php +++ b/src/classes/traits/database/run_sql.php @@ -8,7 +8,7 @@ trait run_sql { public function run($sql, $bind=""): int { $pdostmt = $this->pdo->prepare(trim($sql)); - if (\CodeHydrater\bootstrap\common::get_count($bind) > 0) { + if (\CodeHydrater\common::get_count($bind) > 0) { $exec = $pdostmt->execute($bind); } else { $exec = $pdostmt->execute(); diff --git a/src/classes/traits/database/validation.php b/src/classes/traits/database/validation.php index fc0ea23..56d8441 100644 --- a/src/classes/traits/database/validation.php +++ b/src/classes/traits/database/validation.php @@ -17,7 +17,7 @@ trait validation { * @retval bool true valid, false failed tests */ public function validate_mysql(): bool { - $tbl = (\CodeHydrater\bootstrap\common::is_string_found($this->table, "`")) ? $this->table : "`{$this->table}`"; + $tbl = (\CodeHydrater\common::is_string_found($this->table, "`")) ? $this->table : "`{$this->table}`"; foreach ($this->members as $field => $value) { if ($field == $this->primary_key) { continue; @@ -61,7 +61,7 @@ trait validation { case 'NEWDECIMAL': $prec = intval($meta['precision']); $maxlen = $len - $prec; - if (!\CodeHydrater\bootstrap\common::is_string_found($value, '.')) { + if (!\CodeHydrater\common::is_string_found($value, '.')) { $this->do_verr("Failed Validation: No Decimal Found in field {$field}"); return false; } @@ -169,7 +169,7 @@ trait validation { public function is_valid_mysql_date(string $str): bool { $date_parts = explode('-', $str); - if (\CodeHydrater\bootstrap\common::count($date_parts) != 3) + if (\CodeHydrater\common::count($date_parts) != 3) return false; if ((strlen($date_parts[0]) != 4) || (!is_numeric($date_parts[0]))) return false; diff --git a/src/classes/validator.php b/src/classes/validator.php index b450030..b384d7e 100644 --- a/src/classes/validator.php +++ b/src/classes/validator.php @@ -30,7 +30,7 @@ class validator { private static function make_arrays(array $data, $field): array { $dataset = []; if (isset($data[$field])) { - if (bootstrap\common::get_count($data[$field])) { + if (common::get_count($data[$field])) { foreach($data[$field] as $the_data) { $dataset[] = $the_data; } @@ -100,7 +100,7 @@ class validator { private static function is_required(array $data, string $field): bool { if (isset($data[$field])) { - if (bootstrap\common::get_count($data[$field])) { + if (common::get_count($data[$field])) { return false; // Should not be an array here } if (is_string($data[$field])) { diff --git a/src/classes/view.php b/src/classes/view.php index 51ba69f..4b34387 100644 --- a/src/classes/view.php +++ b/src/classes/view.php @@ -222,7 +222,7 @@ final class view { $page_output .= ob_get_clean(); try { - if (bootstrap\common::get_bool(bootstrap\configure::get('CodeHydrater', 'check_HTML_tags')) === true) { + if (common::get_bool(bootstrap\configure::get('CodeHydrater', 'check_HTML_tags')) === true) { $tags = \CodeHydrater\tag_matches::check_tags($page_output); if (! empty($tags['output'])) { $page_output .= $tags['output'];