@@ -54,17 +54,17 @@ discard block |
||
| 54 | 54 | * @return array with the user languages sorted by priority. |
| 55 | 55 | */ |
| 56 | 56 | |
| 57 | - public static function detectLanguages($key='lang') : array |
|
| 57 | + public static function detectLanguages($key = 'lang') : array |
|
| 58 | 58 | { |
| 59 | 59 | $ret = []; |
| 60 | - foreach(['$_GET' => 1000, '$_SESSION' => 100, '$_COOKIE' => 10] as $source => $quality){ |
|
| 60 | + foreach (['$_GET' => 1000, '$_SESSION' => 100, '$_COOKIE' => 10] as $source => $quality) { |
|
| 61 | 61 | $lang = $$source[$key] ?? null; |
| 62 | - if(!empty($lang) && preg_match('/^[a-zA-Z0-9_-]*$/', $lang) === 1){ |
|
| 62 | + if (!empty($lang) && preg_match('/^[a-zA-Z0-9_-]*$/', $lang) === 1) { |
|
| 63 | 63 | $ret[$quality] = $lang; |
| 64 | 64 | } |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | - if(empty($ret)) |
|
| 67 | + if (empty($ret)) |
|
| 68 | 68 | $ret = self::parseHTTPHeader(); |
| 69 | 69 | |
| 70 | 70 | $ret = array_unique($ret); |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | |
| 95 | 95 | list($year, $month, $day) = explode('-', $date_string); |
| 96 | 96 | |
| 97 | - $ret = intval($day) . ' ' . $this->l("DATETIME_CALENDAR_MONTH_$month"); |
|
| 97 | + $ret = intval($day).' '.$this->l("DATETIME_CALENDAR_MONTH_$month"); |
|
| 98 | 98 | |
| 99 | 99 | if ($short === true && Dato::format(null, 'Y') === $year) { |
| 100 | 100 | return $ret; |
@@ -105,18 +105,18 @@ discard block |
||
| 105 | 105 | |
| 106 | 106 | public function month($date_string) |
| 107 | 107 | { |
| 108 | - return $this->l('DATETIME_CALENDAR_MONTH_' . Dato::format($date_string, 'm')); |
|
| 108 | + return $this->l('DATETIME_CALENDAR_MONTH_'.Dato::format($date_string, 'm')); |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | public function day($date_string) |
| 112 | 112 | { |
| 113 | - return $this->l('DATETIME_CALENDAR_DAY_' . Dato::format($date_string, 'N')); |
|
| 113 | + return $this->l('DATETIME_CALENDAR_DAY_'.Dato::format($date_string, 'N')); |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | public function seconds($seconds) |
| 117 | 117 | { |
| 118 | 118 | $hours = floor($seconds / 3600); |
| 119 | - $mins = floor(($seconds - $hours * 3600) / 60); |
|
| 119 | + $mins = floor(($seconds-$hours * 3600) / 60); |
|
| 120 | 120 | $secs = floor($seconds % 60); |
| 121 | 121 | |
| 122 | 122 | $hours_format = '%dh %dm %ds'; |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | |
| 126 | 126 | public function init() { |
| 127 | 127 | if ($this->isInitialized()) { |
| 128 | - throw new \BadMethodCallException('This object from class ' . __CLASS__ . ' is already initialized. It is not possible to init one object twice!'); |
|
| 128 | + throw new \BadMethodCallException('This object from class '.__CLASS__.' is already initialized. It is not possible to init one object twice!'); |
|
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | $this->isInitialized = true; |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | // search for cache file |
| 149 | - $this->cacheFilePath = $this->cachePath . '/php_i18n_' . md5_file(__FILE__) . '_' . $this->prefix . '_' . $this->appliedLang . '.cache.php'; |
|
| 149 | + $this->cacheFilePath = $this->cachePath.'/php_i18n_'.md5_file(__FILE__).'_'.$this->prefix.'_'.$this->appliedLang.'.cache.php'; |
|
| 150 | 150 | |
| 151 | 151 | // whether we need to create a new cache file |
| 152 | 152 | $outdated = !file_exists($this->cacheFilePath) || |
@@ -158,24 +158,24 @@ discard block |
||
| 158 | 158 | if ($this->mergeFallback) |
| 159 | 159 | $config = array_replace_recursive($this->load($this->getConfigFilename($this->fallbackLang)), $config); |
| 160 | 160 | |
| 161 | - $compiled = "<?php class " . $this->prefix . " {\n" |
|
| 161 | + $compiled = "<?php class ".$this->prefix." {\n" |
|
| 162 | 162 | . $this->compile($config) |
| 163 | - . 'public static function __callStatic($string, $args) {' . "\n" |
|
| 163 | + . 'public static function __callStatic($string, $args) {'."\n" |
|
| 164 | 164 | . ' return vsprintf(constant("self::" . $string), $args);' |
| 165 | 165 | . "\n}\n}\n" |
| 166 | 166 | . $this->compileFunction(); |
| 167 | 167 | |
| 168 | - if( ! is_dir($this->cachePath)) |
|
| 168 | + if (!is_dir($this->cachePath)) |
|
| 169 | 169 | mkdir($this->cachePath, 0755, true); |
| 170 | 170 | |
| 171 | 171 | if (file_put_contents($this->cacheFilePath, $compiled) === FALSE) { |
| 172 | - throw new \Exception("Could not write cache file to path '" . $this->cacheFilePath . "'. Is it writable?"); |
|
| 172 | + throw new \Exception("Could not write cache file to path '".$this->cacheFilePath."'. Is it writable?"); |
|
| 173 | 173 | } |
| 174 | - try{ |
|
| 174 | + try { |
|
| 175 | 175 | chmod($this->cacheFilePath, 0755); |
| 176 | 176 | } |
| 177 | - catch(\Throwable $t){ |
|
| 178 | - throw new \Exception("Could chmod cache file '" . $this->cacheFilePath . "'"); |
|
| 177 | + catch (\Throwable $t) { |
|
| 178 | + throw new \Exception("Could chmod cache file '".$this->cacheFilePath."'"); |
|
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | |
@@ -187,17 +187,17 @@ discard block |
||
| 187 | 187 | public function compileFunction() |
| 188 | 188 | { |
| 189 | 189 | return '' |
| 190 | - . "function " . $this->prefix . '($string, $args=NULL) {' . "\n" |
|
| 191 | - . ' if (!defined("' . $this->prefix . '::".$string))' |
|
| 190 | + . "function ".$this->prefix.'($string, $args=NULL) {'."\n" |
|
| 191 | + . ' if (!defined("'.$this->prefix.'::".$string))' |
|
| 192 | 192 | . ' return $string;' |
| 193 | - . ' $return = constant("' . $this->prefix . '::".$string);' . "\n" |
|
| 193 | + . ' $return = constant("'.$this->prefix.'::".$string);'."\n" |
|
| 194 | 194 | . ' return $args ? vsprintf($return,$args) : $return;' |
| 195 | 195 | . "\n}"; |
| 196 | 196 | } |
| 197 | 197 | |
| 198 | 198 | public function l($message, $context = []): string |
| 199 | 199 | { |
| 200 | - foreach($context as $i => $context_message) |
|
| 200 | + foreach ($context as $i => $context_message) |
|
| 201 | 201 | $context[$i] = $this->l($context_message); |
| 202 | 202 | |
| 203 | 203 | return call_user_func($this->prefix, $message, $context); |
@@ -64,8 +64,9 @@ discard block |
||
| 64 | 64 | } |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | - if(empty($ret)) |
|
| 68 | - $ret = self::parseHTTPHeader(); |
|
| 67 | + if(empty($ret)) { |
|
| 68 | + $ret = self::parseHTTPHeader(); |
|
| 69 | + } |
|
| 69 | 70 | |
| 70 | 71 | $ret = array_unique($ret); |
| 71 | 72 | // Sort the detected languages by quality, with the highest quality first |
@@ -155,8 +156,9 @@ discard block |
||
| 155 | 156 | |
| 156 | 157 | if ($outdated) { |
| 157 | 158 | $config = $this->load($this->langFilePath); |
| 158 | - if ($this->mergeFallback) |
|
| 159 | - $config = array_replace_recursive($this->load($this->getConfigFilename($this->fallbackLang)), $config); |
|
| 159 | + if ($this->mergeFallback) { |
|
| 160 | + $config = array_replace_recursive($this->load($this->getConfigFilename($this->fallbackLang)), $config); |
|
| 161 | + } |
|
| 160 | 162 | |
| 161 | 163 | $compiled = "<?php class " . $this->prefix . " {\n" |
| 162 | 164 | . $this->compile($config) |
@@ -165,16 +167,16 @@ discard block |
||
| 165 | 167 | . "\n}\n}\n" |
| 166 | 168 | . $this->compileFunction(); |
| 167 | 169 | |
| 168 | - if( ! is_dir($this->cachePath)) |
|
| 169 | - mkdir($this->cachePath, 0755, true); |
|
| 170 | + if( ! is_dir($this->cachePath)) { |
|
| 171 | + mkdir($this->cachePath, 0755, true); |
|
| 172 | + } |
|
| 170 | 173 | |
| 171 | 174 | if (file_put_contents($this->cacheFilePath, $compiled) === FALSE) { |
| 172 | 175 | throw new \Exception("Could not write cache file to path '" . $this->cacheFilePath . "'. Is it writable?"); |
| 173 | 176 | } |
| 174 | 177 | try{ |
| 175 | 178 | chmod($this->cacheFilePath, 0755); |
| 176 | - } |
|
| 177 | - catch(\Throwable $t){ |
|
| 179 | + } catch(\Throwable $t){ |
|
| 178 | 180 | throw new \Exception("Could chmod cache file '" . $this->cacheFilePath . "'"); |
| 179 | 181 | } |
| 180 | 182 | |
@@ -197,8 +199,9 @@ discard block |
||
| 197 | 199 | |
| 198 | 200 | public function l($message, $context = []): string |
| 199 | 201 | { |
| 200 | - foreach($context as $i => $context_message) |
|
| 201 | - $context[$i] = $this->l($context_message); |
|
| 202 | + foreach($context as $i => $context_message) { |
|
| 203 | + $context[$i] = $this->l($context_message); |
|
| 204 | + } |
|
| 202 | 205 | |
| 203 | 206 | return call_user_func($this->prefix, $message, $context); |
| 204 | 207 | } |