Skip to content

Commit f3bc5a6

Browse files
Merge pull request #2 from getCompassUtils/release_v2.0.0
Release v2.0.0
2 parents f86e531 + 3bc38ae commit f3bc5a6

File tree

3 files changed

+65
-9
lines changed

3 files changed

+65
-9
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace BaseFrame\Exception\Gateway;
4+
5+
use BaseFrame\Exception\GatewayException;
6+
7+
/**
8+
* Ошибка бизнес-логики в сокет запросе
9+
*/
10+
class DBShardingNotFoundException extends GatewayException {
11+
12+
13+
}

system/functions.php

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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 {
23492391
function 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
}

system/sharding_gateway.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php declare(strict_types=1);
22

33
use BaseFrame\Exception\Domain\ParseFatalException;
4+
use BaseFrame\Exception\Gateway\DBShardingNotFoundException;
45

56
/**
67
* Класс шардинга
@@ -70,7 +71,7 @@ public static function database(string $database):myPDObasic {
7071
$conf = static::instance()->_config_list[static::DB_KEY];
7172

7273
if (!isset($conf[$database])) {
73-
throw new ParseFatalException("database not found in sharding config");
74+
throw new DBShardingNotFoundException("database not found in sharding config");
7475
}
7576

7677
return sharding::configuredPDO($conf[$database]);

0 commit comments

Comments
 (0)