@@ -19,17 +19,17 @@ |
||
| 19 | 19 | |
| 20 | 20 | # Check basic types |
| 21 | 21 | |
| 22 | - if (is_string ($default)) return function(string $value) { return $value; }; |
|
| 22 | + if (is_string($default)) return function(string $value) { return $value; }; |
|
| 23 | 23 | |
| 24 | - if (is_bool ($default)) return function(bool $value) { return $value; }; |
|
| 24 | + if (is_bool($default)) return function(bool $value) { return $value; }; |
|
| 25 | 25 | |
| 26 | - if (is_int ($default)) return function(int $value) { return $value; }; |
|
| 26 | + if (is_int($default)) return function(int $value) { return $value; }; |
|
| 27 | 27 | |
| 28 | - if (is_float ($default)) return function(float $value) { return $value; }; |
|
| 28 | + if (is_float($default)) return function(float $value) { return $value; }; |
|
| 29 | 29 | |
| 30 | - if (is_array ($default)) return function(array $value) { return $value; }; |
|
| 30 | + if (is_array($default)) return function(array $value) { return $value; }; |
|
| 31 | 31 | |
| 32 | - if (is_callable ($default)) return function(callable $value) { return $value; }; |
|
| 32 | + if (is_callable($default)) return function(callable $value) { return $value; }; |
|
| 33 | 33 | |
| 34 | 34 | # Check object type |
| 35 | 35 | |
@@ -19,28 +19,51 @@ |
||
| 19 | 19 | |
| 20 | 20 | # Check basic types |
| 21 | 21 | |
| 22 | - if (is_string ($default)) return function(string $value) { return $value; }; |
|
| 22 | + if (is_string ($default)) { |
|
| 23 | + return function(string $value) { return $value; |
|
| 24 | + } |
|
| 25 | + }; |
|
| 23 | 26 | |
| 24 | - if (is_bool ($default)) return function(bool $value) { return $value; }; |
|
| 27 | + if (is_bool ($default)) { |
|
| 28 | + return function(bool $value) { return $value; |
|
| 29 | + } |
|
| 30 | + }; |
|
| 25 | 31 | |
| 26 | - if (is_int ($default)) return function(int $value) { return $value; }; |
|
| 32 | + if (is_int ($default)) { |
|
| 33 | + return function(int $value) { return $value; |
|
| 34 | + } |
|
| 35 | + }; |
|
| 27 | 36 | |
| 28 | - if (is_float ($default)) return function(float $value) { return $value; }; |
|
| 37 | + if (is_float ($default)) { |
|
| 38 | + return function(float $value) { return $value; |
|
| 39 | + } |
|
| 40 | + }; |
|
| 29 | 41 | |
| 30 | - if (is_array ($default)) return function(array $value) { return $value; }; |
|
| 42 | + if (is_array ($default)) { |
|
| 43 | + return function(array $value) { return $value; |
|
| 44 | + } |
|
| 45 | + }; |
|
| 31 | 46 | |
| 32 | - if (is_callable ($default)) return function(callable $value) { return $value; }; |
|
| 47 | + if (is_callable ($default)) { |
|
| 48 | + return function(callable $value) { return $value; |
|
| 49 | + } |
|
| 50 | + }; |
|
| 33 | 51 | |
| 34 | 52 | # Check object type |
| 35 | 53 | |
| 36 | - if (is_object($default)) return function($value) use($default) { |
|
| 54 | + if (is_object($default)) { |
|
| 55 | + return function($value) use($default) { |
|
| 37 | 56 | |
| 38 | 57 | return (is_a($value, get_class($default)) ? $value : null); |
| 58 | + } |
|
| 39 | 59 | }; |
| 40 | 60 | |
| 41 | 61 | # Check resource type |
| 42 | 62 | |
| 43 | - if (is_resource($default)) return function($value) { return (is_resource($value) ? $value : null); }; |
|
| 63 | + if (is_resource($default)) { |
|
| 64 | + return function($value) { return (is_resource($value) ? $value : null); |
|
| 65 | + } |
|
| 66 | + }; |
|
| 44 | 67 | |
| 45 | 68 | # ------------------------ |
| 46 | 69 | |
@@ -29,9 +29,11 @@ |
||
| 29 | 29 | |
| 30 | 30 | $names = ''; $values = []; |
| 31 | 31 | |
| 32 | - foreach ($set as $key => $row) if (is_array($row)) { |
|
| 32 | + foreach ($set as $key => $row) { |
|
| 33 | + if (is_array($row)) { |
|
| 33 | 34 | |
| 34 | 35 | if (0 === $key) $names = $this->getString(array_keys($row), '$name', ', '); |
| 36 | + } |
|
| 35 | 37 | |
| 36 | 38 | $values[] = ('(' . $this->getString(array_values($row), '$value', ', ') . ')'); |
| 37 | 39 | } |
@@ -29,7 +29,7 @@ |
||
| 29 | 29 | |
| 30 | 30 | # Build query |
| 31 | 31 | |
| 32 | - $this->query = ('UPDATE ' . $table . ' SET ' . $set . ($condition ? (' WHERE (' . $condition . ')') : '')); |
|
| 32 | + $this->query = ('UPDATE '.$table.' SET '.$set.($condition ? (' WHERE ('.$condition.')') : '')); |
|
| 33 | 33 | } |
| 34 | 34 | } |
| 35 | 35 | } |
@@ -21,19 +21,29 @@ discard block |
||
| 21 | 21 | |
| 22 | 22 | # Establish connection |
| 23 | 23 | |
| 24 | - if (false === ($link = mysqli_connect($server, $user, $password))) throw new Exception\DBConnect(); |
|
| 24 | + if (false === ($link = mysqli_connect($server, $user, $password))) { |
|
| 25 | + throw new Exception\DBConnect(); |
|
| 26 | + } |
|
| 25 | 27 | |
| 26 | 28 | # Select database |
| 27 | 29 | |
| 28 | - if (!mysqli_select_db($link, $name)) throw new Exception\DBSelect(); |
|
| 30 | + if (!mysqli_select_db($link, $name)) { |
|
| 31 | + throw new Exception\DBSelect(); |
|
| 32 | + } |
|
| 29 | 33 | |
| 30 | 34 | # Set encoding |
| 31 | 35 | |
| 32 | - if (!mysqli_query($link, "SET character_set_client = 'utf8'")) throw new Exception\DBCharset(); |
|
| 36 | + if (!mysqli_query($link, "SET character_set_client = 'utf8'")) { |
|
| 37 | + throw new Exception\DBCharset(); |
|
| 38 | + } |
|
| 33 | 39 | |
| 34 | - if (!mysqli_query($link, "SET character_set_results = 'utf8'")) throw new Exception\DBCharset(); |
|
| 40 | + if (!mysqli_query($link, "SET character_set_results = 'utf8'")) { |
|
| 41 | + throw new Exception\DBCharset(); |
|
| 42 | + } |
|
| 35 | 43 | |
| 36 | - if (!mysqli_query($link, "SET collation_connection = 'utf8_general_ci'")) throw new Exception\DBCharset(); |
|
| 44 | + if (!mysqli_query($link, "SET collation_connection = 'utf8_general_ci'")) { |
|
| 45 | + throw new Exception\DBCharset(); |
|
| 46 | + } |
|
| 37 | 47 | |
| 38 | 48 | # ------------------------ |
| 39 | 49 | |
@@ -48,7 +58,9 @@ discard block |
||
| 48 | 58 | |
| 49 | 59 | public static function send(string $query) { |
| 50 | 60 | |
| 51 | - if (null === self::$link) return (self::$last = false); |
|
| 61 | + if (null === self::$link) { |
|
| 62 | + return (self::$last = false); |
|
| 63 | + } |
|
| 52 | 64 | |
| 53 | 65 | $time = microtime(true); $result = mysqli_query(self::$link, $query); $time = (microtime(true) - $time); |
| 54 | 66 | |
@@ -56,7 +56,9 @@ discard block |
||
| 56 | 56 | |
| 57 | 57 | public function getRow() { |
| 58 | 58 | |
| 59 | - if (!is_object($this->result)) return null; |
|
| 59 | + if (!is_object($this->result)) { |
|
| 60 | + return null; |
|
| 61 | + } |
|
| 60 | 62 | |
| 61 | 63 | return mysqli_fetch_assoc($this->result); |
| 62 | 64 | } |
@@ -67,9 +69,13 @@ discard block |
||
| 67 | 69 | |
| 68 | 70 | public function getRows() { |
| 69 | 71 | |
| 70 | - if (!is_object($this->result)) return []; |
|
| 72 | + if (!is_object($this->result)) { |
|
| 73 | + return []; |
|
| 74 | + } |
|
| 71 | 75 | |
| 72 | - $rows = []; while (null !== ($row = $this->getRow())) $rows[] = $row; |
|
| 76 | + $rows = []; while (null !== ($row = $this->getRow())) { |
|
| 77 | + $rows[] = $row; |
|
| 78 | + } |
|
| 73 | 79 | |
| 74 | 80 | # ------------------------ |
| 75 | 81 | |
@@ -36,7 +36,9 @@ |
||
| 36 | 36 | |
| 37 | 37 | public function addItems(array $items) { |
| 38 | 38 | |
| 39 | - foreach ($items as $item) if (is_array($item)) $this->addItem($item); |
|
| 39 | + foreach ($items as $item) { |
|
| 40 | + if (is_array($item)) $this->addItem($item); |
|
| 41 | + } |
|
| 40 | 42 | |
| 41 | 43 | return $this; |
| 42 | 44 | } |
@@ -95,7 +95,9 @@ |
||
| 95 | 95 | |
| 96 | 96 | public static function output(Template\Block $block, int $status = STATUS_CODE_200) { |
| 97 | 97 | |
| 98 | - if (!Headers::isStatusCode($status)) $status = STATUS_CODE_200; |
|
| 98 | + if (!Headers::isStatusCode($status)) { |
|
| 99 | + $status = STATUS_CODE_200; |
|
| 100 | + } |
|
| 99 | 101 | |
| 100 | 102 | Headers::sendNoCache(); Headers::sendStatus($status); Headers::sendContent(MIME_TYPE_HTML); |
| 101 | 103 | |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | |
| 36 | 36 | if (!preg_match(REGEX_TEMPLATE_COMPONENT_NAME, $name)) continue; |
| 37 | 37 | |
| 38 | - $this->contents = str_replace($match, ('{ ' . $type . ':' . $name . ' / }'), $this->contents); |
|
| 38 | + $this->contents = str_replace($match, ('{ '.$type.':'.$name.' / }'), $this->contents); |
|
| 39 | 39 | |
| 40 | 40 | if ($type === 'block') $this->blocks[$name] = (new Block($contents))->$toggle(); |
| 41 | 41 | |
@@ -51,9 +51,9 @@ discard block |
||
| 51 | 51 | |
| 52 | 52 | private function parseElementaries() { |
| 53 | 53 | |
| 54 | - $variables = ['pattern' => REGEX_TEMPLATE_VARIABLE, 'stack' => &$this->variables ]; |
|
| 54 | + $variables = ['pattern' => REGEX_TEMPLATE_VARIABLE, 'stack' => &$this->variables]; |
|
| 55 | 55 | |
| 56 | - $phrases = ['pattern' => REGEX_TEMPLATE_PHRASE, 'stack' => &$this->phrases ]; |
|
| 56 | + $phrases = ['pattern' => REGEX_TEMPLATE_PHRASE, 'stack' => &$this->phrases]; |
|
| 57 | 57 | |
| 58 | 58 | foreach ([$variables, $phrases] as $elementaries) { |
| 59 | 59 | |
@@ -80,14 +80,14 @@ discard block |
||
| 80 | 80 | |
| 81 | 81 | foreach ($this->blocks as $name => $block) { |
| 82 | 82 | |
| 83 | - $insertions['{ block:' . $name . ' / }'] = $block->getContents(); |
|
| 83 | + $insertions['{ block:'.$name.' / }'] = $block->getContents(); |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | # Process loops |
| 87 | 87 | |
| 88 | 88 | foreach ($this->loops as $name => $loop) { |
| 89 | 89 | |
| 90 | - $insertions['{ for:' . $name . ' / }'] = $loop->getContents(); |
|
| 90 | + $insertions['{ for:'.$name.' / }'] = $loop->getContents(); |
|
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | # Process widgets |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | |
| 99 | 99 | $contents = ((false !== $widget) ? $widget->getContents() : ''); |
| 100 | 100 | |
| 101 | - $insertions['{ widget:' . $name . ' / }'] = $contents; |
|
| 101 | + $insertions['{ widget:'.$name.' / }'] = $contents; |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | # Process variables |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | |
| 108 | 108 | $value = ((false === $value) ? Template::getGlobal($name) : $value); |
| 109 | 109 | |
| 110 | - $insertions['$' . $name . '$'] = Str::formatOutput($value); |
|
| 110 | + $insertions['$'.$name.'$'] = Str::formatOutput($value); |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | # Process phrases |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | |
| 117 | 117 | $value = Language::get($name); |
| 118 | 118 | |
| 119 | - $insertions['%' . $name . '%'] = Str::formatOutput($value); |
|
| 119 | + $insertions['%'.$name.'%'] = Str::formatOutput($value); |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | # Process insertions |
@@ -31,15 +31,19 @@ discard block |
||
| 31 | 31 | |
| 32 | 32 | $type = $matches[2][$key]; $name = $matches[3][$key]; $contents = ($matches[4][$key] ?? ''); |
| 33 | 33 | |
| 34 | - if (!preg_match(REGEX_TEMPLATE_COMPONENT_NAME, $name)) continue; |
|
| 34 | + if (!preg_match(REGEX_TEMPLATE_COMPONENT_NAME, $name)) { |
|
| 35 | + continue; |
|
| 36 | + } |
|
| 35 | 37 | |
| 36 | 38 | $this->contents = str_replace($match, ('{ ' . $type . ':' . $name . ' / }'), $this->contents); |
| 37 | 39 | |
| 38 | - if ($type === 'block') $this->blocks[$name] = (new Block($contents))->$toggle(); |
|
| 39 | - |
|
| 40 | - else if ($type === 'for') $this->loops[$name] = new Loop($contents); |
|
| 41 | - |
|
| 42 | - else if ($type === 'widget') $this->widgets[] = $name; |
|
| 40 | + if ($type === 'block') { |
|
| 41 | + $this->blocks[$name] = (new Block($contents))->$toggle(); |
|
| 42 | + } else if ($type === 'for') { |
|
| 43 | + $this->loops[$name] = new Loop($contents); |
|
| 44 | + } else if ($type === 'widget') { |
|
| 45 | + $this->widgets[] = $name; |
|
| 46 | + } |
|
| 43 | 47 | } |
| 44 | 48 | } |
| 45 | 49 | |
@@ -59,7 +63,9 @@ discard block |
||
| 59 | 63 | |
| 60 | 64 | foreach ($matches[1] as $index => $name) { |
| 61 | 65 | |
| 62 | - if (!preg_match(REGEX_TEMPLATE_COMPONENT_NAME, $name)) continue; |
|
| 66 | + if (!preg_match(REGEX_TEMPLATE_COMPONENT_NAME, $name)) { |
|
| 67 | + continue; |
|
| 68 | + } |
|
| 63 | 69 | |
| 64 | 70 | $elementaries['stack'][$name] = false; |
| 65 | 71 | } |
@@ -143,11 +149,17 @@ discard block |
||
| 143 | 149 | |
| 144 | 150 | public function __clone() { |
| 145 | 151 | |
| 146 | - foreach ($this->blocks as $name => $block) $this->blocks[$name] = clone $block; |
|
| 152 | + foreach ($this->blocks as $name => $block) { |
|
| 153 | + $this->blocks[$name] = clone $block; |
|
| 154 | + } |
|
| 147 | 155 | |
| 148 | - foreach ($this->loops as $name => $loop) $this->loops[$name] = clone $loop; |
|
| 156 | + foreach ($this->loops as $name => $loop) { |
|
| 157 | + $this->loops[$name] = clone $loop; |
|
| 158 | + } |
|
| 149 | 159 | |
| 150 | - foreach ($this->items as $name => $item) $this->items[$name] = clone $item; |
|
| 160 | + foreach ($this->items as $name => $item) { |
|
| 161 | + $this->items[$name] = clone $item; |
|
| 162 | + } |
|
| 151 | 163 | } |
| 152 | 164 | |
| 153 | 165 | /** |
@@ -158,11 +170,13 @@ discard block |
||
| 158 | 170 | |
| 159 | 171 | public function set(string $name, $value) : Block { |
| 160 | 172 | |
| 161 | - if ($value instanceof Block) $this->setBlock($name, $value); |
|
| 162 | - |
|
| 163 | - else if (is_array($value)) $this->setLoop($name, $value); |
|
| 164 | - |
|
| 165 | - else if (is_scalar($value)) $this->setVar($name, $value); |
|
| 173 | + if ($value instanceof Block) { |
|
| 174 | + $this->setBlock($name, $value); |
|
| 175 | + } else if (is_array($value)) { |
|
| 176 | + $this->setLoop($name, $value); |
|
| 177 | + } else if (is_scalar($value)) { |
|
| 178 | + $this->setVar($name, $value); |
|
| 179 | + } |
|
| 166 | 180 | |
| 167 | 181 | # ------------------------ |
| 168 | 182 | |
@@ -177,7 +191,9 @@ discard block |
||
| 177 | 191 | |
| 178 | 192 | public function setArray(array $components) : Block { |
| 179 | 193 | |
| 180 | - foreach ($components as $name => $component) $this->set($name, $component); |
|
| 194 | + foreach ($components as $name => $component) { |
|
| 195 | + $this->set($name, $component); |
|
| 196 | + } |
|
| 181 | 197 | |
| 182 | 198 | return $this; |
| 183 | 199 | } |
@@ -190,7 +206,9 @@ discard block |
||
| 190 | 206 | |
| 191 | 207 | public function setBlock(string $name, Block $block) : Block { |
| 192 | 208 | |
| 193 | - if (isset($this->blocks[$name])) $this->blocks[$name] = $block; |
|
| 209 | + if (isset($this->blocks[$name])) { |
|
| 210 | + $this->blocks[$name] = $block; |
|
| 211 | + } |
|
| 194 | 212 | |
| 195 | 213 | return $this; |
| 196 | 214 | } |
@@ -203,7 +221,9 @@ discard block |
||
| 203 | 221 | |
| 204 | 222 | public function setLoop(string $name, array $items) : Block { |
| 205 | 223 | |
| 206 | - if (isset($this->loops[$name])) $this->loops[$name]->setItems($items); |
|
| 224 | + if (isset($this->loops[$name])) { |
|
| 225 | + $this->loops[$name]->setItems($items); |
|
| 226 | + } |
|
| 207 | 227 | |
| 208 | 228 | return $this; |
| 209 | 229 | } |
@@ -216,7 +236,9 @@ discard block |
||
| 216 | 236 | |
| 217 | 237 | public function setVar(string $name, string $value) : Block { |
| 218 | 238 | |
| 219 | - if (isset($this->variables[$name])) $this->variables[$name] = $value; |
|
| 239 | + if (isset($this->variables[$name])) { |
|
| 240 | + $this->variables[$name] = $value; |
|
| 241 | + } |
|
| 220 | 242 | |
| 221 | 243 | return $this; |
| 222 | 244 | } |
@@ -298,7 +320,9 @@ discard block |
||
| 298 | 320 | |
| 299 | 321 | public function getContents() : string { |
| 300 | 322 | |
| 301 | - if (!$this->enabled) return ''; |
|
| 323 | + if (!$this->enabled) { |
|
| 324 | + return ''; |
|
| 325 | + } |
|
| 302 | 326 | |
| 303 | 327 | # Lock the block |
| 304 | 328 | |
@@ -134,7 +134,9 @@ discard block |
||
| 134 | 134 | |
| 135 | 135 | public static function sendStatus(int $code) { |
| 136 | 136 | |
| 137 | - if (self::isStatusCode($code)) header(getenv('SERVER_PROTOCOL') . ' ' . self::$status_codes[$code]); |
|
| 137 | + if (self::isStatusCode($code)) { |
|
| 138 | + header(getenv('SERVER_PROTOCOL') . ' ' . self::$status_codes[$code]); |
|
| 139 | + } |
|
| 138 | 140 | } |
| 139 | 141 | |
| 140 | 142 | /** |
@@ -160,7 +162,9 @@ discard block |
||
| 160 | 162 | |
| 161 | 163 | public static function sendCache(int $expires, bool $public = false) { |
| 162 | 164 | |
| 163 | - if (self::$cache_sent) return; |
|
| 165 | + if (self::$cache_sent) { |
|
| 166 | + return; |
|
| 167 | + } |
|
| 164 | 168 | |
| 165 | 169 | header('Expires: ' . gmdate('D, d M Y H:i:s', (REQUEST_TIME + $expires)) . ' GMT'); |
| 166 | 170 | |
@@ -183,7 +187,9 @@ discard block |
||
| 183 | 187 | |
| 184 | 188 | public static function sendNoCache() { |
| 185 | 189 | |
| 186 | - if (self::$cache_sent) return; |
|
| 190 | + if (self::$cache_sent) { |
|
| 191 | + return; |
|
| 192 | + } |
|
| 187 | 193 | |
| 188 | 194 | header('Expires: ' . gmdate('D, d M Y H:i:s', strtotime('-1 day')) . ' GMT'); |
| 189 | 195 | |