Skip to content

Commit 71fb324

Browse files
committed
Fix for image_shop functions
1 parent c83b5ef commit 71fb324

File tree

5 files changed

+138
-139
lines changed

5 files changed

+138
-139
lines changed

src/Configs/MainConfig.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class MainConfig
1818
'rcon' => [
1919
'enable' => true,
2020
'password' => '',
21+
'port' => 25575,
2122
'timeout' => 3,
2223
],
2324
],
@@ -28,12 +29,21 @@ class MainConfig
2829
'rcon' => [
2930
'enable' => false,
3031
'password' => '',
32+
'port' => 25576,
3133
'timeout' => 3,
3234
],
3335
]
3436
];
3537
/** @var array<string, array<string, string|array<string, string>>> */
3638
public const array MODULES = [
39+
'ItemShop' => [
40+
'DB_NAME' => 'ItemShop',
41+
'prefix' => ''
42+
],
43+
'VoteRewards' => [
44+
'DB_NAME' => 'VoteRewards',
45+
'prefix' => '',
46+
],
3747
'LuckPerms' => [
3848
'DB_NAME' => 'LuckPerms',
3949
'prefix' => 'luckperms_',

src/Utils/Path.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,18 @@ public static function ITEM_SHOP_IMAGES(): string
4949
{
5050
return self::ROOT_FOLDER() . self::SITE_TEMPLATES_FOLDER() . self::ITEM_SHOP_PATH_IN_TEMPLATES();
5151
}
52-
public static function URL_ITEM_SHOP_IMAGES(string $image_name, string $category): string
52+
public static function PATH_URL_ITEM_SHOP_IMAGES(string $server, string $mod_id, string $image_name): string
5353
{
54-
return Main::getApplicationURL() . self::SITE_TEMPLATES_FOLDER() . self::ITEM_SHOP_PATH_IN_TEMPLATES() .
55-
(empty($category) ?: ar_slash_string($category)) .
56-
(empty($image_name) ?: $image_name);
54+
return implode('/', array_map('rawurlencode', explode('/', ar_slash_string(self::SITE_TEMPLATES_FOLDER(), true) . self::ITEM_SHOP_PATH_IN_TEMPLATES() .
55+
($mod_id === 'VANILLA' ? '' : (empty($server) ?: ar_slash_string($server))) .
56+
(empty($mod_id) ?: ar_slash_string($mod_id)) .
57+
(empty($image_name) ?: $image_name))));
58+
}
59+
public static function URL_ITEM_SHOP_IMAGES(string $server, string $mod_id, string $image_name): string
60+
{
61+
return Main::getApplicationURL() . implode('/', array_map('rawurlencode', explode('/', ar_slash_string(self::SITE_TEMPLATES_FOLDER(), true) . self::ITEM_SHOP_PATH_IN_TEMPLATES() .
62+
($mod_id === 'VANILLA' ? '' : (empty($server) ?: ar_slash_string($server))) .
63+
(empty($mod_id) ?: ar_slash_string($mod_id)) .
64+
(empty($image_name) ?: $image_name))));
5765
}
5866
}

src/Utils/Rcon.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function sendRconCommand(string $command, $username = '', $check_correct_
3737
if ($check_correct_server) $this->checkServer();
3838
$rcon = new \Thedudeguy\Rcon(
3939
MainConfig::SERVERS[$this->server]['host'],
40-
MainConfig::SERVERS[$this->server]['port'],
40+
MainConfig::SERVERS[$this->server]['rcon']['port'],
4141
MainConfig::SERVERS[$this->server]['rcon']['password'],
4242
MainConfig::SERVERS[$this->server]['rcon']['timeout'],
4343
);

src/Utils/Regex.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function not_empty(): static
5858
{
5959
return !empty($this->last_data) ? $this : $this->reply();
6060
}
61-
private function preg_match(): static
61+
public function preg_match(): static
6262
{
6363
foreach ($this->pattern as $pattern) {
6464
if (!empty($pattern) && $this->last_data !== null && preg_match($pattern, (string)$this->last_data, $v) !== 1) {

src/functions.php

Lines changed: 114 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -2,159 +2,140 @@
22

33
namespace Microwin7\PHPUtils;
44

5-
if (!function_exists('str_starts_with_slash')) {
6-
function str_starts_with_slash(string $string, bool $needle_starts_with_slash = FALSE): string
7-
{
8-
if (str_starts_with($string, DIRECTORY_SEPARATOR)) {
9-
if (!$needle_starts_with_slash) $string = substr($string, 1);
10-
} else {
11-
if ($needle_starts_with_slash) $string = DIRECTORY_SEPARATOR . $string;
12-
}
13-
return $string;
5+
function str_starts_with_slash(string $string, bool $needle_starts_with_slash = FALSE): string
6+
{
7+
if (str_starts_with($string, DIRECTORY_SEPARATOR)) {
8+
if (!$needle_starts_with_slash) $string = substr($string, 1);
9+
} else {
10+
if ($needle_starts_with_slash) $string = DIRECTORY_SEPARATOR . $string;
1411
}
12+
return $string;
1513
}
16-
if (!function_exists('str_ends_with_slash')) {
17-
function str_ends_with_slash(string $string, bool $needle_ends_with_slash = TRUE): string
18-
{
19-
if (str_ends_with($string, DIRECTORY_SEPARATOR)) {
20-
if (!$needle_ends_with_slash) $string = substr($string, 0, -1);
21-
} else {
22-
if ($needle_ends_with_slash) $string .= DIRECTORY_SEPARATOR;
23-
}
24-
return $string;
14+
function str_ends_with_slash(string $string, bool $needle_ends_with_slash = TRUE): string
15+
{
16+
if (str_ends_with($string, DIRECTORY_SEPARATOR)) {
17+
if (!$needle_ends_with_slash) $string = substr($string, 0, -1);
18+
} else {
19+
if ($needle_ends_with_slash) $string .= DIRECTORY_SEPARATOR;
2520
}
21+
return $string;
2622
}
27-
if (!function_exists('ar_slash_string')) {
28-
function ar_slash_string(string $string, bool $needle_starts_with_slash = FALSE, bool $needle_ends_with_slash = TRUE): string
29-
{
30-
return str_ends_with_slash(str_starts_with_slash($string, $needle_starts_with_slash), $needle_ends_with_slash);
31-
}
23+
function ar_slash_string(string $string, bool $needle_starts_with_slash = FALSE, bool $needle_ends_with_slash = TRUE): string
24+
{
25+
return str_ends_with_slash(str_starts_with_slash($string, $needle_starts_with_slash), $needle_ends_with_slash);
3226
}
33-
if (!function_exists('implodeRecursive')) {
34-
/**
35-
* @param string $separator
36-
* @param string[]|list<string|list<string>> $array
37-
* @return string
38-
*/
39-
function implodeRecursive(string $separator, array $array): string
40-
{
41-
$result = '';
42-
foreach ($array as $value) {
43-
if (is_array($value)) {
44-
$result .= implodeRecursive($separator, $value) . $separator;
45-
} else {
46-
if (strrpos($value, '\\') === false) {
47-
$result .= $value . $separator;
48-
} else if (enum_exists($value)) {
49-
$argumentClazz = new \ReflectionClass($value);
50-
if ($argumentClazz->implementsInterface(\Microwin7\PHPUtils\Contracts\Enum\EnumRequestInterface::class)) {
51-
/**
52-
* @var interface-string<
53-
* \BackedEnum &
54-
* \Microwin7\PHPUtils\Contracts\Enum\EnumInterface &
55-
* \Microwin7\PHPUtils\Contracts\Enum\EnumRequestInterface
56-
* > $enumClass
57-
*/
58-
$enumClass = $value;
59-
$result .= $enumClass::getNameRequestVariable() . $separator;
60-
}
27+
/**
28+
* @param string $separator
29+
* @param string[]|list<string|list<string>> $array
30+
* @return string
31+
*/
32+
function implodeRecursive(string $separator, array $array): string
33+
{
34+
$result = '';
35+
foreach ($array as $value) {
36+
if (is_array($value)) {
37+
$result .= implodeRecursive($separator, $value) . $separator;
38+
} else {
39+
if (strrpos($value, '\\') === false) {
40+
$result .= $value . $separator;
41+
} else if (enum_exists($value)) {
42+
$argumentClazz = new \ReflectionClass($value);
43+
if ($argumentClazz->implementsInterface(\Microwin7\PHPUtils\Contracts\Enum\EnumRequestInterface::class)) {
44+
/**
45+
* @var interface-string<
46+
* \BackedEnum &
47+
* \Microwin7\PHPUtils\Contracts\Enum\EnumInterface &
48+
* \Microwin7\PHPUtils\Contracts\Enum\EnumRequestInterface
49+
* > $enumClass
50+
*/
51+
$enumClass = $value;
52+
$result .= $enumClass::getNameRequestVariable() . $separator;
6153
}
6254
}
6355
}
64-
65-
return rtrim($result, $separator);
6656
}
57+
return rtrim($result, $separator);
6758
}
68-
if (!function_exists('getClassMethodsAllFromDocComment')) {
69-
/**
70-
* @param class-string|object|trait-string $class
71-
*
72-
* @return string[]|null
73-
*/
74-
function getClassMethodsAllFromDocComment(string|object $class): ?array
75-
{
76-
$reflectionClass = new \ReflectionClass($class);
77-
$docComment = $reflectionClass->getDocComment();
78-
if ($docComment !== false) {
79-
preg_match_all('/@method\s+([^\r\n\t\f\v(]+)/', $docComment, $matches);
80-
if (isset($matches[1]) && !empty($matches[1])) {
81-
return $matches[1];
82-
}
59+
/**
60+
* @param class-string|object|trait-string $class
61+
*
62+
* @return string[]|null
63+
*/
64+
function getClassMethodsAllFromDocComment(string|object $class): ?array
65+
{
66+
$reflectionClass = new \ReflectionClass($class);
67+
$docComment = $reflectionClass->getDocComment();
68+
if ($docComment !== false) {
69+
preg_match_all('/@method\s+([^\r\n\t\f\v(]+)/', $docComment, $matches);
70+
if (isset($matches[1]) && !empty($matches[1])) {
71+
return $matches[1];
8372
}
84-
return null;
8573
}
74+
return null;
8675
}
87-
if (!function_exists('getClassMethodsFromAnnotations')) {
88-
/**
89-
* @param class-string|object|trait-string $class
90-
*
91-
* @return string[]
92-
*/
93-
function getClassMethodsFromAnnotations(string|object $class): array
94-
{
95-
$annotations = [];
96-
$methodsDocComment = getClassMethodsAllFromDocComment($class);
97-
if ($methodsDocComment !== null) {
98-
foreach ($methodsDocComment as $v) {
99-
$methodComment = explode(" ", $v);
100-
if (count($methodComment) === 2) {
101-
$annotations[] = $methodComment[1];
102-
}
76+
/**
77+
* @param class-string|object|trait-string $class
78+
*
79+
* @return string[]
80+
*/
81+
function getClassMethodsFromAnnotations(string|object $class): array
82+
{
83+
$annotations = [];
84+
$methodsDocComment = getClassMethodsAllFromDocComment($class);
85+
if ($methodsDocComment !== null) {
86+
foreach ($methodsDocComment as $v) {
87+
$methodComment = explode(" ", $v);
88+
if (count($methodComment) === 2) {
89+
$annotations[] = $methodComment[1];
10390
}
10491
}
105-
return $annotations;
10692
}
93+
return $annotations;
10794
}
108-
if (!function_exists('getClassStaticMethodsFromAnnotations')) {
109-
/**
110-
* @param class-string|object|trait-string $class
111-
*
112-
* @return list<object{'name': string, 'type': string}>
113-
*/
114-
function getClassStaticMethodsFromAnnotations(string|object $class): array
115-
{
116-
$annotations = [];
117-
$methodsDocComment = getClassMethodsAllFromDocComment($class);
118-
if ($methodsDocComment !== null) {
119-
foreach ($methodsDocComment as $v) {
120-
$methodComment = explode(" ", $v);
121-
if (count($methodComment) === 3 && $methodComment[0] === 'static') {
122-
$annotations[] = (object) ['name' => $methodComment[2], 'type' => $methodComment[1]];
123-
}
95+
/**
96+
* @param class-string|object|trait-string $class
97+
*
98+
* @return list<object{'name': string, 'type': string}>
99+
*/
100+
function getClassStaticMethodsFromAnnotations(string|object $class): array
101+
{
102+
$annotations = [];
103+
$methodsDocComment = getClassMethodsAllFromDocComment($class);
104+
if ($methodsDocComment !== null) {
105+
foreach ($methodsDocComment as $v) {
106+
$methodComment = explode(" ", $v);
107+
if (count($methodComment) === 3 && $methodComment[0] === 'static') {
108+
$annotations[] = (object) ['name' => $methodComment[2], 'type' => $methodComment[1]];
124109
}
125110
}
126-
return $annotations;
127111
}
112+
return $annotations;
128113
}
129-
if (!function_exists('minifier')) {
130-
function minifier(string $code): string
131-
{
132-
$search = array(
133-
// Remove whitespaces after tags
134-
'/\>[^\S]+/s',
135-
// Remove whitespaces before tags
136-
'/[^\S]+\</s',
137-
// Remove multiple whitespace sequences
138-
'/(\s)+/s',
139-
// Removes comments
140-
'/<!--(.|\s)*?-->/'
141-
);
142-
$replace = array('>', '<', '\\1');
143-
$code = preg_replace($search, $replace, $code);
144-
return $code;
145-
}
114+
function minifier(string $code): string
115+
{
116+
$search = array(
117+
// Remove whitespaces after tags
118+
'/\>[^\S]+/s',
119+
// Remove whitespaces before tags
120+
'/[^\S]+\</s',
121+
// Remove multiple whitespace sequences
122+
'/(\s)+/s',
123+
// Removes comments
124+
'/<!--(.|\s)*?-->/'
125+
);
126+
$replace = array('>', '<', '\\1');
127+
$code = preg_replace($search, $replace, $code);
128+
return $code;
146129
}
147-
if (!function_exists('convertToBytes')) {
148-
function convertToBytes(string $size): int
149-
{
150-
$unit = strtoupper(substr($size, -1)); // Получаем последний символ (единицу измерения)
151-
/** @var int */
152-
$number = substr($size, 0, -1); // Получаем число (без последнего символа)
153-
return match ($unit) {
154-
'K' => $number * 1024,
155-
'M' => $number * 1024 * 1024,
156-
'G' => $number * 1024 * 1024 * 1024,
157-
default => (int) $size
158-
};
159-
}
130+
function convertToBytes(string $size): int
131+
{
132+
$unit = strtoupper(substr($size, -1)); // Получаем последний символ (единицу измерения)
133+
/** @var int */
134+
$number = substr($size, 0, -1); // Получаем число (без последнего символа)
135+
return match ($unit) {
136+
'K' => $number * 1024,
137+
'M' => $number * 1024 * 1024,
138+
'G' => $number * 1024 * 1024 * 1024,
139+
default => (int) $size
140+
};
160141
}

0 commit comments

Comments
 (0)