Skip to content

Commit f2a9df0

Browse files
committed
New version release 1.7.0.0
1 parent 8320b9f commit f2a9df0

28 files changed

+495
-298
lines changed

composer.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@
77
"ext-gd": "*",
88
"ext-mbstring": "*",
99
"ext-pdo": "*",
10-
"ext-pdo_pgsql": "*",
11-
"ext-pdo_mysql": "*",
1210
"ext-pgsql": "*",
1311
"ext-mysqli": "*",
1412
"ext-json": "*",
15-
"microwin7/rcon": "^1.1"
13+
"microwin7/rcon": "^1.1",
14+
"sentry/sentry": "^4.7"
1615
},
1716
"autoload": {
1817
"psr-4": {
@@ -33,7 +32,7 @@
3332
"issues": "https://github.com/microwin7/PHPUtil/issues",
3433
"source": "https://github.com/microwin7/PHPUtil/tree/master"
3534
},
36-
"minimum-stability": "dev",
35+
"minimum-stability": "stable",
3736
"require-dev": {
3837
"vimeo/psalm": "5.x-dev"
3938
}

psalm.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,6 @@
2222
<MixedOperand errorLevel="suppress" />
2323
<UnusedClass errorLevel="suppress" />
2424
<UnusedVariable errorLevel="suppress" />
25+
<DeprecatedClass errorLevel="suppress" />
2526
</issueHandlers>
2627
</psalm>

src/Configs/MainConfig.php

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,38 +7,43 @@
77

88
class MainConfig
99
{
10+
/**
11+
* WEB адресс приложения
12+
* Вид: '<http|https>://<IP|IP:PORT|DOMAIN>/'
13+
* Пример: 'http://127.0.0.1:80/'
14+
* Use Main::getPublicApplicationURL()
15+
*/
16+
protected const string APP_URL = 'http://127.0.0.1:80/';
1017
// Подключение к БД сайта
11-
public const string DB_HOST = 'localhost';
12-
public const string DB_NAME = 'test';
13-
public const string DB_USER = 'test';
14-
public const string DB_PASS = 'test';
15-
public const string DB_PORT = '3306';
18+
protected const string DB_HOST = 'localhost';
19+
protected const string DB_NAME = 'test';
20+
protected const string DB_USER = 'test';
21+
protected const string DB_PASS = 'test';
22+
protected const int DB_PORT = 3306;
1623
/**
1724
* DriverTypeEnum::PDO [SubDBTypeEnum::MySQL, SubDBTypeEnum::PostgreSQL]
18-
* DriverTypeEnum::MySQLi [SubDBTypeEnum::MySQL]
1925
*/
20-
public const DriverTypeEnum DB_DRIVER = DriverTypeEnum::PDO; // MySQLi, PDO | Default: MySQLi
26+
public const DriverTypeEnum DB_DRIVER = DriverTypeEnum::PDO;
2127
/**
22-
* DSN префикс Sub DB для PDO
28+
* DSN префикс Sub DB
2329
* SubDBTypeEnum::MySQL
2430
* SubDBTypeEnum::PostgreSQL
2531
*/
26-
public const SubDBTypeEnum DB_SUD_DB = SubDBTypeEnum::MySQL;
32+
protected const SubDBTypeEnum DB_SUD_DB = SubDBTypeEnum::MySQL;
2733
public const array DB_PDO_OPTIONS = [
2834
\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
2935
\PDO::ATTR_PERSISTENT => true
3036
];
3137
// Префикс БД для SERVERS
32-
public const string DB_PREFIX = 'server_';
38+
protected const string DB_PREFIX_SERVERS = 'server_';
3339
// Запись в файлы лога SQL запросов и их ошибок
34-
public const bool DB_DEBUG = true;
35-
public const string BEARER_TOKEN = '';
36-
public const string PRIVATE_API_KEY = '';
40+
protected const bool DB_DEBUG = true;
41+
protected const string|null BEARER_TOKEN = null;
42+
protected const string PRIVATE_API_KEY = '';
3743
// https://base64.guru/converter/encode/file
38-
protected const string ECDSA256_PUBLIC_KEY_BASE64 = 'MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEJDi51DKs5f6ERSrDDjns00BkI963L9OS9wLA2Ak/nACZCgQma+FsTsbYtZQm4nk+rtabM8b9JgzSi3sPINb8fg==';
39-
protected const string ECDSA256_PUBLIC_KEY_PATH = '';
40-
public const bool SENTRY_ENABLE = false;
41-
public const string SENTRY_DSN = '';
44+
protected const string LAUNCH_SERVER_ECDSA256_PUBLIC_KEY_BASE64 = 'MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEJDi51DKs5f6ERSrDDjns00BkI963L9OS9wLA2Ak/nACZCgQma+FsTsbYtZQm4nk+rtabM8b9JgzSi3sPINb8fg==';
45+
protected const bool SENTRY_ENABLE = false;
46+
protected const string|null SENTRY_DSN = null;
4247

4348
/** @var array<string, array<string, mixed>> */
4449
public const array SERVERS = [

src/Configs/PathConfig.php

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,22 @@
22

33
namespace Microwin7\PHPUtils\Configs;
44

5-
/**
6-
* Use only from WWW Request
7-
* @psalm-suppress PossiblyUndefinedArrayOffset
8-
*/
9-
define("DOCUMENT_ROOT", $_SERVER['DOCUMENT_ROOT'] . '/');
5+
use Microwin7\PHPUtils\Main;
6+
use function Microwin7\PHPUtils\ar_slash_string;
7+
use function Microwin7\PHPUtils\str_ends_with_slash;
108

119
class PathConfig
1210
{
13-
/**
14-
* WEB адресс приложения
15-
* Вид: '<http|https>://<IP|IP:PORT|DOMAIN>/'
16-
* Пример: 'http://127.0.0.1:80/'
17-
*/
18-
public const string APP_URL = 'http://127.0.0.1:80/';
1911
/**
2012
* Укажите root до публичного корня сайта
2113
* Пример: /var/www/html/
2214
*/
23-
public const string ROOT_FOLDER = DOCUMENT_ROOT;
15+
protected const string ROOT_FOLDER = '/var/www/html/';
2416
/**
2517
* Логи БД
2618
*/
27-
public const string DB_LOG_FOLDER = '/var/www/db_logs/';
28-
public const string SITE_TEMPLATES_FOLDER = 'templates/имя_шаблона/';
29-
public const string ITEM_SHOP_IMAGES = self::ROOT_FOLDER . '/' . self::SITE_TEMPLATES_FOLDER . 'images/item_shop/';
30-
public const string URL_ITEM_SHOP_IMAGES = '/' . self::SITE_TEMPLATES_FOLDER . 'images/item_shop/';
19+
protected const string DB_LOG_FOLDER = '/var/www/db_logs/';
20+
# --- OPTIONAL --- #
21+
protected const string SITE_TEMPLATES_FOLDER = 'templates/имя_шаблона/';
22+
protected const string ITEM_SHOP_PATH_IN_TEMPLATES = 'images/item_shop/';
3123
}

src/Configs/TextureConfig.php

Lines changed: 37 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2,63 +2,56 @@
22

33
namespace Microwin7\PHPUtils\Configs;
44

5+
use Microwin7\PHPUtils\Contracts\Texture\Enum\ResponseTypeEnum;
6+
57
class TextureConfig
68
{
7-
/**
8-
* Настройка полного пути хранения файлов
9-
* Пример при склеивании: /var/www/html/storage/skins/
10-
* Если DIRECTORY_SEPARATOR не будет обнаружен в конце, он будет добавлен принудительно
11-
*/
12-
public const string SKIN_PATH = PathConfig::ROOT_FOLDER . self::SKIN_URL_PATH;
13-
public const string CAPE_PATH = PathConfig::ROOT_FOLDER . self::CAPE_URL_PATH;
14-
/**
15-
* Внешние пути хранения файлов, от корня сайта
16-
*/
17-
public const string SKIN_URL_PATH = 'storage/skins/';
18-
public const string CAPE_URL_PATH = 'storage/capes/';
199
/**
2010
* Для вызова, сохранения, проверок
2111
* Может быть пустой строкой, для таких файлов как хеш сумма
2212
* Точка будет добавлена автоматически
2313
*/
24-
public const string EXT = 'png';
25-
/**
26-
* Обвязка для получения по ключу, не менять!!!
27-
*/
28-
public const array TEXTURE_PATH = [
29-
'SKIN' => self::SKIN_PATH,
30-
'CAPE' => self::CAPE_PATH,
31-
];
32-
public const bool LEGACY_DIGEST = false; // Включить при необходимости! Использовать на версии GravitLauncher меньше 5.5.x
33-
/**
34-
* Максимальный размер загружаемого файла
35-
*/
36-
public const int MAX_SIZE_BYTES = 2 * 1024 * 1024; // byte => Kbyte, Kbyte => MB * 2
37-
38-
public const array SIZE = [
39-
'SKIN' => [['w' => 64, 'h' => 64], ['w' => 64, 'h' => 32]],
40-
'CAPE' => [['w' => 64, 'h' => 32]]
41-
];
42-
public const array SIZE_WITH_HD = [
43-
'SKIN' => [
44-
['w' => 128, 'h' => 64], ['w' => 128, 'h' => 128],
45-
['w' => 256, 'h' => 128], ['w' => 256, 'h' => 256],
46-
['w' => 512, 'h' => 256], ['w' => 512, 'h' => 512],
47-
['w' => 1024, 'h' => 512], ['w' => 1024, 'h' => 1024]
48-
],
49-
'CAPE' => [
50-
['w' => 128, 'h' => 64], ['w' => 256, 'h' => 128],
51-
['w' => 512, 'h' => 256], ['w' => 1024, 'h' => 512]
52-
]
53-
];
54-
public const string SKIN_DEFAULT = "iVBORw0KGgoAAAANSUhEUgAAAEAAAAAgCAMAAACVQ462AAAAWlBMVEVHcEwsHg51Ri9qQC+HVTgjIyNO
14+
public const string TEXTURE_EXTENSTION = 'png';
15+
/** Включить при необходимости! Использовать на версии GravitLauncher меньше 5.5.x */
16+
protected const bool LEGACY_DIGEST = false;
17+
/** Максимальный размер загружаемого файла byte => Kbyte, Kbyte => MB * 2 */
18+
protected const int MAX_SIZE_BYTES = 2 * 1024 * 1024;
19+
/** https://base64.guru/converter/encode/image */
20+
protected const string SKIN_DEFAULT = "iVBORw0KGgoAAAANSUhEUgAAAEAAAAAgCAMAAACVQ462AAAAWlBMVEVHcEwsHg51Ri9qQC+HVTgjIyNO
5521
LyK7inGrfWaWb1udZkj///9SPYmAUjaWX0FWScwoKCgAzMwAXl4AqKgAaGgwKHImIVtGOqU6MYkAf38AmpoAr68/Pz9ra2t3xPtNAA
5622
AAAXRSTlMAQObYZgAAAZJJREFUeNrUzLUBwDAUA9EPMsmw/7jhNljl9Xdy0J3t5CndmcOBT4Mw8/8P4pfB6sNg9yA892wQvwzSIr8f
5723
5JRzSeS7AaiptpxazUq8GPQB5uSe2DH644GTsDFsNrqB9CcDgOCAmffegWWwAExnBrljqowsFBuGYShY5oakgOXs/39zF6voDG9r+w
5824
LvTCVUcL+uV4m6uXG/L3Ut691697tgnZgJavinQHOB7DD8awmaLWEmaNuu7YGf6XcIITRm19P1ahbARCRGEc8x/UZ4CroXAQTVIGL0
5925
YySrREBADFGicS8XtG8CTS+IGU2F6EgSE34VNKoNz8348mzoXGDxpxkQBpg2bWobjgZSm+uiKDYH2BAO8C4YBmbgAjpq5jUl4yGJC4
6026
6HQ7HJBfkeTAImIEmgmtpINi44JsHx+CKA/BTuArISXeBTR4AI5gK4C2JqRfPs0HNBkQnG8S4Yxw8IGoIZfXEBOW1D4YJDAdNSXgRe
6127
vP+ylK6fGBCwsWywmA19EtBkJr8K2t4N5pnAVwH0jptsBp+2gUFj4tL5ywAAAABJRU5ErkJggg==";
62-
public const string CAPE_DEFAULT = "iVBORw0KGgoAAAANSUhEUgAAAEAAAAAgAQMAAACYU+zHAAAAA1BMVEVHcEyC+tLSAAAAAXRSTlMAQObY
28+
protected const string CAPE_DEFAULT = "iVBORw0KGgoAAAANSUhEUgAAAEAAAAAgAQMAAACYU+zHAAAAA1BMVEVHcEyC+tLSAAAAAXRSTlMAQObY
6329
ZgAAAAxJREFUeAFjGAV4AQABIAABL3HDQQAAAABJRU5ErkJggg==";
30+
/** @return array<array{w: int, h: int}> */
31+
public static function SIZE(ResponseTypeEnum $type = ResponseTypeEnum::SKIN): array
32+
{
33+
return match ($type) {
34+
ResponseTypeEnum::SKIN => [['w' => 64, 'h' => 64], ['w' => 64, 'h' => 32]],
35+
ResponseTypeEnum::CAPE => [['w' => 64, 'h' => 32]],
36+
default => throw new \InvalidArgumentException(sprintf('Un-supported texture size type: %s', $type->name))
37+
};
38+
}
39+
/** @return array<array{w: int, h: int}> */
40+
public static function SIZE_WITH_HD(ResponseTypeEnum $type = ResponseTypeEnum::SKIN): array
41+
{
42+
return match ($type) {
43+
ResponseTypeEnum::SKIN => [
44+
['w' => 128, 'h' => 64], ['w' => 128, 'h' => 128],
45+
['w' => 256, 'h' => 128], ['w' => 256, 'h' => 256],
46+
['w' => 512, 'h' => 256], ['w' => 512, 'h' => 512],
47+
['w' => 1024, 'h' => 512], ['w' => 1024, 'h' => 1024]
48+
],
49+
ResponseTypeEnum::CAPE => [
50+
['w' => 128, 'h' => 64], ['w' => 256, 'h' => 128],
51+
['w' => 512, 'h' => 256], ['w' => 1024, 'h' => 512]
52+
],
53+
default => throw new \InvalidArgumentException(sprintf('Un-supported texture size type: %s', $type->name))
54+
};
55+
}
56+
6457
}

src/Contracts/Texture/Models/Cape.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
namespace Microwin7\PHPUtils\Contracts\Texture\Models;
66

77
use Microwin7\PHPUtils\Utils\Texture;
8-
use Microwin7\PHPUtils\Configs\TextureConfig;
98
use Microwin7\PHPUtils\Contracts\Texture\Enum\TextureStorageTypeEnum;
109

1110
abstract class Cape implements \JsonSerializable
@@ -19,6 +18,6 @@ public function __construct(
1918
public readonly string $url,
2019
string|null $digest = null,
2120
) {
22-
$this->digest = null !== $digest ? $digest : (TextureConfig::LEGACY_DIGEST ? Texture::digest_legacy($this->data) : Texture::digest($this->data));
21+
$this->digest = null !== $digest ? $digest : (Texture::LEGACY_DIGEST() ? Texture::digest_legacy($this->data) : Texture::digest($this->data));
2322
}
2423
}

src/Contracts/Texture/Models/Skin.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44

55
namespace Microwin7\PHPUtils\Contracts\Texture\Models;
66

7-
use Microwin7\PHPUtils\Configs\TextureConfig;
8-
use Microwin7\PHPUtils\Contracts\Texture\Enum\TextureStorageTypeEnum;
97
use Microwin7\PHPUtils\Utils\Texture;
8+
use Microwin7\PHPUtils\Contracts\Texture\Enum\TextureStorageTypeEnum;
109

1110
abstract class Skin implements \JsonSerializable
1211
{
@@ -20,6 +19,6 @@ public function __construct(
2019
public readonly bool $isSlim,
2120
string|null $digest = null,
2221
) {
23-
$this->digest = null !== $digest ? $digest : (TextureConfig::LEGACY_DIGEST ? Texture::digest_legacy($this->data) : Texture::digest($this->data));
22+
$this->digest = null !== $digest ? $digest : (Texture::LEGACY_DIGEST() ? Texture::digest_legacy($this->data) : Texture::digest($this->data));
2423
}
2524
}

src/DB/Connector.php

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,23 @@
88

99
class Connector
1010
{
11-
/** @var array<string, DriverPDO|DriverMySQLi> */
11+
/** @var array<string, DriverPDO> */
1212
protected array $database = [];
1313

14-
public function __get(string $database): DriverPDO|DriverMySQLi
14+
public function __get(string $database): DriverPDO
1515
{
1616
if (array_key_exists($database, $this->database)) return $this->database[$database];
1717
return $this->getConnect($database);
1818
}
1919

20-
private function getConnect(string $database): DriverPDO|DriverMySQLi
20+
private function getConnect(string $database): DriverPDO
2121
{
2222
$module = [];
23-
if (empty($database) || $database == MainConfig::DB_NAME) $database = MainConfig::DB_NAME;
23+
if (empty($database) || $database == Main::DB_NAME()) $database = Main::DB_NAME();
2424
else {
2525
try {
2626
/** @psalm-suppress RedundantFunctionCall */
27-
$database = strtolower(MainConfig::DB_PREFIX . Main::getServerWithoutDefault($database));
27+
$database = strtolower(Main::DB_PREFIX_SERVERS() . Main::getServerWithoutDefault($database));
2828
} catch (ServerNotFoundException $e) {
2929
$modules_keys_lower_case = array_change_key_case(MainConfig::MODULES);
3030
$key_exists = array_key_exists(strtolower($database), $modules_keys_lower_case);
@@ -38,13 +38,14 @@ private function getConnect(string $database): DriverPDO|DriverMySQLi
3838
}
3939
}
4040
if (array_key_exists($database, $this->database)) return $this->database[$database];
41-
/**
42-
* @var string $module['prefix']
43-
* @psalm-suppress TypeDoesNotContainType
44-
*/
45-
return $this->database[$database] = match (MainConfig::DB_DRIVER) {
46-
DriverTypeEnum::MySQLi => new DriverMySQLi($database, $module['prefix'] ?? ''),
47-
DriverTypeEnum::PDO => new DriverPDO($database, $module['prefix'] ?? ''),
48-
};
41+
return new DriverPDO($database, $module['prefix'] ?? '');
42+
// /**
43+
// * @var string $module['prefix']
44+
// * @psalm-suppress TypeDoesNotContainType
45+
// */
46+
// return $this->database[$database] = match (MainConfig::DB_DRIVER) {
47+
// DriverTypeEnum::MySQLi => new DriverMySQLi($database, $module['prefix'] ?? ''),
48+
// DriverTypeEnum::PDO => new DriverPDO($database, $module['prefix'] ?? ''),
49+
// };
4950
}
5051
}

src/DB/DriverMySQLi.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22

33
namespace Microwin7\PHPUtils\DB;
44

5+
use Microwin7\PHPUtils\Main;
56
use Microwin7\PHPUtils\Utils\DebugDB;
6-
use Microwin7\PHPUtils\Configs\MainConfig;
77
use Microwin7\PHPUtils\Exceptions\DBException;
88

99
/**
1010
* @template-implements \Iterator<int, array>
1111
* @deprecated 1.6.0.12
12+
* @ignore ОТКЛЮЧЕНО
1213
*/
1314
class DriverMySQLi implements \Iterator
1415
{
@@ -27,12 +28,12 @@ class DriverMySQLi implements \Iterator
2728
/** @var list<int> */
2829
private array $unsetKeys = [];
2930

30-
public function __construct(string $database = MainConfig::DB_NAME, string $table_prefix = '')
31+
public function __construct(?string $database = null, string $table_prefix = '')
3132
{
3233
$this->table_prefix = $table_prefix;
33-
$this->database = $database;
34+
$this->database = $database ?? Main::DB_NAME();
3435
$this->debug = new DebugDB;
35-
$this->mysqli = new \mysqli(MainConfig::DB_HOST, MainConfig::DB_USER, MainConfig::DB_PASS, $database, (int)MainConfig::DB_PORT);
36+
$this->mysqli = new \mysqli(Main::DB_HOST(), Main::DB_USER(), Main::DB_PASS(), $database, Main::DB_PORT());
3637
if ($this->mysqli->connect_errno) $this->debug->debug("Connect error: {$this->mysqli->connect_error}");
3738
$this->mysqli->set_charset("utf8");
3839
}
@@ -185,7 +186,7 @@ public function object(): array
185186
* @template T of object
186187
* @param class-string<T> $class
187188
* @param array $constructor_args Аргументы для конструктора передаваемого класса, для заполнения
188-
* @return list<T> Возвращает объекты с параметрами класса как в БД и заполненными добавочными данными из аргументов констркутора класса
189+
* @return list<T>|list<empty> Возвращает объекты с параметрами класса как в БД и заполненными добавочными данными из аргументов констркутора класса
189190
*/
190191
public function objects(string $class = \stdClass::class, array $constructor_args = []): array
191192
{

0 commit comments

Comments
 (0)