@@ -12,19 +12,29 @@ discard block |
||
| 12 | 12 | |
| 13 | 13 | # Establish connection |
| 14 | 14 | |
| 15 | - if (false === ($link = @mysqli_connect($server, $user, $password))) throw new Exception\DBConnect(); |
|
| 15 | + if (false === ($link = @mysqli_connect($server, $user, $password))) { |
|
| 16 | + throw new Exception\DBConnect(); |
|
| 17 | + } |
|
| 16 | 18 | |
| 17 | 19 | # Select database |
| 18 | 20 | |
| 19 | - if (!@mysqli_select_db($link, $name)) throw new Exception\DBSelect(); |
|
| 21 | + if (!@mysqli_select_db($link, $name)) { |
|
| 22 | + throw new Exception\DBSelect(); |
|
| 23 | + } |
|
| 20 | 24 | |
| 21 | 25 | # Set encoding |
| 22 | 26 | |
| 23 | - if (!@mysqli_query($link, "SET character_set_client = 'utf8'")) throw new Exception\DBCharset(); |
|
| 27 | + if (!@mysqli_query($link, "SET character_set_client = 'utf8'")) { |
|
| 28 | + throw new Exception\DBCharset(); |
|
| 29 | + } |
|
| 24 | 30 | |
| 25 | - if (!@mysqli_query($link, "SET character_set_results = 'utf8'")) throw new Exception\DBCharset(); |
|
| 31 | + if (!@mysqli_query($link, "SET character_set_results = 'utf8'")) { |
|
| 32 | + throw new Exception\DBCharset(); |
|
| 33 | + } |
|
| 26 | 34 | |
| 27 | - if (!@mysqli_query($link, "SET collation_connection = 'utf8_general_ci'")) throw new Exception\DBCharset(); |
|
| 35 | + if (!@mysqli_query($link, "SET collation_connection = 'utf8_general_ci'")) { |
|
| 36 | + throw new Exception\DBCharset(); |
|
| 37 | + } |
|
| 28 | 38 | |
| 29 | 39 | # ------------------------ |
| 30 | 40 | |
@@ -35,7 +45,9 @@ discard block |
||
| 35 | 45 | |
| 36 | 46 | public static function send(string $query) { |
| 37 | 47 | |
| 38 | - if (null === self::$link) return (self::$last = false); |
|
| 48 | + if (null === self::$link) { |
|
| 49 | + return (self::$last = false); |
|
| 50 | + } |
|
| 39 | 51 | |
| 40 | 52 | $time = microtime(true); $result = mysqli_query(self::$link, $query); $time = (microtime(true) - $time); |
| 41 | 53 | |
@@ -22,9 +22,9 @@ |
||
| 22 | 22 | |
| 23 | 23 | # Build query |
| 24 | 24 | |
| 25 | - $this->query = ('SELECT ' . $selection . ' FROM ' . $table . ($condition ? (' WHERE (' . $condition . ')') : '') . |
|
| 25 | + $this->query = ('SELECT ' . $selection . ' FROM ' . $table . ($condition ? (' WHERE (' . $condition . ')') : '') . |
|
| 26 | 26 | |
| 27 | - ($order ? (' ORDER BY ' . $order) : '') . ($limit ? (' LIMIT ' . $limit) : '')); |
|
| 27 | + ($order ? (' ORDER BY ' . $order) : '') . ($limit ? (' LIMIT ' . $limit) : '')); |
|
| 28 | 28 | } |
| 29 | 29 | } |
| 30 | 30 | } |
@@ -20,9 +20,11 @@ |
||
| 20 | 20 | |
| 21 | 21 | $names = ''; $values = []; |
| 22 | 22 | |
| 23 | - foreach ($dataset as $key => $row) if (is_array($row)) { |
|
| 23 | + foreach ($dataset as $key => $row) { |
|
| 24 | + if (is_array($row)) { |
|
| 24 | 25 | |
| 25 | 26 | if (0 === $key) $names = $this->getString(array_keys($row), '$name', ', '); |
| 27 | + } |
|
| 26 | 28 | |
| 27 | 29 | $values[] = ('(' . $this->getString(array_values($row), '$value', ', ') . ')'); |
| 28 | 30 | } |
@@ -20,7 +20,7 @@ |
||
| 20 | 20 | |
| 21 | 21 | # Build query |
| 22 | 22 | |
| 23 | - $this->query = ('UPDATE ' . $table . ' SET ' . $dataset . ($condition ? (' WHERE (' . $condition . ')') : '')); |
|
| 23 | + $this->query = ('UPDATE ' . $table . ' SET ' . $dataset . ($condition ? (' WHERE (' . $condition . ')') : '')); |
|
| 24 | 24 | } |
| 25 | 25 | } |
| 26 | 26 | } |
@@ -18,7 +18,7 @@ |
||
| 18 | 18 | |
| 19 | 19 | # Build query |
| 20 | 20 | |
| 21 | - $this->query = ('DELETE FROM ' . $table . ($condition ? (' WHERE (' . $condition . ')') : '')); |
|
| 21 | + $this->query = ('DELETE FROM ' . $table . ($condition ? (' WHERE (' . $condition . ')') : '')); |
|
| 22 | 22 | } |
| 23 | 23 | } |
| 24 | 24 | } |
@@ -40,7 +40,9 @@ discard block |
||
| 40 | 40 | |
| 41 | 41 | public function row() { |
| 42 | 42 | |
| 43 | - if (!is_object($this->result)) return null; |
|
| 43 | + if (!is_object($this->result)) { |
|
| 44 | + return null; |
|
| 45 | + } |
|
| 44 | 46 | |
| 45 | 47 | return mysqli_fetch_assoc($this->result); |
| 46 | 48 | } |
@@ -49,9 +51,13 @@ discard block |
||
| 49 | 51 | |
| 50 | 52 | public function rows() { |
| 51 | 53 | |
| 52 | - if (!is_object($this->result)) return []; |
|
| 54 | + if (!is_object($this->result)) { |
|
| 55 | + return []; |
|
| 56 | + } |
|
| 53 | 57 | |
| 54 | - $rows = []; while (null !== ($row = $this->row())) $rows[] = $row; |
|
| 58 | + $rows = []; while (null !== ($row = $this->row())) { |
|
| 59 | + $rows[] = $row; |
|
| 60 | + } |
|
| 55 | 61 | |
| 56 | 62 | # ------------------------ |
| 57 | 63 | |
@@ -31,7 +31,9 @@ discard block |
||
| 31 | 31 | |
| 32 | 32 | protected function getString($source = null, string $pattern = '', string $separator = '') { |
| 33 | 33 | |
| 34 | - if (!is_array($source)) return (is_scalar($source) ? strval($source) : ''); |
|
| 34 | + if (!is_array($source)) { |
|
| 35 | + return (is_scalar($source) ? strval($source) : ''); |
|
| 36 | + } |
|
| 35 | 37 | |
| 36 | 38 | $regexs = ['key' => '/\^([a-z]+)/', 'value' => '/\$([a-z]+)/']; $matches = ['key' => [], 'value' => []]; |
| 37 | 39 | |
@@ -39,18 +41,25 @@ discard block |
||
| 39 | 41 | |
| 40 | 42 | # Parse pattern |
| 41 | 43 | |
| 42 | - foreach ($regexs as $name => $regex) preg_match($regex, $pattern, $matches[$name]); |
|
| 44 | + foreach ($regexs as $name => $regex) { |
|
| 45 | + preg_match($regex, $pattern, $matches[$name]); |
|
| 46 | + } |
|
| 43 | 47 | |
| 44 | 48 | # Process replacements |
| 45 | 49 | |
| 46 | - foreach ($source as $key => $value) if (is_scalar($value)) { |
|
| 50 | + foreach ($source as $key => $value) { |
|
| 51 | + if (is_scalar($value)) { |
|
| 47 | 52 | |
| 48 | - $output[$count] = $pattern; $item = &$output[$count++]; |
|
| 53 | + $output[$count] = $pattern; |
|
| 54 | + } |
|
| 55 | + $item = &$output[$count++]; |
|
| 49 | 56 | |
| 50 | - foreach ($matches as $name => $match) if (isset($match[1]) && isset($parsers[$match[1]])) { |
|
| 57 | + foreach ($matches as $name => $match) { |
|
| 58 | + if (isset($match[1]) && isset($parsers[$match[1]])) { |
|
| 51 | 59 | |
| 52 | 60 | $item = str_replace($match[0], [$this, $parsers[$match[1]]]($$name), $item); |
| 53 | 61 | } |
| 62 | + } |
|
| 54 | 63 | }; |
| 55 | 64 | |
| 56 | 65 | # ------------------------ |
@@ -117,7 +117,9 @@ discard block |
||
| 117 | 117 | |
| 118 | 118 | public static function status(string $code) { |
| 119 | 119 | |
| 120 | - if (self::isStatusCode($code)) header(getenv('SERVER_PROTOCOL') . ' ' . self::$status_codes[$code]); |
|
| 120 | + if (self::isStatusCode($code)) { |
|
| 121 | + header(getenv('SERVER_PROTOCOL') . ' ' . self::$status_codes[$code]); |
|
| 122 | + } |
|
| 121 | 123 | } |
| 122 | 124 | |
| 123 | 125 | # Send content header |
@@ -139,9 +141,13 @@ discard block |
||
| 139 | 141 | |
| 140 | 142 | public static function cache(string $limiter, int $expires) { |
| 141 | 143 | |
| 142 | - if (self::$cache_send) return; |
|
| 144 | + if (self::$cache_send) { |
|
| 145 | + return; |
|
| 146 | + } |
|
| 143 | 147 | |
| 144 | - if (!in_array($limiter, [CACHE_LIMITER_PRIVATE, CACHE_LIMITER_PUBLIC], true)) return; |
|
| 148 | + if (!in_array($limiter, [CACHE_LIMITER_PRIVATE, CACHE_LIMITER_PUBLIC], true)) { |
|
| 149 | + return; |
|
| 150 | + } |
|
| 145 | 151 | |
| 146 | 152 | header('Expires: ' . gmdate('D, d M Y H:i:s', (REQUEST_TIME + $expires)) . ' GMT'); |
| 147 | 153 | |
@@ -160,7 +166,9 @@ discard block |
||
| 160 | 166 | |
| 161 | 167 | public static function nocache() { |
| 162 | 168 | |
| 163 | - if (self::$cache_send) return; |
|
| 169 | + if (self::$cache_send) { |
|
| 170 | + return; |
|
| 171 | + } |
|
| 164 | 172 | |
| 165 | 173 | header('Expires: ' . gmdate('D, d M Y H:i:s', strtotime('-1 day')) . ' GMT'); |
| 166 | 174 | |
@@ -19,7 +19,9 @@ |
||
| 19 | 19 | |
| 20 | 20 | public function error(string $value = null) { |
| 21 | 21 | |
| 22 | - if (null !== $value) $this->set('error', $value); |
|
| 22 | + if (null !== $value) { |
|
| 23 | + $this->set('error', $value); |
|
| 24 | + } |
|
| 23 | 25 | |
| 24 | 26 | $this->status = false; |
| 25 | 27 | |