@@ -501,6 +501,19 @@ function weekStart(int $time = null):int {
501501 return dayStart ($ start );
502502}
503503
504+ /**
505+ * время начала текущей недели по UTC
506+ *
507+ * @param int|null $time
508+ *
509+ * @return int
510+ */
511+ function weekStartOnGreenwich ():int {
512+
513+ $ datetime = (new \DateTime ())->setTimezone (new \DateTimeZone ("UTC " ));
514+ return $ datetime ->modify ("Monday this week " )->getTimestamp ();
515+ }
516+
504517/**
505518 * время начала текущего месяца
506519 *
@@ -1154,6 +1167,29 @@ function obfuscateFullName(string $full_name):string {
11541167 return implode (" " , $ obfuscated_parts );
11551168}
11561169
1170+ /**
1171+ * Универсальняа функция для скрытия слов в строке
1172+ */
1173+ function obfuscateWords (string $ string , int $ visible_count = 1 ):string {
1174+
1175+ $ string_length = mb_strlen ($ string );
1176+
1177+ $ delimiter = " " ;
1178+ $ words = explode ($ delimiter , $ string );
1179+
1180+ $ output = (string ) array_reduce ($ words , static function (string $ output , string $ word ) use ($ visible_count , $ delimiter ) {
1181+
1182+ $ length = mb_strlen ($ word );
1183+ $ hidden_count = $ length - ($ visible_count * 2 );
1184+
1185+ return $ output . mb_substr ($ word , 0 , $ visible_count )
1186+ . ($ hidden_count < 0 ? "" : str_repeat ('* ' , $ hidden_count ))
1187+ . mb_substr ($ word , ($ visible_count * -1 ), $ visible_count ) . $ delimiter ;
1188+ }, "" );
1189+
1190+ return mb_substr ($ output , 0 , $ string_length );
1191+ }
1192+
11571193/**
11581194 * вернуть массив отсортированный в едином формате для создания подписи
11591195 *
@@ -1412,13 +1448,19 @@ function inHtml(string $html, string $str):bool {
14121448 *
14131449 * @return string
14141450 */
1415- function generateRandomString (int $ length = 10 ):string {
1451+ function generateRandomString (int $ length = 10 , bool $ with_special_characters = false ):string {
1452+
1453+ $ characters = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ " ;
1454+ $ special_characters = "!@#$%^&*() " ;
1455+
1456+ if ($ with_special_characters ) {
1457+ $ characters .= $ special_characters ;
1458+ }
14161459
1417- $ characters = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ " ;
14181460 $ charactersLength = strlen ($ characters );
14191461 $ randomString = "" ;
14201462 for ($ i = 0 ; $ i < $ length ; $ i ++) {
1421- $ randomString .= $ characters [rand (0 , $ charactersLength - 1 )];
1463+ $ randomString .= $ characters [random_int (0 , $ charactersLength - 1 )];
14221464 }
14231465
14241466 return $ randomString ;
@@ -2349,11 +2391,11 @@ function checkGuid(string $value):bool {
23492391function matchUuid (int $ version_uuid ):string {
23502392
23512393 return match ($ version_uuid ) {
2352- 1 => "/^[0-9A-F]{8}-[0-9A-F]{4}-[1][0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/ " ,
2353- 2 => "/^[0-9A-F]{8}-[0-9A-F]{4}-[2][0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/ " ,
2354- 3 => "/^[0-9A-F]{8}-[0-9A-F]{4}-[3][0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/ " ,
2355- 4 => "/^[0-9a-f]{8}-[0-9a-f]{4}-[4][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/ " ,
2356- 5 => "/^[0-9A-F]{8}-[0-9A-F]{4}-[5][0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i " ,
2394+ 1 => "/^[0-9A-F]{8}-[0-9A-F]{4}-[1][0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/ " ,
2395+ 2 => "/^[0-9A-F]{8}-[0-9A-F]{4}-[2][0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/ " ,
2396+ 3 => "/^[0-9A-F]{8}-[0-9A-F]{4}-[3][0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/ " ,
2397+ 4 => "/^[0-9a-f]{8}-[0-9a-f]{4}-[4][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/ " ,
2398+ 5 => "/^[0-9A-F]{8}-[0-9A-F]{4}-[5][0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i " ,
23572399 default => throw new cs_InvalidUuidVersionException (),
23582400 };
23592401}
0 commit comments