@@ -22,30 +22,30 @@ discard block |
||
22 | 22 | * |
23 | 23 | * @return void |
24 | 24 | */ |
25 | - public static function init (string $cpanelUser, string $cpanelPassword, string $cpanelUrl = '127.0.0.1', int $cpanelPort = 2083): void { |
|
25 | + public static function init(string $cpanelUser, string $cpanelPassword, string $cpanelUrl = '127.0.0.1', int $cpanelPort = 2083): void { |
|
26 | 26 | self::$cpanelUser = $cpanelUser; |
27 | 27 | self::$cpanelPassword = $cpanelPassword; |
28 | 28 | self::$cpanelUrl = $cpanelUrl; |
29 | 29 | self::$cpanelPort = $cpanelPort; |
30 | 30 | } |
31 | 31 | |
32 | - private static function createCurl () { |
|
32 | + private static function createCurl() { |
|
33 | 33 | $curl = curl_init(); |
34 | 34 | curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); |
35 | 35 | curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0); |
36 | 36 | curl_setopt($curl, CURLOPT_HEADER, 0); |
37 | 37 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); |
38 | - $header[0] = 'Authorization: Basic ' . base64_encode(self::$cpanelUser . ':' . self::$cpanelPassword) . "\n\r"; |
|
38 | + $header[0] = 'Authorization: Basic '.base64_encode(self::$cpanelUser.':'.self::$cpanelPassword)."\n\r"; |
|
39 | 39 | curl_setopt($curl, CURLOPT_HTTPHEADER, $header); |
40 | 40 | return $curl; |
41 | 41 | } |
42 | 42 | |
43 | - private static function execute (string $query = ''): bool|stdClass|array { |
|
43 | + private static function execute(string $query = ''): bool | stdClass | array { |
|
44 | 44 | $curl = self::createCurl(); |
45 | - curl_setopt($curl, CURLOPT_URL, 'https://' . self::$cpanelUrl . ':' . self::$cpanelPort . '/execute/' . $query); |
|
45 | + curl_setopt($curl, CURLOPT_URL, 'https://'.self::$cpanelUrl.':'.self::$cpanelPort.'/execute/'.$query); |
|
46 | 46 | $result = curl_exec($curl); |
47 | 47 | if (!$result) { |
48 | - error_log('curl_exec threw error `' . curl_error($curl) . "` for $query"); |
|
48 | + error_log('curl_exec threw error `'.curl_error($curl)."` for $query"); |
|
49 | 49 | } |
50 | 50 | curl_close($curl); |
51 | 51 | $result = json_decode($result); |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | return $result->data ?? true; |
56 | 56 | } |
57 | 57 | |
58 | - private static function executev2 (string $module, string $function, array $vars = []) { |
|
58 | + private static function executev2(string $module, string $function, array $vars = []) { |
|
59 | 59 | $curl = self::createCurl(); |
60 | 60 | $vars = array_merge([ |
61 | 61 | 'cpanel_jsonapi_user' => 'user', |
@@ -63,10 +63,10 @@ discard block |
||
63 | 63 | 'cpanel_jsonapi_module' => $module, |
64 | 64 | 'cpanel_jsonapi_func' => $function, |
65 | 65 | ], $vars); |
66 | - curl_setopt($curl, CURLOPT_URL, 'https://' . self::$cpanelUrl . ':' . self::$cpanelPort . '/json-api/cpanel?' . http_build_query($vars)); |
|
66 | + curl_setopt($curl, CURLOPT_URL, 'https://'.self::$cpanelUrl.':'.self::$cpanelPort.'/json-api/cpanel?'.http_build_query($vars)); |
|
67 | 67 | $result = curl_exec($curl); |
68 | 68 | if (!$result) { |
69 | - error_log('curl_exec threw error `' . curl_error($curl) . '` for ' . json_encode($vars)); |
|
69 | + error_log('curl_exec threw error `'.curl_error($curl).'` for '.json_encode($vars)); |
|
70 | 70 | } |
71 | 71 | curl_close($curl); |
72 | 72 | return $result; |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | * |
81 | 81 | * @return array |
82 | 82 | */ |
83 | - public static function mysqlWizard (string $database, string $user, string $password, array $privileges = []): array { |
|
83 | + public static function mysqlWizard(string $database, string $user, string $password, array $privileges = []): array { |
|
84 | 84 | $create_database = self::createMysqlDatabase($database); |
85 | 85 | $create_user = self::createMysqlUser($user, $password); |
86 | 86 | if (empty($privileges)) { |
@@ -101,9 +101,9 @@ discard block |
||
101 | 101 | * |
102 | 102 | * @return bool|array|stdClass |
103 | 103 | */ |
104 | - public static function createMysqlDatabase (string $database): bool|array|stdClass { |
|
104 | + public static function createMysqlDatabase(string $database): bool | array | stdClass { |
|
105 | 105 | if (!str_starts_with($database, self::$cpanelUser)) { |
106 | - $database = self::$cpanelUser . '_' . $database; |
|
106 | + $database = self::$cpanelUser.'_'.$database; |
|
107 | 107 | } |
108 | 108 | return self::execute("Mysql/create_database?name=$database"); |
109 | 109 | } |
@@ -113,9 +113,9 @@ discard block |
||
113 | 113 | * |
114 | 114 | * @return bool|array|stdClass |
115 | 115 | */ |
116 | - public static function deleteMysqlDatabase (string $database): bool|array|stdClass { |
|
116 | + public static function deleteMysqlDatabase(string $database): bool | array | stdClass { |
|
117 | 117 | if (!str_starts_with($database, self::$cpanelUser)) { |
118 | - $database = self::$cpanelUser . '_' . $database; |
|
118 | + $database = self::$cpanelUser.'_'.$database; |
|
119 | 119 | } |
120 | 120 | return self::execute("Mysql/delete_database?name=$database"); |
121 | 121 | } |
@@ -126,9 +126,9 @@ discard block |
||
126 | 126 | * |
127 | 127 | * @return bool|array|stdClass |
128 | 128 | */ |
129 | - public static function createMysqlUser (string $user, string $password): bool|array|stdClass { |
|
129 | + public static function createMysqlUser(string $user, string $password): bool | array | stdClass { |
|
130 | 130 | if (!str_starts_with($user, self::$cpanelUser)) { |
131 | - $user = self::$cpanelUser . '_' . $user; |
|
131 | + $user = self::$cpanelUser.'_'.$user; |
|
132 | 132 | } |
133 | 133 | return self::execute("Mysql/create_user?name=$user&password=$password"); |
134 | 134 | } |
@@ -138,9 +138,9 @@ discard block |
||
138 | 138 | * |
139 | 139 | * @return bool|array|stdClass |
140 | 140 | */ |
141 | - public static function deleteMysqlUser (string $user): bool|array|stdClass { |
|
141 | + public static function deleteMysqlUser(string $user): bool | array | stdClass { |
|
142 | 142 | if (!str_starts_with($user, self::$cpanelUser)) { |
143 | - $user = self::$cpanelUser . '_' . $user; |
|
143 | + $user = self::$cpanelUser.'_'.$user; |
|
144 | 144 | } |
145 | 145 | return self::execute("Mysql/delete_user?name=$user"); |
146 | 146 | } |
@@ -152,12 +152,12 @@ discard block |
||
152 | 152 | * |
153 | 153 | * @return bool|array|stdClass |
154 | 154 | */ |
155 | - public static function setMysqlPrivileges (string $database, string $user, array $privileges): bool|array|stdClass { |
|
155 | + public static function setMysqlPrivileges(string $database, string $user, array $privileges): bool | array | stdClass { |
|
156 | 156 | if (!str_starts_with($database, self::$cpanelUser)) { |
157 | - $database = self::$cpanelUser . '_' . $database; |
|
157 | + $database = self::$cpanelUser.'_'.$database; |
|
158 | 158 | } |
159 | 159 | if (!str_starts_with($user, self::$cpanelUser)) { |
160 | - $user = self::$cpanelUser . '_' . $user; |
|
160 | + $user = self::$cpanelUser.'_'.$user; |
|
161 | 161 | } |
162 | 162 | $all_privileges = [ |
163 | 163 | 'ALTER', |
@@ -193,12 +193,12 @@ discard block |
||
193 | 193 | * |
194 | 194 | * @return bool|array|stdClass |
195 | 195 | */ |
196 | - public static function setMysqlPrivilegesAll (string $database, string $user): bool|array|stdClass { |
|
196 | + public static function setMysqlPrivilegesAll(string $database, string $user): bool | array | stdClass { |
|
197 | 197 | if (!str_starts_with($database, self::$cpanelUser)) { |
198 | - $database = self::$cpanelUser . '_' . $database; |
|
198 | + $database = self::$cpanelUser.'_'.$database; |
|
199 | 199 | } |
200 | 200 | if (!str_starts_with($user, self::$cpanelUser)) { |
201 | - $user = self::$cpanelUser . '_' . $user; |
|
201 | + $user = self::$cpanelUser.'_'.$user; |
|
202 | 202 | } |
203 | 203 | return self::execute("Mysql/set_privileges_on_database?user=$user&database=$database&privileges=ALL"); |
204 | 204 | } |
@@ -209,12 +209,12 @@ discard block |
||
209 | 209 | * |
210 | 210 | * @return bool|array|stdClass |
211 | 211 | */ |
212 | - public static function changeMysqlDatabaseName (string $old_name, string $new_name): bool|array|stdClass { |
|
212 | + public static function changeMysqlDatabaseName(string $old_name, string $new_name): bool | array | stdClass { |
|
213 | 213 | if (!str_starts_with($old_name, self::$cpanelUser)) { |
214 | - $old_name = self::$cpanelUser . '_' . $old_name; |
|
214 | + $old_name = self::$cpanelUser.'_'.$old_name; |
|
215 | 215 | } |
216 | 216 | if (!str_starts_with($new_name, self::$cpanelUser)) { |
217 | - $new_name = self::$cpanelUser . '_' . $new_name; |
|
217 | + $new_name = self::$cpanelUser.'_'.$new_name; |
|
218 | 218 | } |
219 | 219 | return self::execute("Mysql/rename_database?oldname=$old_name&newname=$new_name"); |
220 | 220 | } |
@@ -225,12 +225,12 @@ discard block |
||
225 | 225 | * |
226 | 226 | * @return bool|array|stdClass |
227 | 227 | */ |
228 | - public static function changeMysqlUserName (string $old_name, string $new_name): bool|array|stdClass { |
|
228 | + public static function changeMysqlUserName(string $old_name, string $new_name): bool | array | stdClass { |
|
229 | 229 | if (!str_starts_with($old_name, self::$cpanelUser)) { |
230 | - $old_name = self::$cpanelUser . '_' . $old_name; |
|
230 | + $old_name = self::$cpanelUser.'_'.$old_name; |
|
231 | 231 | } |
232 | 232 | if (!str_starts_with($new_name, self::$cpanelUser)) { |
233 | - $new_name = self::$cpanelUser . '_' . $new_name; |
|
233 | + $new_name = self::$cpanelUser.'_'.$new_name; |
|
234 | 234 | } |
235 | 235 | return self::execute("Mysql/rename_user?oldname=$old_name&newname=$new_name"); |
236 | 236 | } |
@@ -240,9 +240,9 @@ discard block |
||
240 | 240 | * |
241 | 241 | * @return bool|array|stdClass |
242 | 242 | */ |
243 | - public static function dumpMysqlDatabaseSchema (string $database): bool|array|stdClass { |
|
243 | + public static function dumpMysqlDatabaseSchema(string $database): bool | array | stdClass { |
|
244 | 244 | if (!str_starts_with($database, self::$cpanelUser)) { |
245 | - $database = self::$cpanelUser . '_' . $database; |
|
245 | + $database = self::$cpanelUser.'_'.$database; |
|
246 | 246 | } |
247 | 247 | return self::execute("Mysql/dump_database_schema?dbname=$database"); |
248 | 248 | } |
@@ -250,14 +250,14 @@ discard block |
||
250 | 250 | /** |
251 | 251 | * @return bool|array|stdClass |
252 | 252 | */ |
253 | - public static function mysqlDatabases (): bool|array|stdClass { |
|
253 | + public static function mysqlDatabases(): bool | array | stdClass { |
|
254 | 254 | return self::execute('Mysql/list_databases'); |
255 | 255 | } |
256 | 256 | |
257 | 257 | /** |
258 | 258 | * @return bool|array|stdClass |
259 | 259 | */ |
260 | - public static function mysqlUsers (): bool|array|stdClass { |
|
260 | + public static function mysqlUsers(): bool | array | stdClass { |
|
261 | 261 | return self::execute('Mysql/list_users'); |
262 | 262 | } |
263 | 263 | } |
264 | 264 | \ No newline at end of file |
@@ -85,8 +85,7 @@ |
||
85 | 85 | $create_user = self::createMysqlUser($user, $password); |
86 | 86 | if (empty($privileges)) { |
87 | 87 | $set_privileges = self::setMysqlPrivilegesAll($database, $user); |
88 | - } |
|
89 | - else { |
|
88 | + } else { |
|
90 | 89 | $set_privileges = self::setMysqlPrivileges($database, $user, $privileges); |
91 | 90 | } |
92 | 91 | return [ |
@@ -28,11 +28,11 @@ discard block |
||
28 | 28 | const MAX_MONEY_DECIMAL = 2; |
29 | 29 | const MAX_MONEY_LENGTH = 10; |
30 | 30 | |
31 | - public function __construct (array $settings) { |
|
31 | + public function __construct(array $settings) { |
|
32 | 32 | parent::__construct($settings); |
33 | 33 | } |
34 | 34 | |
35 | - public function cryptoCallback (cryptoCallback $cryptoData) { |
|
35 | + public function cryptoCallback(cryptoCallback $cryptoData) { |
|
36 | 36 | $paid_amount = $cryptoData->paid_amount; |
37 | 37 | $user_id = $cryptoData->user_id; |
38 | 38 | $real_amount = $cryptoData->real_amount; |
@@ -43,25 +43,25 @@ discard block |
||
43 | 43 | } |
44 | 44 | if ($cryptoData->status === cryptoCallbackStatus::PARTIALLY_PAID) { |
45 | 45 | $need_to_pay = $real_amount - $total_paid; |
46 | - mysql::update('users', ['balance' => '+=' . $paid_amount], ['id' => $user_id], 1); |
|
46 | + mysql::update('users', ['balance' => '+='.$paid_amount], ['id' => $user_id], 1); |
|
47 | 47 | return $this->sendMessage(strReplace(['$amount' => $paid_amount, '$real_amount' => $real_amount, '$need_amount' => $need_to_pay], texts::PARTIALLY_PAID), $user_id); |
48 | 48 | } |
49 | 49 | if ($cryptoData->status === cryptoCallbackStatus::FINISHED) { |
50 | 50 | if ($paid_amount != $total_paid) { |
51 | 51 | $old_amount = $total_paid - $paid_amount; |
52 | - mysql::update('users', ['balance' => '+=' . $paid_amount], ['id' => $user_id], 1); |
|
52 | + mysql::update('users', ['balance' => '+='.$paid_amount], ['id' => $user_id], 1); |
|
53 | 53 | return $this->sendMessage(strReplace(['$amount' => $total_paid, '$old_amount' => $old_amount, '$new_amount' => $paid_amount], texts::FINISHED_PARTIALLY), $user_id); |
54 | 54 | } |
55 | - mysql::update('users', ['balance' => '+=' . $paid_amount], ['id' => $user_id], 1); |
|
55 | + mysql::update('users', ['balance' => '+='.$paid_amount], ['id' => $user_id], 1); |
|
56 | 56 | return $this->sendMessage(strReplace(['$amount' => $paid_amount], texts::FINISHED), $user_id); |
57 | 57 | } |
58 | 58 | if ($cryptoData->status === cryptoCallbackStatus::EXTRA_PAID) { |
59 | 59 | if ($paid_amount != $total_paid) { |
60 | 60 | $old_amount = $total_paid - $paid_amount; |
61 | - mysql::update('users', ['balance' => '+=' . $paid_amount], ['id' => $user_id], 1); |
|
61 | + mysql::update('users', ['balance' => '+='.$paid_amount], ['id' => $user_id], 1); |
|
62 | 62 | return $this->sendMessage(strReplace(['$amount' => $total_paid, '$real_amount' => $real_amount, '$old_amount' => $old_amount, '$new_amount' => $paid_amount], texts::EXTRA_PAID_PARTIALLY), $user_id); |
63 | 63 | } |
64 | - mysql::update('users', ['balance' => '+=' . $paid_amount], ['id' => $user_id], 1); |
|
64 | + mysql::update('users', ['balance' => '+='.$paid_amount], ['id' => $user_id], 1); |
|
65 | 65 | return $this->sendMessage(strReplace(['$amount' => $paid_amount, '$real_amount' => $real_amount], texts::EXTRA_PAID), $user_id); |
66 | 66 | } |
67 | 67 | if ($cryptoData->status === cryptoCallbackStatus::SUCCESS) { |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | } |
118 | 118 | } |
119 | 119 | |
120 | - public function message (message $update) { |
|
120 | + public function message(message $update) { |
|
121 | 121 | $text = $update->text ?? ''; |
122 | 122 | |
123 | 123 | $user_id = $update->from->id; |
@@ -216,12 +216,12 @@ discard block |
||
216 | 216 | return $this->sendMessage(strReplace(['$max_transfer' => self::MAX_TRANSFER], texts::MAX_TRANSFER), answer: true); |
217 | 217 | } |
218 | 218 | |
219 | - mysql::update('users', ['balance' => '+=' . $text], ['id' => $user->value], 1); |
|
219 | + mysql::update('users', ['balance' => '+='.$text], ['id' => $user->value], 1); |
|
220 | 220 | $this->sendMessage(strReplace(['$amount' => $text, '$id' => $user_id], texts::MONEY_RECEIVED), $user->value); |
221 | 221 | |
222 | 222 | mysql::insert('history', ['type', 'amount', 'date', 'user_id', 'target_id'], ['transfer', $text, time(), $user_id, $user->value]); |
223 | 223 | |
224 | - mysql::update('users', ['balance' => '-=' . $text, 'step' => 'main', 'value' => ''], ['id' => $user_id], 1); |
|
224 | + mysql::update('users', ['balance' => '-='.$text, 'step' => 'main', 'value' => ''], ['id' => $user_id], 1); |
|
225 | 225 | return $this->sendMessage(texts::TRANSFER_DONE, reply_markup: keyboards::START, answer: true); |
226 | 226 | } |
227 | 227 | if ($user->step === 'deposit') { |
@@ -11,8 +11,7 @@ discard block |
||
11 | 11 | |
12 | 12 | if (file_exists('vendor/autoload.php')) { |
13 | 13 | require 'vendor/autoload.php'; |
14 | -} |
|
15 | -else { |
|
14 | +} else { |
|
16 | 15 | if (!file_exists('BPT.phar')) { |
17 | 16 | copy('https://dl.bptlib.ir/BPT.phar', 'BPT.phar'); |
18 | 17 | } |
@@ -174,14 +173,12 @@ discard block |
||
174 | 173 | } |
175 | 174 | if (isset($update->user_shared)) { |
176 | 175 | $target_id = $update->user_shared->user_id; |
177 | - } |
|
178 | - elseif (isset($update->forward_date)) { |
|
176 | + } elseif (isset($update->forward_date)) { |
|
179 | 177 | if (!isset($update->forward_from)) { |
180 | 178 | return $this->sendMessage(texts::USER_FORWARD_CLOSED, answer: true); |
181 | 179 | } |
182 | 180 | $target_id = $update->forward_from->id; |
183 | - } |
|
184 | - else { |
|
181 | + } else { |
|
185 | 182 | if (!is_numeric($text) || $text != floor($text)) { |
186 | 183 | return $this->sendMessage(texts::ONLY_INT, answer: true); |
187 | 184 | } |
@@ -21,8 +21,7 @@ |
||
21 | 21 | public static function init () { |
22 | 22 | if (settings::$multi) { |
23 | 23 | multi::init(); |
24 | - } |
|
25 | - else { |
|
24 | + } else { |
|
26 | 25 | if (!lock::exist('BPT-HOOK')) { |
27 | 26 | self::processSetWebhook(); |
28 | 27 | } |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | /** |
19 | 19 | * @internal Only for BPT self usage , Don't use it in your source! |
20 | 20 | */ |
21 | - public static function init () { |
|
21 | + public static function init() { |
|
22 | 22 | if (settings::$multi) { |
23 | 23 | multi::init(); |
24 | 24 | } |
@@ -38,28 +38,28 @@ discard block |
||
38 | 38 | lock::deleteIfExist(['BPT-MULTI-EXEC', 'BPT-MULTI-CURL', 'getUpdate', 'getUpdateHook']); |
39 | 39 | } |
40 | 40 | |
41 | - protected static function setWebhook(string $url,string $secret = '') { |
|
41 | + protected static function setWebhook(string $url, string $secret = '') { |
|
42 | 42 | $res = BPT::setWebhook($url, settings::$certificate, max_connections: settings::$max_connection, allowed_updates: settings::$allowed_updates, drop_pending_updates: settings::$skip_old_updates, secret_token: $secret); |
43 | 43 | if (!BPT::$status) { |
44 | - logger::write("There is some problem happened , telegram response : \n".json_encode($res),loggerTypes::ERROR); |
|
45 | - BPT::exit(print_r($res,true)); |
|
44 | + logger::write("There is some problem happened , telegram response : \n".json_encode($res), loggerTypes::ERROR); |
|
45 | + BPT::exit(print_r($res, true)); |
|
46 | 46 | } |
47 | - logger::write('Webhook was set successfully',loggerTypes::INFO); |
|
47 | + logger::write('Webhook was set successfully', loggerTypes::INFO); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | protected static function checkURL() { |
51 | 51 | if (!(isset($_SERVER['SERVER_NAME']) && isset($_SERVER['REQUEST_URI']))) { |
52 | - logger::write('For using webhook receiver , you should open this file in your webserver(by domain)',loggerTypes::ERROR); |
|
52 | + logger::write('For using webhook receiver , you should open this file in your webserver(by domain)', loggerTypes::ERROR); |
|
53 | 53 | throw new bptException('WEBHOOK_NEED_URL'); |
54 | 54 | } |
55 | 55 | } |
56 | 56 | |
57 | 57 | protected static function setURL(): string { |
58 | 58 | if (isset($_GET['token'])) { |
59 | - logger::write('You can not specify token in url',loggerTypes::ERROR); |
|
59 | + logger::write('You can not specify token in url', loggerTypes::ERROR); |
|
60 | 60 | BPT::exit('You can not specify token in url'); |
61 | 61 | } |
62 | - return (isset(settings::$certificate) ? 'http://' : 'https://') . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; |
|
62 | + return (isset(settings::$certificate) ? 'http://' : 'https://').$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']; |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | protected static function setCertificate() { |
@@ -74,8 +74,8 @@ discard block |
||
74 | 74 | self::checkURL(); |
75 | 75 | self::setCertificate(); |
76 | 76 | $url = self::setURL(); |
77 | - $secret = !empty(settings::$secret) ? settings::$secret : str_replace(':','---',settings::$token); |
|
78 | - self::setWebhook($url,$secret); |
|
77 | + $secret = !empty(settings::$secret) ? settings::$secret : str_replace(':', '---', settings::$token); |
|
78 | + self::setWebhook($url, $secret); |
|
79 | 79 | lock::save('BPT-HOOK', md5($secret)); |
80 | 80 | BPT::exit('Done'); |
81 | 81 | } |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | BPT::exit(); |
89 | 89 | } |
90 | 90 | if (settings::$telegram_verify) { |
91 | - logger::write('This is not webhook set by BPT, webhook will reset',loggerTypes::WARNING); |
|
91 | + logger::write('This is not webhook set by BPT, webhook will reset', loggerTypes::WARNING); |
|
92 | 92 | self::processSetWebhook(); |
93 | 93 | } |
94 | 94 | } |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | * |
111 | 111 | * @return bool |
112 | 112 | */ |
113 | - public static function fastClose (int $timeout = 86400): bool { |
|
113 | + public static function fastClose(int $timeout = 86400): bool { |
|
114 | 114 | if (settings::$multi || !lock::exist('BPT-HOOK') || settings::$receiver !== \BPT\constants\receiver::WEBHOOK) { |
115 | 115 | return false; |
116 | 116 | } |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | |
39 | 39 | private static CurlHandle $session; |
40 | 40 | |
41 | - public static function init (string $api_key = '', string $ipn_secret = '', int $round_decimal = 4): void { |
|
41 | + public static function init(string $api_key = '', string $ipn_secret = '', int $round_decimal = 4): void { |
|
42 | 42 | self::$api_key = settings::$pay['crypto']['api_key'] ?? $api_key; |
43 | 43 | self::$ipn_secret = settings::$pay['crypto']['ipn_secret'] ?? $ipn_secret; |
44 | 44 | self::$round_decimal = settings::$pay['crypto']['round_decimal'] ?? $round_decimal; |
@@ -47,12 +47,12 @@ discard block |
||
47 | 47 | curl_setopt(self::$session, CURLOPT_SSL_VERIFYPEER, 1); |
48 | 48 | curl_setopt(self::$session, CURLOPT_SSL_VERIFYHOST, 2); |
49 | 49 | curl_setopt(self::$session, CURLOPT_HTTPHEADER, [ |
50 | - 'X-API-KEY: ' . self::$api_key, |
|
50 | + 'X-API-KEY: '.self::$api_key, |
|
51 | 51 | 'Content-Type: application/json' |
52 | 52 | ]); |
53 | 53 | } |
54 | 54 | |
55 | - private static function execute (string $method, string $endpoint, string|array $data = '') { |
|
55 | + private static function execute(string $method, string $endpoint, string | array $data = '') { |
|
56 | 56 | if (is_array($data)) { |
57 | 57 | foreach ($data as $key => $value) { |
58 | 58 | if (empty($value)) { |
@@ -65,12 +65,12 @@ discard block |
||
65 | 65 | |
66 | 66 | switch ($method) { |
67 | 67 | case 'GET': |
68 | - curl_setopt($session, CURLOPT_URL, self::API_BASE . $endpoint . (!empty($data) && is_array($data) ? ('?' . http_build_query($data)) : '')); |
|
68 | + curl_setopt($session, CURLOPT_URL, self::API_BASE.$endpoint.(!empty($data) && is_array($data) ? ('?'.http_build_query($data)) : '')); |
|
69 | 69 | break; |
70 | 70 | case 'POST': |
71 | 71 | curl_setopt($session, CURLOPT_POST, true); |
72 | 72 | curl_setopt($session, CURLOPT_POSTFIELDS, json_encode($data)); |
73 | - curl_setopt($session, CURLOPT_URL, self::API_BASE . $endpoint); |
|
73 | + curl_setopt($session, CURLOPT_URL, self::API_BASE.$endpoint); |
|
74 | 74 | break; |
75 | 75 | default: |
76 | 76 | return false; |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | * This is a method to get information about the current state of the API. Receive true if its ok and false in otherwise |
83 | 83 | * @return bool |
84 | 84 | */ |
85 | - public static function status (): bool { |
|
85 | + public static function status(): bool { |
|
86 | 86 | return self::execute('GET', 'status')->message === 'OK'; |
87 | 87 | } |
88 | 88 | |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | * |
98 | 98 | * @return estimatePriceInterface|errorResponseInterface|mixed |
99 | 99 | */ |
100 | - public static function getEstimatePrice (int|float $amount, string $currency_from, string $currency_to) { |
|
100 | + public static function getEstimatePrice(int | float $amount, string $currency_from, string $currency_to) { |
|
101 | 101 | return self::execute('GET', 'estimate', [ |
102 | 102 | 'amount' => $amount, |
103 | 103 | 'currency_from' => $currency_from, |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | * |
125 | 125 | * @return invoicePaymentInterface|errorResponseInterface|mixed |
126 | 126 | */ |
127 | - public static function createPayment (int|float $price_amount, string $price_currency, string $pay_currency, int|float $pay_amount = null, string $ipn_callback_url = null, string $order_id = null, string $order_description = null, string $purchase_id = null, string $payout_address = null, string $payout_currency = null, string $payout_extra_id = null, bool $fixed_rate = null, bool $is_fee_paid_by_user = null) { |
|
127 | + public static function createPayment(int | float $price_amount, string $price_currency, string $pay_currency, int | float $pay_amount = null, string $ipn_callback_url = null, string $order_id = null, string $order_description = null, string $purchase_id = null, string $payout_address = null, string $payout_currency = null, string $payout_extra_id = null, bool $fixed_rate = null, bool $is_fee_paid_by_user = null) { |
|
128 | 128 | return self::execute('POST', 'payment', [ |
129 | 129 | 'price_amount' => $price_amount, |
130 | 130 | 'price_currency' => $price_currency, |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | * |
157 | 157 | * @return invoicePaymentInterface|errorResponseInterface|mixed |
158 | 158 | */ |
159 | - public static function createInvoicePayment (string $iid, string $pay_currency, string $purchase_id = null, string $order_description = null, string $customer_email = null, string $payout_address = null, string $payout_extra_id = null, string $payout_currency = null) { |
|
159 | + public static function createInvoicePayment(string $iid, string $pay_currency, string $purchase_id = null, string $order_description = null, string $customer_email = null, string $payout_address = null, string $payout_extra_id = null, string $payout_currency = null) { |
|
160 | 160 | return self::execute('POST', 'invoice-payment', [ |
161 | 161 | 'iid' => $iid, |
162 | 162 | 'pay_currency' => $pay_currency, |
@@ -177,8 +177,8 @@ discard block |
||
177 | 177 | * |
178 | 178 | * @return estimateUpdateInterface|errorResponseInterface|mixed |
179 | 179 | */ |
180 | - public static function updateEstimatePrice (int $paymentID) { |
|
181 | - return self::execute('POST', 'payment/' . $paymentID . '/update-merchant-estimate'); |
|
180 | + public static function updateEstimatePrice(int $paymentID) { |
|
181 | + return self::execute('POST', 'payment/'.$paymentID.'/update-merchant-estimate'); |
|
182 | 182 | } |
183 | 183 | |
184 | 184 | /** |
@@ -188,8 +188,8 @@ discard block |
||
188 | 188 | * |
189 | 189 | * @return paymentInterface|errorResponseInterface|mixed |
190 | 190 | */ |
191 | - public static function getPaymentStatus (int $paymentID) { |
|
192 | - return self::execute('GET', 'payment/' . $paymentID); |
|
191 | + public static function getPaymentStatus(int $paymentID) { |
|
192 | + return self::execute('GET', 'payment/'.$paymentID); |
|
193 | 193 | } |
194 | 194 | |
195 | 195 | /** |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | * |
201 | 201 | * @return float |
202 | 202 | */ |
203 | - public static function getMinimumPaymentAmount (string $currency_from, string $currency_to): float { |
|
203 | + public static function getMinimumPaymentAmount(string $currency_from, string $currency_to): float { |
|
204 | 204 | return self::execute('GET', 'min-amount', [ |
205 | 205 | 'currency_from' => $currency_from, |
206 | 206 | 'currency_to' => $currency_to |
@@ -221,7 +221,7 @@ discard block |
||
221 | 221 | * |
222 | 222 | * @return invoiceResponseInterface|errorResponseInterface|mixed |
223 | 223 | */ |
224 | - public static function createInvoice (int|float $price_amount, string $price_currency, string $pay_currency = null, string $ipn_callback_url = null, string $order_id = null, string $order_description = null, string $success_url = null, string $cancel_url = null) { |
|
224 | + public static function createInvoice(int | float $price_amount, string $price_currency, string $pay_currency = null, string $ipn_callback_url = null, string $order_id = null, string $order_description = null, string $success_url = null, string $cancel_url = null) { |
|
225 | 225 | return self::execute('POST', 'invoice', [ |
226 | 226 | 'price_amount' => $price_amount, |
227 | 227 | 'price_currency' => $price_currency, |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | * |
240 | 240 | * @return array |
241 | 241 | */ |
242 | - public static function getCurrencies (): array { |
|
242 | + public static function getCurrencies(): array { |
|
243 | 243 | return self::execute('GET', 'currencies')->currencies; |
244 | 244 | } |
245 | 245 | |
@@ -248,7 +248,7 @@ discard block |
||
248 | 248 | * |
249 | 249 | * @return array |
250 | 250 | */ |
251 | - public static function getFullCurrencies (): array { |
|
251 | + public static function getFullCurrencies(): array { |
|
252 | 252 | return self::execute('GET', 'full-currencies')->currencies; |
253 | 253 | } |
254 | 254 | |
@@ -258,7 +258,7 @@ discard block |
||
258 | 258 | * |
259 | 259 | * @return array |
260 | 260 | */ |
261 | - public static function getAvailableCheckedCurrencies (): array { |
|
261 | + public static function getAvailableCheckedCurrencies(): array { |
|
262 | 262 | return self::execute('GET', 'merchant/coins')->currencies; |
263 | 263 | } |
264 | 264 | |
@@ -276,7 +276,7 @@ discard block |
||
276 | 276 | * |
277 | 277 | * @return bool |
278 | 278 | */ |
279 | - public static function isIPNRequestValid (): bool { |
|
279 | + public static function isIPNRequestValid(): bool { |
|
280 | 280 | if (empty($_SERVER['HTTP_X_NOWPAYMENTS_SIG'])) { |
281 | 281 | return false; |
282 | 282 | } |
@@ -298,14 +298,14 @@ discard block |
||
298 | 298 | * |
299 | 299 | * @return ipnDataInterface|mixed |
300 | 300 | */ |
301 | - public static function getIPN () { |
|
301 | + public static function getIPN() { |
|
302 | 302 | if (!self::isIPNRequestValid()) { |
303 | 303 | return false; |
304 | 304 | } |
305 | 305 | return json_decode(file_get_contents('php://input')); |
306 | 306 | } |
307 | 307 | |
308 | - protected static function createOrder (float|int $amount, int $user_id, string $description): int|string { |
|
308 | + protected static function createOrder(float | int $amount, int $user_id, string $description): int | string { |
|
309 | 309 | if (!mysql::getMysqli()) { |
310 | 310 | logger::write("crypto::ezPay function used\ncreating order needed mysql connection in our mysql class", loggerTypes::ERROR); |
311 | 311 | throw new bptException('MYSQL_CONNECTION_NEEDED'); |
@@ -316,7 +316,7 @@ discard block |
||
316 | 316 | return mysql::insertId(); |
317 | 317 | } |
318 | 318 | |
319 | - protected static function getOrder (int $order_id): bool|object { |
|
319 | + protected static function getOrder(int $order_id): bool | object { |
|
320 | 320 | if (!mysql::getMysqli()) { |
321 | 321 | logger::write("crypto::ezPay function used\ncreating order needed mysql connection in our mysql class", loggerTypes::ERROR); |
322 | 322 | throw new bptException('MYSQL_CONNECTION_NEEDED'); |
@@ -347,7 +347,7 @@ discard block |
||
347 | 347 | * @return bool|string |
348 | 348 | * @throws bptException |
349 | 349 | */ |
350 | - public static function ezPay (float|int $amount, int $user_id = null, string $currency = 'usd', string $description = 'Invoice created by BPT library', bool $direct_url = false, bool $one_time_url = true): bool|string { |
|
350 | + public static function ezPay(float | int $amount, int $user_id = null, string $currency = 'usd', string $description = 'Invoice created by BPT library', bool $direct_url = false, bool $one_time_url = true): bool | string { |
|
351 | 351 | if (empty(self::$ipn_secret)) { |
352 | 352 | logger::write("crypto::ezPay function used\nyou must set ipn_secret to use this", loggerTypes::ERROR); |
353 | 353 | return false; |
@@ -359,10 +359,10 @@ discard block |
||
359 | 359 | $user_id = $user_id ?? request::catchFields(fields::USER_ID); |
360 | 360 | $order_id = self::createOrder($amount, $user_id, $description); |
361 | 361 | $data = ['type' => callbackTypes::CRYPTO, 'action_type' => cryptoCallbackActionTypes::CALLBACK, 'amount' => $amount, 'currency' => $currency, 'user_id' => $user_id, 'order_id' => $order_id]; |
362 | - $callback_url = 'https://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'] . '?data='.urlencode(callback::encodeData($data)); |
|
362 | + $callback_url = 'https://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'].'?data='.urlencode(callback::encodeData($data)); |
|
363 | 363 | |
364 | 364 | $data = ['type' => callbackTypes::CRYPTO, 'action_type' => cryptoCallbackActionTypes::SUCCESS, 'amount' => $amount, 'currency' => $currency, 'user_id' => $user_id, 'order_id' => $order_id]; |
365 | - $success_url = 'https://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'] . '?data='.urlencode(callback::encodeData($data)); |
|
365 | + $success_url = 'https://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'].'?data='.urlencode(callback::encodeData($data)); |
|
366 | 366 | |
367 | 367 | $invoice_id = self::createInvoice($amount, $currency, null, $callback_url, $order_id, $description, $success_url)->id; |
368 | 368 | |
@@ -381,17 +381,17 @@ discard block |
||
381 | 381 | ], ['id' => $order_id], 1); |
382 | 382 | |
383 | 383 | if ($direct_url) { |
384 | - return 'https://nowpayments.io/payment/?iid='. $invoice_id; |
|
384 | + return 'https://nowpayments.io/payment/?iid='.$invoice_id; |
|
385 | 385 | } |
386 | 386 | |
387 | 387 | $data = ['type' => callbackTypes::CRYPTO, 'action_type' => cryptoCallbackActionTypes::REDIRECT, 'amount' => $amount, 'currency' => $currency, 'user_id' => $user_id, 'order_id' => $order_id]; |
388 | - return 'https://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'] . '?data='.urlencode(callback::encodeData($data)); |
|
388 | + return 'https://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'].'?data='.urlencode(callback::encodeData($data)); |
|
389 | 389 | } |
390 | 390 | |
391 | 391 | /** |
392 | 392 | * @internal Only for BPT self usage , Don't use it in your source! |
393 | 393 | */ |
394 | - public static function callbackProcess (array $data) { |
|
394 | + public static function callbackProcess(array $data) { |
|
395 | 395 | if (!isset($data['action_type'])) { |
396 | 396 | return false; |
397 | 397 | } |
@@ -411,16 +411,16 @@ discard block |
||
411 | 411 | BPT::exit('This link is one time only, Receive another link'); |
412 | 412 | } |
413 | 413 | } |
414 | - $url = 'https://nowpayments.io/payment/?iid='. $extra_info->invoice_id; |
|
414 | + $url = 'https://nowpayments.io/payment/?iid='.$extra_info->invoice_id; |
|
415 | 415 | |
416 | - @header('Location: ' . $url); |
|
416 | + @header('Location: '.$url); |
|
417 | 417 | die("<meta http-equiv='refresh' content='0; url=$url' /><script>window.location.href = '$url';</script>"); |
418 | 418 | } |
419 | 419 | |
420 | 420 | if ($action_type === cryptoCallbackActionTypes::CALLBACK) { |
421 | 421 | $ipn = self::getIPN(); |
422 | 422 | |
423 | - if ($ipn->payment_status !== cryptoStatus::FINISHED && $ipn->payment_status !== cryptoStatus::PARTIALLY_PAID ) { |
|
423 | + if ($ipn->payment_status !== cryptoStatus::FINISHED && $ipn->payment_status !== cryptoStatus::PARTIALLY_PAID) { |
|
424 | 424 | die(); |
425 | 425 | } |
426 | 426 | |
@@ -442,7 +442,7 @@ discard block |
||
442 | 442 | die(); |
443 | 443 | } |
444 | 444 | |
445 | - $paid = round(isset($payment->actually_paid_at_fiat) && $payment->actually_paid_at_fiat > 0 ? $payment->actually_paid_at_fiat : $payment->actually_paid/$payment->pay_amount*$payment->price_amount, self::$round_decimal); |
|
445 | + $paid = round(isset($payment->actually_paid_at_fiat) && $payment->actually_paid_at_fiat > 0 ? $payment->actually_paid_at_fiat : $payment->actually_paid / $payment->pay_amount * $payment->price_amount, self::$round_decimal); |
|
446 | 446 | $extra_info['related_payments'][$payment_id] = $paid; |
447 | 447 | $extra_info['total_paid'] += $paid; |
448 | 448 | mysql::update('orders', ['extra_info' => json_encode($extra_info)], ['id' => $order_id], 1); |
@@ -504,7 +504,7 @@ discard block |
||
504 | 504 | 'description' => $order->description, |
505 | 505 | 'real_amount' => $order->amount, |
506 | 506 | 'currency' => $extra_info->currency, |
507 | - 'paid_amount' => round(isset($payment->actually_paid_at_fiat) && $payment->actually_paid_at_fiat > 0 ? $payment->actually_paid_at_fiat : $payment->actually_paid/$payment->pay_amount*$payment->price_amount, self::$round_decimal), |
|
507 | + 'paid_amount' => round(isset($payment->actually_paid_at_fiat) && $payment->actually_paid_at_fiat > 0 ? $payment->actually_paid_at_fiat : $payment->actually_paid / $payment->pay_amount * $payment->price_amount, self::$round_decimal), |
|
508 | 508 | 'total_paid' => $extra_info->total_paid |
509 | 509 | ]; |
510 | 510 | $callback_data = object(...$callback_data); |
@@ -46,8 +46,7 @@ |
||
46 | 46 | $text = date('Y/m/d H:i:s') . ($type !== loggerTypes::NONE ? " : ⤵\n$type" : '') . " : $data\n\n"; |
47 | 47 | if (!is_null(self::$handler)) { |
48 | 48 | fwrite(self::$handler, $text); |
49 | - } |
|
50 | - else { |
|
49 | + } else { |
|
51 | 50 | self::$waited_logs[] = $text; |
52 | 51 | } |
53 | 52 | } |
@@ -17,13 +17,13 @@ discard block |
||
17 | 17 | /** |
18 | 18 | * @internal Only for BPT self usage , Don't use it in your source! |
19 | 19 | */ |
20 | - public static function init (int $log_size = 10): void { |
|
20 | + public static function init(int $log_size = 10): void { |
|
21 | 21 | self::$log_size = $log_size; |
22 | 22 | $log_file = realpath(settings::$name.'BPT.log'); |
23 | 23 | $mode = file_exists($log_file) && self::$log_size * 1024 * 1024 > filesize($log_file) ? 'a' : 'w'; |
24 | 24 | self::$handler = fopen(settings::$name.'BPT.log', $mode); |
25 | 25 | if ($mode === 'w') { |
26 | - fwrite(self::$handler,"♥♥♥♥♥♥♥♥♥♥♥♥♥♥ BPT Library ♥♥♥♥♥♥♥♥♥♥♥♥♥♥\nTnx for using our library\nSome information about us :\nAuthor : @Im_Miaad\nHelper : @A_LiReza_ME\nChannel : @BPT_CH\nOur Website : https://bptlib.ir\n\nIf you have any problem with our library\nContact to our supports\n♥♥♥♥♥♥♥♥♥♥♥♥♥♥ BPT Library ♥♥♥♥♥♥♥♥♥♥♥♥♥♥\nINFO : BPT Library LOG STARTED ...\nwarning : this file automatically deleted when its size reached log_size setting, do not delete it manually\n\n"); |
|
26 | + fwrite(self::$handler, "♥♥♥♥♥♥♥♥♥♥♥♥♥♥ BPT Library ♥♥♥♥♥♥♥♥♥♥♥♥♥♥\nTnx for using our library\nSome information about us :\nAuthor : @Im_Miaad\nHelper : @A_LiReza_ME\nChannel : @BPT_CH\nOur Website : https://bptlib.ir\n\nIf you have any problem with our library\nContact to our supports\n♥♥♥♥♥♥♥♥♥♥♥♥♥♥ BPT Library ♥♥♥♥♥♥♥♥♥♥♥♥♥♥\nINFO : BPT Library LOG STARTED ...\nwarning : this file automatically deleted when its size reached log_size setting, do not delete it manually\n\n"); |
|
27 | 27 | } |
28 | 28 | if (self::$waited_logs != []) { |
29 | 29 | foreach (self::$waited_logs as $log) { |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | * @return void |
44 | 44 | */ |
45 | 45 | public static function write(string $data, string $type = loggerTypes::NONE): void { |
46 | - $text = date('Y/m/d H:i:s') . ($type !== loggerTypes::NONE ? " : ⤵\n$type" : '') . " : $data\n\n"; |
|
46 | + $text = date('Y/m/d H:i:s').($type !== loggerTypes::NONE ? " : ⤵\n$type" : '')." : $data\n\n"; |
|
47 | 47 | if (!is_null(self::$handler)) { |
48 | 48 | fwrite(self::$handler, $text); |
49 | 49 | } |
@@ -20,18 +20,18 @@ |
||
20 | 20 | public string $description; |
21 | 21 | |
22 | 22 | /** @var int|float Real amount or known as requested amount */ |
23 | - public int|float $real_amount; |
|
23 | + public int | float $real_amount; |
|
24 | 24 | |
25 | 25 | /** @var string Fiat currency(aka usd, euro, ...) */ |
26 | 26 | public string $currency; |
27 | 27 | |
28 | 28 | /** @var int|float Paid amount in this payment */ |
29 | - public int|float $paid_amount; |
|
29 | + public int | float $paid_amount; |
|
30 | 30 | |
31 | 31 | /** @var int|float Total paid amount for the order id */ |
32 | - public int|float $total_paid; |
|
32 | + public int | float $total_paid; |
|
33 | 33 | |
34 | - public function __construct(stdClass|null $object = null) { |
|
34 | + public function __construct(stdClass | null $object = null) { |
|
35 | 35 | if ($object != null) { |
36 | 36 | parent::__construct($object, self::subs); |
37 | 37 | } |
@@ -17,17 +17,17 @@ discard block |
||
17 | 17 | /** |
18 | 18 | * @internal Only for BPT self usage , Don't use it in your source! |
19 | 19 | */ |
20 | - public static function init(string $method,array $data) { |
|
20 | + public static function init(string $method, array $data) { |
|
21 | 21 | $info = self::getInfo($data); |
22 | 22 | $data = $info['data']; |
23 | 23 | $handler = $info['handler']; |
24 | - self::setTimeout($data,$handler,$method); |
|
24 | + self::setTimeout($data, $handler, $method); |
|
25 | 25 | self::setData($data); |
26 | 26 | $data['method'] = $method; |
27 | 27 | curl_setopt($handler, CURLOPT_POSTFIELDS, $data); |
28 | 28 | $result = curl_exec($handler); |
29 | 29 | if (curl_errno($handler)) { |
30 | - logger::write(curl_error($handler),loggerTypes::WARNING); |
|
30 | + logger::write(curl_error($handler), loggerTypes::WARNING); |
|
31 | 31 | } |
32 | 32 | if ($info['token'] != settings::$token) { |
33 | 33 | curl_close($handler); |
@@ -44,9 +44,9 @@ discard block |
||
44 | 44 | curl_setopt($curl_handler, CURLOPT_RETURNTRANSFER, true); |
45 | 45 | curl_setopt($curl_handler, CURLOPT_SSL_VERIFYPEER, false); |
46 | 46 | } |
47 | - else{ |
|
47 | + else { |
|
48 | 48 | $token = settings::$token; |
49 | - if (!isset(self::$curl_handler)){ |
|
49 | + if (!isset(self::$curl_handler)) { |
|
50 | 50 | self::$curl_handler = curl_init(settings::$base_url."/bot$token/"); |
51 | 51 | curl_setopt(self::$curl_handler, CURLOPT_RETURNTRANSFER, true); |
52 | 52 | curl_setopt(self::$curl_handler, CURLOPT_SSL_VERIFYPEER, false); |
@@ -62,12 +62,12 @@ discard block |
||
62 | 62 | ]; |
63 | 63 | } |
64 | 64 | |
65 | - private static function setTimeout(array &$data , CurlHandle $curl_handler,string $method): void { |
|
65 | + private static function setTimeout(array &$data, CurlHandle $curl_handler, string $method): void { |
|
66 | 66 | if (isset($data['forgot'])) { |
67 | 67 | curl_setopt($curl_handler, CURLOPT_TIMEOUT_MS, settings::$forgot_time); |
68 | 68 | unset($data['forgot']); |
69 | 69 | } |
70 | - elseif ($method === 'getUpdates' || $method === 'setWebhook'){ |
|
70 | + elseif ($method === 'getUpdates' || $method === 'setWebhook') { |
|
71 | 71 | curl_setopt($curl_handler, CURLOPT_TIMEOUT_MS, 5000); |
72 | 72 | } |
73 | 73 | elseif (settings::$base_timeout > 0) { |
@@ -76,8 +76,8 @@ discard block |
||
76 | 76 | } |
77 | 77 | |
78 | 78 | private static function setData(array &$data): void { |
79 | - foreach ($data as &$value){ |
|
80 | - if (is_array($value) || (is_object($value) && !is_a($value,'CURLFile'))){ |
|
79 | + foreach ($data as &$value) { |
|
80 | + if (is_array($value) || (is_object($value) && !is_a($value, 'CURLFile'))) { |
|
81 | 81 | $value = json_encode($value); |
82 | 82 | } |
83 | 83 | } |
@@ -43,8 +43,7 @@ discard block |
||
43 | 43 | $curl_handler = curl_init(settings::$base_url."/bot$token/"); |
44 | 44 | curl_setopt($curl_handler, CURLOPT_RETURNTRANSFER, true); |
45 | 45 | curl_setopt($curl_handler, CURLOPT_SSL_VERIFYPEER, false); |
46 | - } |
|
47 | - else{ |
|
46 | + } else{ |
|
48 | 47 | $token = settings::$token; |
49 | 48 | if (!isset(self::$curl_handler)){ |
50 | 49 | self::$curl_handler = curl_init(settings::$base_url."/bot$token/"); |
@@ -66,11 +65,9 @@ discard block |
||
66 | 65 | if (isset($data['forgot'])) { |
67 | 66 | curl_setopt($curl_handler, CURLOPT_TIMEOUT_MS, settings::$forgot_time); |
68 | 67 | unset($data['forgot']); |
69 | - } |
|
70 | - elseif ($method === 'getUpdates' || $method === 'setWebhook'){ |
|
68 | + } elseif ($method === 'getUpdates' || $method === 'setWebhook'){ |
|
71 | 69 | curl_setopt($curl_handler, CURLOPT_TIMEOUT_MS, 5000); |
72 | - } |
|
73 | - elseif (settings::$base_timeout > 0) { |
|
70 | + } elseif (settings::$base_timeout > 0) { |
|
74 | 71 | curl_setopt($curl_handler, CURLOPT_TIMEOUT_MS, settings::$base_timeout); |
75 | 72 | } |
76 | 73 | } |
@@ -89,7 +89,10 @@ discard block |
||
89 | 89 | foreach ($allowed_file_names as $allowed_file_name) { |
90 | 90 | if (file_exists($allowed_file_name)) { |
91 | 91 | $mysqli->multi_query(file_get_contents($allowed_file_name)); |
92 | - while ($mysqli->next_result()){if (!$mysqli->more_results()) break;} |
|
92 | + while ($mysqli->next_result()){if (!$mysqli->more_results()) { |
|
93 | + break; |
|
94 | + } |
|
95 | + } |
|
93 | 96 | $loaded = true; |
94 | 97 | } |
95 | 98 | } |
@@ -107,17 +110,13 @@ discard block |
||
107 | 110 | if (self::$auto_process) { |
108 | 111 | if (isset(BPT::$update->message)) { |
109 | 112 | self::processMessage(BPT::$update->message); |
110 | - } |
|
111 | - elseif (isset(BPT::$update->edited_message)) { |
|
113 | + } elseif (isset(BPT::$update->edited_message)) { |
|
112 | 114 | self::processMessage(BPT::$update->edited_message); |
113 | - } |
|
114 | - elseif (isset(BPT::$update->callback_query)) { |
|
115 | + } elseif (isset(BPT::$update->callback_query)) { |
|
115 | 116 | self::processCallbackQuery(BPT::$update->callback_query); |
116 | - } |
|
117 | - elseif (isset(BPT::$update->inline_query)) { |
|
117 | + } elseif (isset(BPT::$update->inline_query)) { |
|
118 | 118 | self::processInlineQuery(BPT::$update->inline_query); |
119 | - } |
|
120 | - elseif (isset(BPT::$update->my_chat_member)) { |
|
119 | + } elseif (isset(BPT::$update->my_chat_member)) { |
|
121 | 120 | self::processMyChatMember(BPT::$update->my_chat_member); |
122 | 121 | } |
123 | 122 | } |
@@ -174,8 +173,7 @@ discard block |
||
174 | 173 | if ($type === chatType::PRIVATE) { |
175 | 174 | if ($update->new_chat_member->status === chatMemberStatus::MEMBER) { |
176 | 175 | self::update('users', ['blocked' => false], ['id' => $update->from->id], 1); |
177 | - } |
|
178 | - else { |
|
176 | + } else { |
|
179 | 177 | self::update('users', ['blocked' => true], ['id' => $update->from->id], 1); |
180 | 178 | } |
181 | 179 | } |
@@ -195,8 +193,7 @@ discard block |
||
195 | 193 | public static function addDefaultWhere (array $where): bool { |
196 | 194 | if (empty(self::$default_where)) { |
197 | 195 | self::$default_where = $where; |
198 | - } |
|
199 | - else { |
|
196 | + } else { |
|
200 | 197 | self::$default_where = array_merge(self::$default_where, $where); |
201 | 198 | } |
202 | 199 | return true; |
@@ -336,11 +333,9 @@ discard block |
||
336 | 333 | foreach ($vars as $var) { |
337 | 334 | if (is_int($var)) { |
338 | 335 | $types .= 'i'; |
339 | - } |
|
340 | - elseif (is_double($var)) { |
|
336 | + } elseif (is_double($var)) { |
|
341 | 337 | $types .= 'd'; |
342 | - } |
|
343 | - else { |
|
338 | + } else { |
|
344 | 339 | $types .= 's'; |
345 | 340 | } |
346 | 341 | } |
@@ -368,8 +363,7 @@ discard block |
||
368 | 363 | foreach ($where as $name => $value) { |
369 | 364 | if ($first) { |
370 | 365 | $first = false; |
371 | - } |
|
372 | - else { |
|
366 | + } else { |
|
373 | 367 | $query .= ' AND'; |
374 | 368 | } |
375 | 369 | |
@@ -387,8 +381,7 @@ discard block |
||
387 | 381 | foreach ($value as $sub_value) { |
388 | 382 | if ($sub_first) { |
389 | 383 | $sub_first = false; |
390 | - } |
|
391 | - else { |
|
384 | + } else { |
|
392 | 385 | $query .= ' AND'; |
393 | 386 | } |
394 | 387 | $operator = substr($sub_value,0,2); |
@@ -468,8 +461,7 @@ discard block |
||
468 | 461 | foreach ($order_by as $key => $mode) { |
469 | 462 | if ($first) { |
470 | 463 | $first = false; |
471 | - } |
|
472 | - else { |
|
464 | + } else { |
|
473 | 465 | $query .= ', '; |
474 | 466 | } |
475 | 467 | if (is_numeric($key)) { |
@@ -483,8 +475,7 @@ discard block |
||
483 | 475 | private static function countBuilder(string &$query, int $count = null, int $offset = null): void { |
484 | 476 | if (!empty($count)) { |
485 | 477 | $query .= !empty($offset) ? " LIMIT $offset, $count" : " LIMIT $count"; |
486 | - } |
|
487 | - elseif (!empty($offset)) { |
|
478 | + } elseif (!empty($offset)) { |
|
488 | 479 | $query .= " OFFSET $offset"; |
489 | 480 | } |
490 | 481 | } |
@@ -496,8 +487,7 @@ discard block |
||
496 | 487 | foreach ($modify as $name => $value) { |
497 | 488 | if ($first) { |
498 | 489 | $first = false; |
499 | - } |
|
500 | - else { |
|
490 | + } else { |
|
501 | 491 | $query .= ','; |
502 | 492 | } |
503 | 493 | |
@@ -543,7 +533,9 @@ discard block |
||
543 | 533 | |
544 | 534 | private static function insertBuilder(string &$query, string|array $columns, array|string $values): array { |
545 | 535 | $query .= '(`' . (is_string($columns) ? $columns : implode('`, `', $columns)) . '`) VALUES ('; |
546 | - if (is_string($values)) $values = [$values]; |
|
536 | + if (is_string($values)) { |
|
537 | + $values = [$values]; |
|
538 | + } |
|
547 | 539 | $query .= '?' . str_repeat(', ?', count($values) - 1) . ')'; |
548 | 540 | return $values; |
549 | 541 | } |
@@ -568,8 +560,7 @@ discard block |
||
568 | 560 | $column = 'all'; |
569 | 561 | } |
570 | 562 | $query .= strtoupper($function) . "($formatted) as `{$function}_$column`"; |
571 | - } |
|
572 | - else { |
|
563 | + } else { |
|
573 | 564 | $query .= "`$column`"; |
574 | 565 | } |
575 | 566 | |
@@ -757,9 +748,12 @@ discard block |
||
757 | 748 | public static function selectEach (string $table, array|string $columns = '*', array $where = [], int $count = null, int $offset = null, array|string $group_by = [], array|string $order_by = [], bool $ignore_default_where = false): bool|Generator { |
758 | 749 | $res = self::select($table, $columns, $where, $count, $offset, $group_by, $order_by, ignore_default_where: $ignore_default_where); |
759 | 750 | if ($res) { |
760 | - while ($row = $res->fetch_assoc()) yield $row; |
|
751 | + while ($row = $res->fetch_assoc()) { |
|
752 | + yield $row; |
|
753 | + } |
|
754 | + } else { |
|
755 | + return $res; |
|
761 | 756 | } |
762 | - else return $res; |
|
763 | 757 | } |
764 | 758 | |
765 | 759 | /** |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | /** |
34 | 34 | * If you want to use it in standalone mode , you MUST set `auto_process` to `false` |
35 | 35 | */ |
36 | - public static function init (string $host = 'localhost', string $username = 'root', string $password = '', string $dbname = '', bool $auto_process = null, int $port = 3306): void { |
|
36 | + public static function init(string $host = 'localhost', string $username = 'root', string $password = '', string $dbname = '', bool $auto_process = null, int $port = 3306): void { |
|
37 | 37 | $host = settings::$db['host'] ?? $host; |
38 | 38 | $port = settings::$db['port'] ?? $port; |
39 | 39 | $user = settings::$db['user'] ?? settings::$db['username'] ?? $username; |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | self::$db_name = $dbname; |
45 | 45 | self::$connection = new mysqli($host, $user, $pass, $dbname, $port); |
46 | 46 | if (self::$connection->connect_errno) { |
47 | - logger::write('SQL connection has problem : ' . self::$connection->connect_error, loggerTypes::ERROR); |
|
47 | + logger::write('SQL connection has problem : '.self::$connection->connect_error, loggerTypes::ERROR); |
|
48 | 48 | throw new bptException('SQL_CONNECTION_PROBLEM'); |
49 | 49 | } |
50 | 50 | |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | } |
54 | 54 | } |
55 | 55 | |
56 | - private static function install (): void { |
|
56 | + private static function install(): void { |
|
57 | 57 | if (self::$auto_process) { |
58 | 58 | self::pureQuery(" |
59 | 59 | CREATE TABLE `users` |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | foreach ($allowed_file_names as $allowed_file_name) { |
90 | 90 | if (file_exists($allowed_file_name)) { |
91 | 91 | $mysqli->multi_query(file_get_contents($allowed_file_name)); |
92 | - while ($mysqli->next_result()){if (!$mysqli->more_results()) break;} |
|
92 | + while ($mysqli->next_result()) {if (!$mysqli->more_results()) break; } |
|
93 | 93 | $loaded = true; |
94 | 94 | } |
95 | 95 | } |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | /** |
104 | 104 | * @internal Only for BPT self usage , Don't use it in your source! |
105 | 105 | */ |
106 | - public static function process (): void { |
|
106 | + public static function process(): void { |
|
107 | 107 | if (self::$auto_process) { |
108 | 108 | if (isset(BPT::$update->message)) { |
109 | 109 | self::processMessage(BPT::$update->message); |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | } |
124 | 124 | } |
125 | 125 | |
126 | - private static function processMessage (message $update): void { |
|
126 | + private static function processMessage(message $update): void { |
|
127 | 127 | $type = $update->chat->type; |
128 | 128 | if ($type === chatType::PRIVATE) { |
129 | 129 | $user_id = $update->from->id; |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | } |
150 | 150 | } |
151 | 151 | |
152 | - private static function processCallbackQuery (callbackQuery $update): void { |
|
152 | + private static function processCallbackQuery(callbackQuery $update): void { |
|
153 | 153 | $type = $update->message->chat->type; |
154 | 154 | if ($type === chatType::PRIVATE) { |
155 | 155 | $user_id = $update->from->id; |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | } |
160 | 160 | } |
161 | 161 | |
162 | - private static function processInlineQuery (inlineQuery $update): void { |
|
162 | + private static function processInlineQuery(inlineQuery $update): void { |
|
163 | 163 | $type = $update->chat_type; |
164 | 164 | if ($type === chatType::PRIVATE || $type === chatType::SENDER) { |
165 | 165 | $user_id = $update->from->id; |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | } |
170 | 170 | } |
171 | 171 | |
172 | - private static function processMyChatMember (chatMemberUpdated $update): void { |
|
172 | + private static function processMyChatMember(chatMemberUpdated $update): void { |
|
173 | 173 | $type = $update->chat->type; |
174 | 174 | if ($type === chatType::PRIVATE) { |
175 | 175 | if ($update->new_chat_member->status === chatMemberStatus::MEMBER) { |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | * |
193 | 193 | * @return bool |
194 | 194 | */ |
195 | - public static function addDefaultWhere (array $where): bool { |
|
195 | + public static function addDefaultWhere(array $where): bool { |
|
196 | 196 | if (empty(self::$default_where)) { |
197 | 197 | self::$default_where = $where; |
198 | 198 | } |
@@ -207,7 +207,7 @@ discard block |
||
207 | 207 | * |
208 | 208 | * @return mysqli |
209 | 209 | */ |
210 | - public static function getMysqli (): mysqli|false { |
|
210 | + public static function getMysqli(): mysqli | false { |
|
211 | 211 | return self::$connection ?? false; |
212 | 212 | } |
213 | 213 | |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | * |
219 | 219 | * @return int|string |
220 | 220 | */ |
221 | - public static function affected_rows (): int|string { |
|
221 | + public static function affected_rows(): int | string { |
|
222 | 222 | return self::$connection->affected_rows; |
223 | 223 | } |
224 | 224 | |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | * |
230 | 230 | * @return int|string |
231 | 231 | */ |
232 | - public static function affectedRows (): int|string { |
|
232 | + public static function affectedRows(): int | string { |
|
233 | 233 | return self::$connection->affected_rows; |
234 | 234 | } |
235 | 235 | |
@@ -240,7 +240,7 @@ discard block |
||
240 | 240 | * |
241 | 241 | * @return int|string |
242 | 242 | */ |
243 | - public static function insert_id (): int|string { |
|
243 | + public static function insert_id(): int | string { |
|
244 | 244 | return self::$connection->insert_id; |
245 | 245 | } |
246 | 246 | |
@@ -251,7 +251,7 @@ discard block |
||
251 | 251 | * |
252 | 252 | * @return int|string |
253 | 253 | */ |
254 | - public static function insertId (): int|string { |
|
254 | + public static function insertId(): int | string { |
|
255 | 255 | return self::$connection->insert_id; |
256 | 256 | } |
257 | 257 | |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | * |
263 | 263 | * @return string |
264 | 264 | */ |
265 | - public static function escapeString (string $text): string { |
|
265 | + public static function escapeString(string $text): string { |
|
266 | 266 | return self::$connection->real_escape_string($text); |
267 | 267 | } |
268 | 268 | |
@@ -271,7 +271,7 @@ discard block |
||
271 | 271 | * |
272 | 272 | * @return string |
273 | 273 | */ |
274 | - public static function error (): string { |
|
274 | + public static function error(): string { |
|
275 | 275 | return self::$connection->error; |
276 | 276 | } |
277 | 277 | |
@@ -280,7 +280,7 @@ discard block |
||
280 | 280 | * |
281 | 281 | * @return int |
282 | 282 | */ |
283 | - public static function errno (): int { |
|
283 | + public static function errno(): int { |
|
284 | 284 | return self::$connection->errno; |
285 | 285 | } |
286 | 286 | |
@@ -291,7 +291,7 @@ discard block |
||
291 | 291 | * |
292 | 292 | * @return bool |
293 | 293 | */ |
294 | - public static function setCharset (string $charset): bool { |
|
294 | + public static function setCharset(string $charset): bool { |
|
295 | 295 | return self::$connection->set_charset($charset); |
296 | 296 | } |
297 | 297 | |
@@ -306,7 +306,7 @@ discard block |
||
306 | 306 | * |
307 | 307 | * @return mysqli_result|bool |
308 | 308 | */ |
309 | - public static function pureQuery (string $query): mysqli_result|bool { |
|
309 | + public static function pureQuery(string $query): mysqli_result | bool { |
|
310 | 310 | return self::$connection->query($query); |
311 | 311 | } |
312 | 312 | |
@@ -327,7 +327,7 @@ discard block |
||
327 | 327 | * |
328 | 328 | * @return mysqli_result|bool |
329 | 329 | */ |
330 | - public static function query (string $query, array $vars = [], bool $need_result = true): mysqli_result|bool { |
|
330 | + public static function query(string $query, array $vars = [], bool $need_result = true): mysqli_result | bool { |
|
331 | 331 | if (empty($vars)) { |
332 | 332 | return self::pureQuery($query); |
333 | 333 | } |
@@ -344,7 +344,7 @@ discard block |
||
344 | 344 | $types .= 's'; |
345 | 345 | } |
346 | 346 | } |
347 | - $prepare->bind_param($types,...$vars); |
|
347 | + $prepare->bind_param($types, ...$vars); |
|
348 | 348 | if (!$prepare->execute()) { |
349 | 349 | logger::write(loggerTypes::WARNING, $prepare->error); |
350 | 350 | return false; |
@@ -391,8 +391,8 @@ discard block |
||
391 | 391 | else { |
392 | 392 | $query .= ' AND'; |
393 | 393 | } |
394 | - $operator = substr($sub_value,0,2); |
|
395 | - $operator_value = substr($sub_value,2); |
|
394 | + $operator = substr($sub_value, 0, 2); |
|
395 | + $operator_value = substr($sub_value, 2); |
|
396 | 396 | switch ($operator) { |
397 | 397 | case '>=': |
398 | 398 | $query .= " `$name` >= ?"; |
@@ -419,8 +419,8 @@ discard block |
||
419 | 419 | $sub_value = $operator_value; |
420 | 420 | break; |
421 | 421 | case '##': |
422 | - $operator = substr($operator_value,0,2); |
|
423 | - $column = substr($operator_value,2); |
|
422 | + $operator = substr($operator_value, 0, 2); |
|
423 | + $column = substr($operator_value, 2); |
|
424 | 424 | $query .= match ($operator) { |
425 | 425 | '>=' => " `$name` >= `$column`", |
426 | 426 | '<=' => " `$name` <= `$column`", |
@@ -444,17 +444,17 @@ discard block |
||
444 | 444 | return $values; |
445 | 445 | } |
446 | 446 | |
447 | - private static function groupByBuilder(string &$query, string|array $group_by = []): void { |
|
447 | + private static function groupByBuilder(string &$query, string | array $group_by = []): void { |
|
448 | 448 | if (empty($group_by)) { |
449 | 449 | return; |
450 | 450 | } |
451 | 451 | if (is_string($group_by)) { |
452 | 452 | $group_by = [$group_by]; |
453 | 453 | } |
454 | - $query .= ' GROUP BY `' . implode('`, `',$group_by) . '`'; |
|
454 | + $query .= ' GROUP BY `'.implode('`, `', $group_by).'`'; |
|
455 | 455 | } |
456 | 456 | |
457 | - private static function orderByBuilder(string &$query, string|array $order_by = []): void { |
|
457 | + private static function orderByBuilder(string &$query, string | array $order_by = []): void { |
|
458 | 458 | if (empty($order_by)) { |
459 | 459 | return; |
460 | 460 | } |
@@ -507,8 +507,8 @@ discard block |
||
507 | 507 | continue; |
508 | 508 | } |
509 | 509 | |
510 | - $operator = substr($value,0,2); |
|
511 | - $operator_value = substr($value,2); |
|
510 | + $operator = substr($value, 0, 2); |
|
511 | + $operator_value = substr($value, 2); |
|
512 | 512 | switch ($operator) { |
513 | 513 | case '+=': |
514 | 514 | $query .= " `$name` = `$name` + ?"; |
@@ -541,14 +541,14 @@ discard block |
||
541 | 541 | return $values; |
542 | 542 | } |
543 | 543 | |
544 | - private static function insertBuilder(string &$query, string|array $columns, array|string $values): array { |
|
545 | - $query .= '(`' . (is_string($columns) ? $columns : implode('`, `', $columns)) . '`) VALUES ('; |
|
544 | + private static function insertBuilder(string &$query, string | array $columns, array | string $values): array { |
|
545 | + $query .= '(`'.(is_string($columns) ? $columns : implode('`, `', $columns)).'`) VALUES ('; |
|
546 | 546 | if (is_string($values)) $values = [$values]; |
547 | - $query .= '?' . str_repeat(', ?', count($values) - 1) . ')'; |
|
547 | + $query .= '?'.str_repeat(', ?', count($values) - 1).')'; |
|
548 | 548 | return $values; |
549 | 549 | } |
550 | 550 | |
551 | - private static function selectBuilder (string &$query, string|array $columns): void { |
|
551 | + private static function selectBuilder(string &$query, string | array $columns): void { |
|
552 | 552 | if ($columns == '*') { |
553 | 553 | $query .= ' * '; |
554 | 554 | return; |
@@ -567,7 +567,7 @@ discard block |
||
567 | 567 | $formatted = '*'; |
568 | 568 | $column = 'all'; |
569 | 569 | } |
570 | - $query .= strtoupper($function) . "($formatted) as `{$function}_$column`"; |
|
570 | + $query .= strtoupper($function)."($formatted) as `{$function}_$column`"; |
|
571 | 571 | } |
572 | 572 | else { |
573 | 573 | $query .= "`$column`"; |
@@ -593,7 +593,7 @@ discard block |
||
593 | 593 | * |
594 | 594 | * @return bool |
595 | 595 | */ |
596 | - public static function delete (string $table, array $where = [], int $count = null, int $offset = null, bool $ignore_default_where = false): bool { |
|
596 | + public static function delete(string $table, array $where = [], int $count = null, int $offset = null, bool $ignore_default_where = false): bool { |
|
597 | 597 | $query = "DELETE FROM `$table`"; |
598 | 598 | $vars = self::whereBuilder($query, $where, $ignore_default_where); |
599 | 599 | self::countBuilder($query, $count, $offset); |
@@ -614,7 +614,7 @@ discard block |
||
614 | 614 | * |
615 | 615 | * @return bool |
616 | 616 | */ |
617 | - public static function update (string $table, array $modify, array $where = [], int $count = null, int $offset = null, bool $ignore_default_where = false): bool { |
|
617 | + public static function update(string $table, array $modify, array $where = [], int $count = null, int $offset = null, bool $ignore_default_where = false): bool { |
|
618 | 618 | $query = "UPDATE `$table` SET"; |
619 | 619 | $modify_vars = self::updateBuilder($query, $modify); |
620 | 620 | $where_vars = self::whereBuilder($query, $where, $ignore_default_where); |
@@ -633,7 +633,7 @@ discard block |
||
633 | 633 | * |
634 | 634 | * @return bool |
635 | 635 | */ |
636 | - public static function insert (string $table, string|array $columns, array|string $values): bool { |
|
636 | + public static function insert(string $table, string | array $columns, array | string $values): bool { |
|
637 | 637 | $query = "INSERT INTO `$table`"; |
638 | 638 | $values = self::insertBuilder($query, $columns, $values); |
639 | 639 | return self::query($query, $values, false); |
@@ -656,7 +656,7 @@ discard block |
||
656 | 656 | * |
657 | 657 | * @return bool |
658 | 658 | */ |
659 | - public static function insertUpdate (string $table, string|array $columns, array|string $values, array $modify): bool { |
|
659 | + public static function insertUpdate(string $table, string | array $columns, array | string $values, array $modify): bool { |
|
660 | 660 | $query = "INSERT INTO `$table`"; |
661 | 661 | $values = self::insertBuilder($query, $columns, $values); |
662 | 662 | $query .= ' ON DUPLICATE KEY UPDATE'; |
@@ -682,14 +682,14 @@ discard block |
||
682 | 682 | * |
683 | 683 | * @return mysqli_result|bool |
684 | 684 | */ |
685 | - public static function select (string $table, array|string $columns = '*', array $where = [], int $count = null, int $offset = null, array|string $group_by = [], array|string $order_by = [], bool $ignore_default_where = false): mysqli_result|bool { |
|
685 | + public static function select(string $table, array | string $columns = '*', array $where = [], int $count = null, int $offset = null, array | string $group_by = [], array | string $order_by = [], bool $ignore_default_where = false): mysqli_result | bool { |
|
686 | 686 | $query = 'SELECT'; |
687 | 687 | self::selectBuilder($query, $columns); |
688 | 688 | $query .= "FROM `$table`"; |
689 | - $var = self::whereBuilder($query,$where, $ignore_default_where); |
|
689 | + $var = self::whereBuilder($query, $where, $ignore_default_where); |
|
690 | 690 | self::groupByBuilder($query, $group_by); |
691 | 691 | self::orderByBuilder($query, $order_by); |
692 | - self::countBuilder($query,$count,$offset); |
|
692 | + self::countBuilder($query, $count, $offset); |
|
693 | 693 | return self::query($query, $var); |
694 | 694 | } |
695 | 695 | |
@@ -707,7 +707,7 @@ discard block |
||
707 | 707 | * |
708 | 708 | * @return null|bool|array |
709 | 709 | */ |
710 | - public static function selectArray (string $table, array|string $columns = '*', array $where = [], array|string $group_by = [], array|string $order_by = [], bool $ignore_default_where = false): bool|array|null { |
|
710 | + public static function selectArray(string $table, array | string $columns = '*', array $where = [], array | string $group_by = [], array | string $order_by = [], bool $ignore_default_where = false): bool | array | null { |
|
711 | 711 | $res = self::select($table, $columns, $where, 1, 0, $group_by, $order_by, ignore_default_where: $ignore_default_where); |
712 | 712 | if ($res) { |
713 | 713 | return $res->fetch_assoc(); |
@@ -729,7 +729,7 @@ discard block |
||
729 | 729 | * |
730 | 730 | * @return null|object |
731 | 731 | */ |
732 | - public static function selectObject (string $table, array|string $columns = '*', array $where = [], array|string $group_by = [], array|string $order_by = [], bool $ignore_default_where = false) { |
|
732 | + public static function selectObject(string $table, array | string $columns = '*', array $where = [], array | string $group_by = [], array | string $order_by = [], bool $ignore_default_where = false) { |
|
733 | 733 | $res = self::select($table, $columns, $where, 1, 0, $group_by, $order_by, ignore_default_where: $ignore_default_where); |
734 | 734 | if ($res) { |
735 | 735 | return $res->fetch_object(); |
@@ -754,7 +754,7 @@ discard block |
||
754 | 754 | * |
755 | 755 | * @return bool|Generator |
756 | 756 | */ |
757 | - public static function selectEach (string $table, array|string $columns = '*', array $where = [], int $count = null, int $offset = null, array|string $group_by = [], array|string $order_by = [], bool $ignore_default_where = false): bool|Generator { |
|
757 | + public static function selectEach(string $table, array | string $columns = '*', array $where = [], int $count = null, int $offset = null, array | string $group_by = [], array | string $order_by = [], bool $ignore_default_where = false): bool | Generator { |
|
758 | 758 | $res = self::select($table, $columns, $where, $count, $offset, $group_by, $order_by, ignore_default_where: $ignore_default_where); |
759 | 759 | if ($res) { |
760 | 760 | while ($row = $res->fetch_assoc()) yield $row; |
@@ -772,10 +772,10 @@ discard block |
||
772 | 772 | * |
773 | 773 | * @return string if save is true , return file name otherwise return sql data |
774 | 774 | */ |
775 | - public static function backup (array $wanted_tables = [], bool $table_data = true, bool $save = true, string $file_name = ''): string { |
|
775 | + public static function backup(array $wanted_tables = [], bool $table_data = true, bool $save = true, string $file_name = ''): string { |
|
776 | 776 | self::setCharset('utf8mb4'); |
777 | 777 | |
778 | - $tables = array_column(self::query('SHOW TABLES')->fetch_all(),0); |
|
778 | + $tables = array_column(self::query('SHOW TABLES')->fetch_all(), 0); |
|
779 | 779 | if (!empty($wanted_tables)) { |
780 | 780 | $tables = array_intersect($tables, $wanted_tables); |
781 | 781 | } |
@@ -786,12 +786,12 @@ discard block |
||
786 | 786 | logger::write('No table founded for backup, if your database has table : check $wanted_tables argument', loggerTypes::WARNING); |
787 | 787 | } |
788 | 788 | foreach ($tables as $table) { |
789 | - $sql .= self::query("SHOW CREATE TABLE `$table`")->fetch_row()[1] . ";\n\n"; |
|
789 | + $sql .= self::query("SHOW CREATE TABLE `$table`")->fetch_row()[1].";\n\n"; |
|
790 | 790 | if ($table_data) { |
791 | 791 | $total_rows = self::query("SELECT COUNT(*) as `cnt` FROM `$table`")->fetch_object()->cnt; |
792 | 792 | for ($i = 0; $i < $total_rows; $i = $i + 1000) { |
793 | - $sql .= 'INSERT INTO ' . $table . ' VALUES'; |
|
794 | - $result = self::select($table, '*' , [], 1000, $i); |
|
793 | + $sql .= 'INSERT INTO '.$table.' VALUES'; |
|
794 | + $result = self::select($table, '*', [], 1000, $i); |
|
795 | 795 | $field_count = $result->field_count; |
796 | 796 | $affected_rows = self::affected_rows(); |
797 | 797 | $counter = 1; |
@@ -799,12 +799,12 @@ discard block |
||
799 | 799 | $sql .= "\n("; |
800 | 800 | for ($column = 0; $column < $field_count; $column++) { |
801 | 801 | $row[$column] = str_replace("\n", "\\n", addslashes($row[$column])); |
802 | - $sql .= !empty($row[$column]) ? '"' . $row[$column] . '"' : '""'; |
|
802 | + $sql .= !empty($row[$column]) ? '"'.$row[$column].'"' : '""'; |
|
803 | 803 | if ($column < $field_count - 1) { |
804 | 804 | $sql .= ','; |
805 | 805 | } |
806 | 806 | } |
807 | - $sql .= ')' . ($counter == $affected_rows ? ';' : ','); |
|
807 | + $sql .= ')'.($counter == $affected_rows ? ';' : ','); |
|
808 | 808 | $counter++; |
809 | 809 | } |
810 | 810 | } |
@@ -820,7 +820,7 @@ discard block |
||
820 | 820 | } |
821 | 821 | |
822 | 822 | if (empty($file_name)) { |
823 | - $file_name = self::$db_name . time() . '.sql'; |
|
823 | + $file_name = self::$db_name.time().'.sql'; |
|
824 | 824 | } |
825 | 825 | file_put_contents($file_name, $sql); |
826 | 826 | return $file_name; |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | * |
15 | 15 | * @return $this |
16 | 16 | */ |
17 | - public function setGlobal (array $global): self { |
|
17 | + public function setGlobal(array $global): self { |
|
18 | 18 | $this->settings['global'] = $global; |
19 | 19 | return $this; |
20 | 20 | } |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * |
25 | 25 | * @return $this |
26 | 26 | */ |
27 | - public function setGroup (array $group): self { |
|
27 | + public function setGroup(array $group): self { |
|
28 | 28 | $this->settings['group'] = $group; |
29 | 29 | return $this; |
30 | 30 | } |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | * |
35 | 35 | * @return $this |
36 | 36 | */ |
37 | - public function setSuperGroup (array $supergroup): self { |
|
37 | + public function setSuperGroup(array $supergroup): self { |
|
38 | 38 | $this->settings['supergroup'] = $supergroup; |
39 | 39 | return $this; |
40 | 40 | } |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | * |
45 | 45 | * @return $this |
46 | 46 | */ |
47 | - public function setChannel (array $channel): self { |
|
47 | + public function setChannel(array $channel): self { |
|
48 | 48 | $this->settings['channel'] = $channel; |
49 | 49 | return $this; |
50 | 50 | } |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | * |
55 | 55 | * @return $this |
56 | 56 | */ |
57 | - public function setUser (array $user): self { |
|
57 | + public function setUser(array $user): self { |
|
58 | 58 | $this->settings['user'] = $user; |
59 | 59 | return $this; |
60 | 60 | } |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | * |
65 | 65 | * @return $this |
66 | 66 | */ |
67 | - public function setGroupUser (array $group_user): self { |
|
67 | + public function setGroupUser(array $group_user): self { |
|
68 | 68 | $this->settings['group_user'] = $group_user; |
69 | 69 | return $this; |
70 | 70 | } |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | /** |
73 | 73 | * @return array |
74 | 74 | */ |
75 | - public function getSettings (): array { |
|
75 | + public function getSettings(): array { |
|
76 | 76 | return $this->settings; |
77 | 77 | } |
78 | 78 | } |
79 | 79 | \ No newline at end of file |