@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | /** |
| 28 | 28 | * @internal Only for BPT self usage , Don't use it in your source! |
| 29 | 29 | */ |
| 30 | - public static function init (): void { |
|
| 30 | + public static function init(): void { |
|
| 31 | 31 | $host = settings::$db['host'] ?? 'localhost'; |
| 32 | 32 | $port = settings::$db['port'] ?? 3306; |
| 33 | 33 | $user = settings::$db['user'] ?? settings::$db['username'] ?? 'unknown'; |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | $dbname = settings::$db['dbname']; |
| 37 | 37 | self::$connection = new mysqli($host, $user, $pass, $dbname, $port); |
| 38 | 38 | if (self::$connection->connect_errno) { |
| 39 | - logger::write('SQL connection has problem : ' . self::$connection->connect_error, loggerTypes::ERROR); |
|
| 39 | + logger::write('SQL connection has problem : '.self::$connection->connect_error, loggerTypes::ERROR); |
|
| 40 | 40 | throw new bptException('SQL_CONNECTION_PROBLEM'); |
| 41 | 41 | } |
| 42 | 42 | if (self::$auto_process && !lock::exist('BPT-MYSQL')) { |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | } |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | - private static function install (): void { |
|
| 47 | + private static function install(): void { |
|
| 48 | 48 | self::pureQuery(" |
| 49 | 49 | CREATE TABLE `users` |
| 50 | 50 | ( |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | /** |
| 66 | 66 | * @internal Only for BPT self usage , Don't use it in your source! |
| 67 | 67 | */ |
| 68 | - public static function process (): void { |
|
| 68 | + public static function process(): void { |
|
| 69 | 69 | if (self::$auto_process) { |
| 70 | 70 | if (isset(BPT::$update->message)) { |
| 71 | 71 | self::processMessage(BPT::$update->message); |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | } |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | - private static function processMessage (message $update): void { |
|
| 88 | + private static function processMessage(message $update): void { |
|
| 89 | 89 | $type = $update->chat->type; |
| 90 | 90 | if ($type === chatType::PRIVATE) { |
| 91 | 91 | $user_id = $update->from->id; |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | } |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | - private static function processCallbackQuery (callbackQuery $update): void { |
|
| 114 | + private static function processCallbackQuery(callbackQuery $update): void { |
|
| 115 | 115 | $type = $update->message->chat->type; |
| 116 | 116 | if ($type === chatType::PRIVATE) { |
| 117 | 117 | $user_id = $update->from->id; |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | } |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | - private static function processInlineQuery (inlineQuery $update): void { |
|
| 124 | + private static function processInlineQuery(inlineQuery $update): void { |
|
| 125 | 125 | $type = $update->chat_type; |
| 126 | 126 | if ($type === chatType::PRIVATE || $type === chatType::SENDER) { |
| 127 | 127 | $user_id = $update->from->id; |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | } |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | - private static function processMyChatMember (chatMemberUpdated $update): void { |
|
| 134 | + private static function processMyChatMember(chatMemberUpdated $update): void { |
|
| 135 | 135 | $type = $update->chat->type; |
| 136 | 136 | if ($type === chatType::PRIVATE) { |
| 137 | 137 | if ($update->new_chat_member->status === chatMemberStatus::MEMBER) { |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | * |
| 149 | 149 | * @return mysqli |
| 150 | 150 | */ |
| 151 | - public static function getMysqli (): mysqli { |
|
| 151 | + public static function getMysqli(): mysqli { |
|
| 152 | 152 | return self::$connection; |
| 153 | 153 | } |
| 154 | 154 | |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | * |
| 158 | 158 | * @return int|string |
| 159 | 159 | */ |
| 160 | - public static function affected_rows (): int|string { |
|
| 160 | + public static function affected_rows(): int | string { |
|
| 161 | 161 | return self::$connection->affected_rows; |
| 162 | 162 | } |
| 163 | 163 | |
@@ -166,7 +166,7 @@ discard block |
||
| 166 | 166 | * |
| 167 | 167 | * @return int|string |
| 168 | 168 | */ |
| 169 | - public static function insert_id (): int|string { |
|
| 169 | + public static function insert_id(): int | string { |
|
| 170 | 170 | return self::$connection->insert_id; |
| 171 | 171 | } |
| 172 | 172 | |
@@ -177,7 +177,7 @@ discard block |
||
| 177 | 177 | * |
| 178 | 178 | * @return string |
| 179 | 179 | */ |
| 180 | - public static function escapeString (string $text): string { |
|
| 180 | + public static function escapeString(string $text): string { |
|
| 181 | 181 | return self::$connection->real_escape_string($text); |
| 182 | 182 | } |
| 183 | 183 | |
@@ -192,7 +192,7 @@ discard block |
||
| 192 | 192 | * |
| 193 | 193 | * @return mysqli_result|bool |
| 194 | 194 | */ |
| 195 | - public static function pureQuery (string $query): mysqli_result|bool { |
|
| 195 | + public static function pureQuery(string $query): mysqli_result | bool { |
|
| 196 | 196 | return self::$connection->query($query); |
| 197 | 197 | } |
| 198 | 198 | |
@@ -211,7 +211,7 @@ discard block |
||
| 211 | 211 | * |
| 212 | 212 | * @return mysqli_result|bool |
| 213 | 213 | */ |
| 214 | - public static function query (string $query, array $vars = [], bool $need_result = true): mysqli_result|bool { |
|
| 214 | + public static function query(string $query, array $vars = [], bool $need_result = true): mysqli_result | bool { |
|
| 215 | 215 | $prepare = self::$connection->prepare($query); |
| 216 | 216 | $types = ''; |
| 217 | 217 | foreach ($vars as $var) { |
@@ -225,7 +225,7 @@ discard block |
||
| 225 | 225 | $types .= 's'; |
| 226 | 226 | } |
| 227 | 227 | } |
| 228 | - $prepare->bind_param($types,...$vars); |
|
| 228 | + $prepare->bind_param($types, ...$vars); |
|
| 229 | 229 | if (!$prepare->execute()) { |
| 230 | 230 | logger::write(loggerTypes::WARNING, $prepare->error); |
| 231 | 231 | return false; |
@@ -233,7 +233,7 @@ discard block |
||
| 233 | 233 | return $need_result ? $prepare->get_result() : true; |
| 234 | 234 | } |
| 235 | 235 | |
| 236 | - private static function makeArrayReady (string &$query, array $array, string $operator = ' AND '): array { |
|
| 236 | + private static function makeArrayReady(string &$query, array $array, string $operator = ' AND '): array { |
|
| 237 | 237 | $first = true; |
| 238 | 238 | $values = []; |
| 239 | 239 | foreach ($array as $name => $value) { |
@@ -249,7 +249,7 @@ discard block |
||
| 249 | 249 | return $values; |
| 250 | 250 | } |
| 251 | 251 | |
| 252 | - private static function makeQueryReady (string &$query, array $where = null, int $count = null, int $offset = null): array { |
|
| 252 | + private static function makeQueryReady(string &$query, array $where = null, int $count = null, int $offset = null): array { |
|
| 253 | 253 | $values = []; |
| 254 | 254 | if (!empty($where)) { |
| 255 | 255 | $query .= " WHERE"; |
@@ -276,7 +276,7 @@ discard block |
||
| 276 | 276 | * |
| 277 | 277 | * @return mysqli_result|bool |
| 278 | 278 | */ |
| 279 | - public static function delete (string $table, array $where = null, int $count = null, int $offset = null): mysqli_result|bool { |
|
| 279 | + public static function delete(string $table, array $where = null, int $count = null, int $offset = null): mysqli_result | bool { |
|
| 280 | 280 | $query = "DELETE FROM `$table`"; |
| 281 | 281 | $res = self::makeQueryReady($query, $where, $count, $offset); |
| 282 | 282 | return self::query($query, $res, false); |
@@ -295,7 +295,7 @@ discard block |
||
| 295 | 295 | * |
| 296 | 296 | * @return mysqli_result|bool |
| 297 | 297 | */ |
| 298 | - public static function update (string $table, array $modify, array $where = null, int $count = null, int $offset = null): mysqli_result|bool { |
|
| 298 | + public static function update(string $table, array $modify, array $where = null, int $count = null, int $offset = null): mysqli_result | bool { |
|
| 299 | 299 | $query = "UPDATE `$table` SET"; |
| 300 | 300 | $values = self::makeArrayReady($query, $modify, ', '); |
| 301 | 301 | $res = self::makeQueryReady($query, $where, $count, $offset); |
@@ -313,11 +313,11 @@ discard block |
||
| 313 | 313 | * |
| 314 | 314 | * @return mysqli_result|bool |
| 315 | 315 | */ |
| 316 | - public static function insert (string $table, string|array $columns, array|string $values): mysqli_result|bool { |
|
| 316 | + public static function insert(string $table, string | array $columns, array | string $values): mysqli_result | bool { |
|
| 317 | 317 | $query = "INSERT INTO `$table`("; |
| 318 | - $query .= '`' . (is_string($columns) ? $columns : implode('`,`', $columns)) . '`) VALUES ('; |
|
| 318 | + $query .= '`'.(is_string($columns) ? $columns : implode('`,`', $columns)).'`) VALUES ('; |
|
| 319 | 319 | if (is_string($values)) $values = [$values]; |
| 320 | - $query .= '?' . str_repeat(',?', count($values) - 1) . ')'; |
|
| 320 | + $query .= '?'.str_repeat(',?', count($values) - 1).')'; |
|
| 321 | 321 | return self::query($query, $values, false); |
| 322 | 322 | } |
| 323 | 323 | |
@@ -336,13 +336,13 @@ discard block |
||
| 336 | 336 | * |
| 337 | 337 | * @return mysqli_result|bool |
| 338 | 338 | */ |
| 339 | - public static function select (string $table, array|string $columns = '*', array $where = null, int $count = null, int $offset = null): mysqli_result|bool { |
|
| 339 | + public static function select(string $table, array | string $columns = '*', array $where = null, int $count = null, int $offset = null): mysqli_result | bool { |
|
| 340 | 340 | $query = "SELECT "; |
| 341 | 341 | if ($columns == '*') { |
| 342 | 342 | $query .= "* "; |
| 343 | 343 | } |
| 344 | 344 | else { |
| 345 | - $query .= '`' . (is_string($columns) ? $columns : implode('`,`', $columns)) . '` '; |
|
| 345 | + $query .= '`'.(is_string($columns) ? $columns : implode('`,`', $columns)).'` '; |
|
| 346 | 346 | } |
| 347 | 347 | $query .= "FROM `$table`"; |
| 348 | 348 | $res = self::makeQueryReady($query, $where, $count, $offset); |
@@ -360,7 +360,7 @@ discard block |
||
| 360 | 360 | * |
| 361 | 361 | * @return null|bool|array |
| 362 | 362 | */ |
| 363 | - public static function selectArray (string $table, array|string $columns = '*', array $where = null): bool|array|null { |
|
| 363 | + public static function selectArray(string $table, array | string $columns = '*', array $where = null): bool | array | null { |
|
| 364 | 364 | $res = self::select($table, $columns, $where, 1); |
| 365 | 365 | if ($res) { |
| 366 | 366 | return $res->fetch_assoc(); |
@@ -377,7 +377,7 @@ discard block |
||
| 377 | 377 | * @param array|string $columns sets column that you want to retrieve , set '*' to retrieve all , default : '*' |
| 378 | 378 | * @param array|null $where Set your ifs default : null |
| 379 | 379 | */ |
| 380 | - public static function selectObject (string $table, array|string $columns = '*', array $where = null) { |
|
| 380 | + public static function selectObject(string $table, array | string $columns = '*', array $where = null) { |
|
| 381 | 381 | $res = self::select($table, $columns, $where, 1); |
| 382 | 382 | if ($res) { |
| 383 | 383 | return $res->fetch_object(); |
@@ -399,7 +399,7 @@ discard block |
||
| 399 | 399 | * |
| 400 | 400 | * @return bool|Generator |
| 401 | 401 | */ |
| 402 | - public static function selectEach (string $table, array|string $columns = '*', array $where = null, int $count = null, int $offset = null): bool|Generator { |
|
| 402 | + public static function selectEach(string $table, array | string $columns = '*', array $where = null, int $count = null, int $offset = null): bool | Generator { |
|
| 403 | 403 | $res = self::select($table, $columns, $where, $count, $offset); |
| 404 | 404 | if ($res) { |
| 405 | 405 | while ($row = $res->fetch_assoc()) yield $row; |
@@ -69,17 +69,13 @@ discard block |
||
| 69 | 69 | if (self::$auto_process) { |
| 70 | 70 | if (isset(BPT::$update->message)) { |
| 71 | 71 | self::processMessage(BPT::$update->message); |
| 72 | - } |
|
| 73 | - elseif (isset(BPT::$update->edited_message)) { |
|
| 72 | + } elseif (isset(BPT::$update->edited_message)) { |
|
| 74 | 73 | self::processMessage(BPT::$update->edited_message); |
| 75 | - } |
|
| 76 | - elseif (isset(BPT::$update->callback_query)) { |
|
| 74 | + } elseif (isset(BPT::$update->callback_query)) { |
|
| 77 | 75 | self::processCallbackQuery(BPT::$update->callback_query); |
| 78 | - } |
|
| 79 | - elseif (isset(BPT::$update->inline_query)) { |
|
| 76 | + } elseif (isset(BPT::$update->inline_query)) { |
|
| 80 | 77 | self::processInlineQuery(BPT::$update->inline_query); |
| 81 | - } |
|
| 82 | - elseif (isset(BPT::$update->my_chat_member)) { |
|
| 78 | + } elseif (isset(BPT::$update->my_chat_member)) { |
|
| 83 | 79 | self::processMyChatMember(BPT::$update->my_chat_member); |
| 84 | 80 | } |
| 85 | 81 | } |
@@ -136,8 +132,7 @@ discard block |
||
| 136 | 132 | if ($type === chatType::PRIVATE) { |
| 137 | 133 | if ($update->new_chat_member->status === chatMemberStatus::MEMBER) { |
| 138 | 134 | self::update('users', ['blocked' => false], ['id' => $update->from->id], 1); |
| 139 | - } |
|
| 140 | - else { |
|
| 135 | + } else { |
|
| 141 | 136 | self::update('users', ['blocked' => true], ['id' => $update->from->id], 1); |
| 142 | 137 | } |
| 143 | 138 | } |
@@ -217,11 +212,9 @@ discard block |
||
| 217 | 212 | foreach ($vars as $var) { |
| 218 | 213 | if (is_int($var)) { |
| 219 | 214 | $types .= 'i'; |
| 220 | - } |
|
| 221 | - elseif (is_double($var)) { |
|
| 215 | + } elseif (is_double($var)) { |
|
| 222 | 216 | $types .= 'd'; |
| 223 | - } |
|
| 224 | - else { |
|
| 217 | + } else { |
|
| 225 | 218 | $types .= 's'; |
| 226 | 219 | } |
| 227 | 220 | } |
@@ -239,8 +232,7 @@ discard block |
||
| 239 | 232 | foreach ($array as $name => $value) { |
| 240 | 233 | if ($first) { |
| 241 | 234 | $first = false; |
| 242 | - } |
|
| 243 | - else { |
|
| 235 | + } else { |
|
| 244 | 236 | $query .= $operator; |
| 245 | 237 | } |
| 246 | 238 | $query .= " `$name` = ?"; |
@@ -257,8 +249,7 @@ discard block |
||
| 257 | 249 | } |
| 258 | 250 | if (!empty($count)) { |
| 259 | 251 | $query .= !empty($offset) ? " LIMIT $offset,$count" : " LIMIT $count"; |
| 260 | - } |
|
| 261 | - elseif (!empty($offset)) { |
|
| 252 | + } elseif (!empty($offset)) { |
|
| 262 | 253 | $query .= " OFFSET $offset"; |
| 263 | 254 | } |
| 264 | 255 | return $values; |
@@ -316,7 +307,9 @@ discard block |
||
| 316 | 307 | public static function insert (string $table, string|array $columns, array|string $values): mysqli_result|bool { |
| 317 | 308 | $query = "INSERT INTO `$table`("; |
| 318 | 309 | $query .= '`' . (is_string($columns) ? $columns : implode('`,`', $columns)) . '`) VALUES ('; |
| 319 | - if (is_string($values)) $values = [$values]; |
|
| 310 | + if (is_string($values)) { |
|
| 311 | + $values = [$values]; |
|
| 312 | + } |
|
| 320 | 313 | $query .= '?' . str_repeat(',?', count($values) - 1) . ')'; |
| 321 | 314 | return self::query($query, $values, false); |
| 322 | 315 | } |
@@ -340,8 +333,7 @@ discard block |
||
| 340 | 333 | $query = "SELECT "; |
| 341 | 334 | if ($columns == '*') { |
| 342 | 335 | $query .= "* "; |
| 343 | - } |
|
| 344 | - else { |
|
| 336 | + } else { |
|
| 345 | 337 | $query .= '`' . (is_string($columns) ? $columns : implode('`,`', $columns)) . '` '; |
| 346 | 338 | } |
| 347 | 339 | $query .= "FROM `$table`"; |
@@ -402,8 +394,11 @@ discard block |
||
| 402 | 394 | public static function selectEach (string $table, array|string $columns = '*', array $where = null, int $count = null, int $offset = null): bool|Generator { |
| 403 | 395 | $res = self::select($table, $columns, $where, $count, $offset); |
| 404 | 396 | if ($res) { |
| 405 | - while ($row = $res->fetch_assoc()) yield $row; |
|
| 397 | + while ($row = $res->fetch_assoc()) { |
|
| 398 | + yield $row; |
|
| 399 | + } |
|
| 400 | + } else { |
|
| 401 | + return $res; |
|
| 406 | 402 | } |
| 407 | - else return $res; |
|
| 408 | 403 | } |
| 409 | 404 | } |
| 410 | 405 | \ No newline at end of file |