@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | /** |
22 | 22 | * Include the CultureInfo class. |
23 | 23 | */ |
24 | -require_once(dirname(__FILE__) . '/CultureInfo.php'); |
|
24 | +require_once(dirname(__FILE__).'/CultureInfo.php'); |
|
25 | 25 | |
26 | 26 | /** |
27 | 27 | * HTTPNegotiator class. |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | */ |
52 | 52 | public function getLanguages() |
53 | 53 | { |
54 | - if($this->languages !== null) { |
|
54 | + if ($this->languages !== null) { |
|
55 | 55 | return $this->languages; |
56 | 56 | } |
57 | 57 | |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | //$ext = CultureInfo::fileExt(); |
65 | 65 | $info = new CultureInfo(); |
66 | 66 | |
67 | - foreach(explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']) as $lang) |
|
67 | + foreach (explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']) as $lang) |
|
68 | 68 | { |
69 | 69 | // Cut off any q-value that might come after a semi-colon |
70 | 70 | if ($pos = strpos($lang, ';')) |
@@ -73,29 +73,29 @@ discard block |
||
73 | 73 | if (strstr($lang, '-')) |
74 | 74 | { |
75 | 75 | $codes = explode('-', $lang); |
76 | - if($codes[0] == 'i') |
|
76 | + if ($codes[0] == 'i') |
|
77 | 77 | { |
78 | 78 | // Language not listed in ISO 639 that are not variants |
79 | 79 | // of any listed language, which can be registerd with the |
80 | 80 | // i-prefix, such as i-cherokee |
81 | - if(count($codes) > 1) |
|
81 | + if (count($codes) > 1) |
|
82 | 82 | $lang = $codes[1]; |
83 | 83 | } |
84 | 84 | else |
85 | 85 | { |
86 | - for($i = 0, $k = count($codes); $i < $k; ++$i) |
|
86 | + for ($i = 0, $k = count($codes); $i < $k; ++$i) |
|
87 | 87 | { |
88 | - if($i == 0) |
|
88 | + if ($i == 0) |
|
89 | 89 | $lang = strtolower($codes[0]); |
90 | 90 | else |
91 | - $lang .= '_' . strtoupper($codes[$i]); |
|
91 | + $lang .= '_'.strtoupper($codes[$i]); |
|
92 | 92 | } |
93 | 93 | } |
94 | 94 | } |
95 | 95 | |
96 | 96 | |
97 | 97 | |
98 | - if($info->validCulture($lang)) |
|
98 | + if ($info->validCulture($lang)) |
|
99 | 99 | $this->languages[] = $lang; |
100 | 100 | } |
101 | 101 | |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | */ |
109 | 109 | public function getCharsets() |
110 | 110 | { |
111 | - if($this->charsets !== null) { |
|
111 | + if ($this->charsets !== null) { |
|
112 | 112 | return $this->charsets; |
113 | 113 | } |
114 | 114 |
@@ -57,8 +57,9 @@ discard block |
||
57 | 57 | |
58 | 58 | $this->languages = []; |
59 | 59 | |
60 | - if (!isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) |
|
61 | - return $this->languages; |
|
60 | + if (!isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { |
|
61 | + return $this->languages; |
|
62 | + } |
|
62 | 63 | |
63 | 64 | //$basedir = CultureInfo::dataDir(); |
64 | 65 | //$ext = CultureInfo::fileExt(); |
@@ -67,8 +68,9 @@ discard block |
||
67 | 68 | foreach(explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']) as $lang) |
68 | 69 | { |
69 | 70 | // Cut off any q-value that might come after a semi-colon |
70 | - if ($pos = strpos($lang, ';')) |
|
71 | - $lang = trim(substr($lang, 0, $pos)); |
|
71 | + if ($pos = strpos($lang, ';')) { |
|
72 | + $lang = trim(substr($lang, 0, $pos)); |
|
73 | + } |
|
72 | 74 | |
73 | 75 | if (strstr($lang, '-')) |
74 | 76 | { |
@@ -78,25 +80,27 @@ discard block |
||
78 | 80 | // Language not listed in ISO 639 that are not variants |
79 | 81 | // of any listed language, which can be registerd with the |
80 | 82 | // i-prefix, such as i-cherokee |
81 | - if(count($codes) > 1) |
|
82 | - $lang = $codes[1]; |
|
83 | - } |
|
84 | - else |
|
83 | + if(count($codes) > 1) { |
|
84 | + $lang = $codes[1]; |
|
85 | + } |
|
86 | + } else |
|
85 | 87 | { |
86 | 88 | for($i = 0, $k = count($codes); $i < $k; ++$i) |
87 | 89 | { |
88 | - if($i == 0) |
|
89 | - $lang = strtolower($codes[0]); |
|
90 | - else |
|
91 | - $lang .= '_' . strtoupper($codes[$i]); |
|
90 | + if($i == 0) { |
|
91 | + $lang = strtolower($codes[0]); |
|
92 | + } else { |
|
93 | + $lang .= '_' . strtoupper($codes[$i]); |
|
94 | + } |
|
92 | 95 | } |
93 | 96 | } |
94 | 97 | } |
95 | 98 | |
96 | 99 | |
97 | 100 | |
98 | - if($info->validCulture($lang)) |
|
99 | - $this->languages[] = $lang; |
|
101 | + if($info->validCulture($lang)) { |
|
102 | + $this->languages[] = $lang; |
|
103 | + } |
|
100 | 104 | } |
101 | 105 | |
102 | 106 | return $this->languages; |
@@ -114,13 +118,15 @@ discard block |
||
114 | 118 | |
115 | 119 | $this->charsets = []; |
116 | 120 | |
117 | - if (!isset($_SERVER['HTTP_ACCEPT_CHARSET'])) |
|
118 | - return $this->charsets; |
|
121 | + if (!isset($_SERVER['HTTP_ACCEPT_CHARSET'])) { |
|
122 | + return $this->charsets; |
|
123 | + } |
|
119 | 124 | |
120 | 125 | foreach (explode(',', $_SERVER['HTTP_ACCEPT_CHARSET']) as $charset) |
121 | 126 | { |
122 | - if (!empty($charset)) |
|
123 | - $this->charsets[] = preg_replace('/;.*/', '', $charset); |
|
127 | + if (!empty($charset)) { |
|
128 | + $this->charsets[] = preg_replace('/;.*/', '', $charset); |
|
129 | + } |
|
124 | 130 | } |
125 | 131 | |
126 | 132 | return $this->charsets; |
@@ -117,9 +117,9 @@ discard block |
||
117 | 117 | { |
118 | 118 | $n = preg_match_all($this->validate, $set, $matches, PREG_SET_ORDER); |
119 | 119 | |
120 | - if($n < 3) throw new Exception("Invalid set \"{$set}\""); |
|
120 | + if ($n < 3) throw new Exception("Invalid set \"{$set}\""); |
|
121 | 121 | |
122 | - if(preg_match('/\{\s*n:([^\}]+)\}/', $set, $def)) |
|
122 | + if (preg_match('/\{\s*n:([^\}]+)\}/', $set, $def)) |
|
123 | 123 | { |
124 | 124 | return $this->isValidSetNotation($number, $def[1]); |
125 | 125 | } |
@@ -129,12 +129,12 @@ discard block |
||
129 | 129 | |
130 | 130 | $i = 0; |
131 | 131 | $elements = []; |
132 | - foreach($matches as $match) |
|
132 | + foreach ($matches as $match) |
|
133 | 133 | { |
134 | 134 | $string = $match[0]; |
135 | - if($i != 0 && $i != $n - 1 && $string !== ',') |
|
135 | + if ($i != 0 && $i != $n - 1 && $string !== ',') |
|
136 | 136 | { |
137 | - if($string == '-Inf') |
|
137 | + if ($string == '-Inf') |
|
138 | 138 | $elements[] = -1 * $this->inf; |
139 | 139 | elseif ($string == '+Inf' || $string == 'Inf') |
140 | 140 | $elements[] = $this->inf; |
@@ -146,35 +146,35 @@ discard block |
||
146 | 146 | $total = count($elements); |
147 | 147 | $number = floatval($number); |
148 | 148 | |
149 | - if($leftBracket == '{' && $rightBracket == '}') |
|
149 | + if ($leftBracket == '{' && $rightBracket == '}') |
|
150 | 150 | return in_array($number, $elements); |
151 | 151 | |
152 | 152 | $left = false; |
153 | - if($leftBracket == '[') |
|
153 | + if ($leftBracket == '[') |
|
154 | 154 | $left = $number >= $elements[0]; |
155 | 155 | elseif ($leftBracket == '(') |
156 | 156 | $left = $number > $elements[0]; |
157 | 157 | |
158 | 158 | $right = false; |
159 | - if($rightBracket == ']') |
|
159 | + if ($rightBracket == ']') |
|
160 | 160 | $right = $number <= $elements[$total - 1]; |
161 | - elseif($rightBracket == ')') |
|
161 | + elseif ($rightBracket == ')') |
|
162 | 162 | $right = $number < $elements[$total - 1]; |
163 | 163 | |
164 | - if($left && $right) return true; |
|
164 | + if ($left && $right) return true; |
|
165 | 165 | |
166 | 166 | return false; |
167 | 167 | } |
168 | 168 | |
169 | 169 | protected function isValidSetNotation($number, $set) |
170 | 170 | { |
171 | - $str = '$result = ' . str_replace('n', '$number', $set) . ';'; |
|
171 | + $str = '$result = '.str_replace('n', '$number', $set).';'; |
|
172 | 172 | try |
173 | 173 | { |
174 | 174 | eval($str); |
175 | 175 | return $result; |
176 | 176 | } |
177 | - catch(Exception $e) |
|
177 | + catch (Exception $e) |
|
178 | 178 | { |
179 | 179 | return false; |
180 | 180 | } |
@@ -190,14 +190,14 @@ discard block |
||
190 | 190 | { |
191 | 191 | $n = preg_match_all($this->parse, $string, $matches, PREG_OFFSET_CAPTURE); |
192 | 192 | $sets = []; |
193 | - foreach($matches[1] as $match) |
|
193 | + foreach ($matches[1] as $match) |
|
194 | 194 | $sets[] = $match[0]; |
195 | 195 | $offset = $matches[0]; |
196 | 196 | $strings = []; |
197 | - for($i = 0; $i < $n; $i++) |
|
197 | + for ($i = 0; $i < $n; $i++) |
|
198 | 198 | { |
199 | 199 | $len = strlen($offset[$i][0]); |
200 | - $begin = $i == 0? $len : $offset[$i][1] + $len; |
|
200 | + $begin = $i == 0 ? $len : $offset[$i][1] + $len; |
|
201 | 201 | $end = $i == $n - 1 ? strlen($string) : $offset[$i + 1][1]; |
202 | 202 | $strings[] = substr($string, $begin, $end - $begin); |
203 | 203 | } |
@@ -215,9 +215,9 @@ discard block |
||
215 | 215 | { |
216 | 216 | list($sets, $strings) = $this->parse($string); |
217 | 217 | $total = count($sets); |
218 | - for($i = 0; $i < $total; $i++) |
|
218 | + for ($i = 0; $i < $total; $i++) |
|
219 | 219 | { |
220 | - if($this->isValid($number, $sets[$i])) |
|
220 | + if ($this->isValid($number, $sets[$i])) |
|
221 | 221 | return $strings[$i]; |
222 | 222 | } |
223 | 223 | return false; |
@@ -117,7 +117,9 @@ discard block |
||
117 | 117 | { |
118 | 118 | $n = preg_match_all($this->validate, $set, $matches, PREG_SET_ORDER); |
119 | 119 | |
120 | - if($n < 3) throw new Exception("Invalid set \"{$set}\""); |
|
120 | + if($n < 3) { |
|
121 | + throw new Exception("Invalid set \"{$set}\""); |
|
122 | + } |
|
121 | 123 | |
122 | 124 | if(preg_match('/\{\s*n:([^\}]+)\}/', $set, $def)) |
123 | 125 | { |
@@ -134,34 +136,40 @@ discard block |
||
134 | 136 | $string = $match[0]; |
135 | 137 | if($i != 0 && $i != $n - 1 && $string !== ',') |
136 | 138 | { |
137 | - if($string == '-Inf') |
|
138 | - $elements[] = -1 * $this->inf; |
|
139 | - elseif ($string == '+Inf' || $string == 'Inf') |
|
140 | - $elements[] = $this->inf; |
|
141 | - else |
|
142 | - $elements[] = floatval($string); |
|
139 | + if($string == '-Inf') { |
|
140 | + $elements[] = -1 * $this->inf; |
|
141 | + } elseif ($string == '+Inf' || $string == 'Inf') { |
|
142 | + $elements[] = $this->inf; |
|
143 | + } else { |
|
144 | + $elements[] = floatval($string); |
|
145 | + } |
|
143 | 146 | } |
144 | 147 | $i++; |
145 | 148 | } |
146 | 149 | $total = count($elements); |
147 | 150 | $number = floatval($number); |
148 | 151 | |
149 | - if($leftBracket == '{' && $rightBracket == '}') |
|
150 | - return in_array($number, $elements); |
|
152 | + if($leftBracket == '{' && $rightBracket == '}') { |
|
153 | + return in_array($number, $elements); |
|
154 | + } |
|
151 | 155 | |
152 | 156 | $left = false; |
153 | - if($leftBracket == '[') |
|
154 | - $left = $number >= $elements[0]; |
|
155 | - elseif ($leftBracket == '(') |
|
156 | - $left = $number > $elements[0]; |
|
157 | + if($leftBracket == '[') { |
|
158 | + $left = $number >= $elements[0]; |
|
159 | + } elseif ($leftBracket == '(') { |
|
160 | + $left = $number > $elements[0]; |
|
161 | + } |
|
157 | 162 | |
158 | 163 | $right = false; |
159 | - if($rightBracket == ']') |
|
160 | - $right = $number <= $elements[$total - 1]; |
|
161 | - elseif($rightBracket == ')') |
|
162 | - $right = $number < $elements[$total - 1]; |
|
164 | + if($rightBracket == ']') { |
|
165 | + $right = $number <= $elements[$total - 1]; |
|
166 | + } elseif($rightBracket == ')') { |
|
167 | + $right = $number < $elements[$total - 1]; |
|
168 | + } |
|
163 | 169 | |
164 | - if($left && $right) return true; |
|
170 | + if($left && $right) { |
|
171 | + return true; |
|
172 | + } |
|
165 | 173 | |
166 | 174 | return false; |
167 | 175 | } |
@@ -173,8 +181,7 @@ discard block |
||
173 | 181 | { |
174 | 182 | eval($str); |
175 | 183 | return $result; |
176 | - } |
|
177 | - catch(Exception $e) |
|
184 | + } catch(Exception $e) |
|
178 | 185 | { |
179 | 186 | return false; |
180 | 187 | } |
@@ -190,8 +197,9 @@ discard block |
||
190 | 197 | { |
191 | 198 | $n = preg_match_all($this->parse, $string, $matches, PREG_OFFSET_CAPTURE); |
192 | 199 | $sets = []; |
193 | - foreach($matches[1] as $match) |
|
194 | - $sets[] = $match[0]; |
|
200 | + foreach($matches[1] as $match) { |
|
201 | + $sets[] = $match[0]; |
|
202 | + } |
|
195 | 203 | $offset = $matches[0]; |
196 | 204 | $strings = []; |
197 | 205 | for($i = 0; $i < $n; $i++) |
@@ -217,8 +225,9 @@ discard block |
||
217 | 225 | $total = count($sets); |
218 | 226 | for($i = 0; $i < $total; $i++) |
219 | 227 | { |
220 | - if($this->isValid($number, $sets[$i])) |
|
221 | - return $strings[$i]; |
|
228 | + if($this->isValid($number, $sets[$i])) { |
|
229 | + return $strings[$i]; |
|
230 | + } |
|
222 | 231 | } |
223 | 232 | return false; |
224 | 233 | } |
@@ -138,11 +138,11 @@ discard block |
||
138 | 138 | */ |
139 | 139 | public function __get($name) |
140 | 140 | { |
141 | - $getProperty = 'get' . $name; |
|
142 | - if(in_array($getProperty, $this->properties)) |
|
141 | + $getProperty = 'get'.$name; |
|
142 | + if (in_array($getProperty, $this->properties)) |
|
143 | 143 | return $this->$getProperty(); |
144 | 144 | else |
145 | - throw new Exception('Property ' . $name . ' does not exists.'); |
|
145 | + throw new Exception('Property '.$name.' does not exists.'); |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | /** |
@@ -151,11 +151,11 @@ discard block |
||
151 | 151 | */ |
152 | 152 | public function __set($name, $value) |
153 | 153 | { |
154 | - $setProperty = 'set' . $name; |
|
155 | - if(in_array($setProperty, $this->properties)) |
|
154 | + $setProperty = 'set'.$name; |
|
155 | + if (in_array($setProperty, $this->properties)) |
|
156 | 156 | $this->$setProperty($value); |
157 | 157 | else |
158 | - throw new Exception('Property ' . $name . ' can not be set.'); |
|
158 | + throw new Exception('Property '.$name.' can not be set.'); |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | { |
172 | 172 | $this->properties = get_class_methods($this); |
173 | 173 | |
174 | - if(empty($culture)) |
|
174 | + if (empty($culture)) |
|
175 | 175 | $culture = 'en'; |
176 | 176 | |
177 | 177 | $this->dataDir = $this->dataDir(); |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | */ |
191 | 191 | protected static function dataDir() |
192 | 192 | { |
193 | - return dirname(__FILE__) . '/data/'; |
|
193 | + return dirname(__FILE__).'/data/'; |
|
194 | 194 | } |
195 | 195 | |
196 | 196 | /** |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | public static function getInstance($culture) |
210 | 210 | { |
211 | 211 | static $instances = []; |
212 | - if(!isset($instances[$culture])) |
|
212 | + if (!isset($instances[$culture])) |
|
213 | 213 | $instances[$culture] = new CultureInfo($culture); |
214 | 214 | return $instances[$culture]; |
215 | 215 | } |
@@ -222,8 +222,8 @@ discard block |
||
222 | 222 | */ |
223 | 223 | public static function validCulture($culture) |
224 | 224 | { |
225 | - if(preg_match('/^[_\\w]+$/', $culture)) |
|
226 | - return is_file(self::dataDir() . $culture . self::fileExt()); |
|
225 | + if (preg_match('/^[_\\w]+$/', $culture)) |
|
226 | + return is_file(self::dataDir().$culture.self::fileExt()); |
|
227 | 227 | |
228 | 228 | return false; |
229 | 229 | } |
@@ -235,10 +235,10 @@ discard block |
||
235 | 235 | */ |
236 | 236 | protected function setCulture($culture) |
237 | 237 | { |
238 | - if(!empty($culture)) |
|
238 | + if (!empty($culture)) |
|
239 | 239 | { |
240 | 240 | if (!preg_match('/^[_\\w]+$/', $culture)) |
241 | - throw new Exception('Invalid culture supplied: ' . $culture); |
|
241 | + throw new Exception('Invalid culture supplied: '.$culture); |
|
242 | 242 | } |
243 | 243 | |
244 | 244 | $this->culture = $culture; |
@@ -255,27 +255,27 @@ discard block |
||
255 | 255 | |
256 | 256 | $files = [$current_part]; |
257 | 257 | |
258 | - for($i = 1, $k = count($file_parts); $i < $k; ++$i) |
|
258 | + for ($i = 1, $k = count($file_parts); $i < $k; ++$i) |
|
259 | 259 | { |
260 | - $current_part .= '_' . $file_parts[$i]; |
|
260 | + $current_part .= '_'.$file_parts[$i]; |
|
261 | 261 | $files[] = $current_part; |
262 | 262 | } |
263 | 263 | |
264 | - foreach($files as $file) |
|
264 | + foreach ($files as $file) |
|
265 | 265 | { |
266 | - $filename = $this->dataDir . $file . $this->dataFileExt; |
|
266 | + $filename = $this->dataDir.$file.$this->dataFileExt; |
|
267 | 267 | |
268 | - if(is_file($filename) == false) |
|
269 | - throw new Exception('Data file for "' . $file . '" was not found.'); |
|
268 | + if (is_file($filename) == false) |
|
269 | + throw new Exception('Data file for "'.$file.'" was not found.'); |
|
270 | 270 | |
271 | - if(in_array($filename, $this->dataFiles) === false) |
|
271 | + if (in_array($filename, $this->dataFiles) === false) |
|
272 | 272 | { |
273 | 273 | array_unshift($this->dataFiles, $file); |
274 | 274 | |
275 | 275 | $data = &$this->getData($filename); |
276 | 276 | $this->data[$file] = &$data; |
277 | 277 | |
278 | - if(isset($data['__ALIAS'])) |
|
278 | + if (isset($data['__ALIAS'])) |
|
279 | 279 | $this->loadCultureData($data['__ALIAS'][0]); |
280 | 280 | unset($data); |
281 | 281 | } |
@@ -294,7 +294,7 @@ discard block |
||
294 | 294 | static $data = []; |
295 | 295 | static $files = []; |
296 | 296 | |
297 | - if(!in_array($filename, $files)) |
|
297 | + if (!in_array($filename, $files)) |
|
298 | 298 | { |
299 | 299 | $data[$filename] = unserialize(file_get_contents($filename)); |
300 | 300 | $files[] = $filename; |
@@ -320,13 +320,13 @@ discard block |
||
320 | 320 | protected function findInfo($path = '/', $merge = false) |
321 | 321 | { |
322 | 322 | $result = []; |
323 | - foreach($this->dataFiles as $section) |
|
323 | + foreach ($this->dataFiles as $section) |
|
324 | 324 | { |
325 | 325 | $info = $this->searchArray($this->data[$section], $path); |
326 | 326 | |
327 | - if($info) |
|
327 | + if ($info) |
|
328 | 328 | { |
329 | - if($merge) |
|
329 | + if ($merge) |
|
330 | 330 | $result = array_merge($info, $result); |
331 | 331 | else |
332 | 332 | return $info; |
@@ -350,10 +350,10 @@ discard block |
||
350 | 350 | |
351 | 351 | $array = $info; |
352 | 352 | |
353 | - for($i = 0, $k = count($index); $i < $k; ++$i) |
|
353 | + for ($i = 0, $k = count($index); $i < $k; ++$i) |
|
354 | 354 | { |
355 | 355 | $value = $index[$i]; |
356 | - if($i < $k - 1 && isset($array[$value])) |
|
356 | + if ($i < $k - 1 && isset($array[$value])) |
|
357 | 357 | $array = $array[$value]; |
358 | 358 | elseif ($i == $k - 1 && isset($array[$value])) |
359 | 359 | return $array[$value]; |
@@ -377,7 +377,7 @@ discard block |
||
377 | 377 | */ |
378 | 378 | public function getDateTimeFormat() |
379 | 379 | { |
380 | - if($this->dateTimeFormat === null) |
|
380 | + if ($this->dateTimeFormat === null) |
|
381 | 381 | { |
382 | 382 | $calendar = $this->getCalendar(); |
383 | 383 | $info = $this->findInfo("calendar/{$calendar}", true); |
@@ -418,8 +418,8 @@ discard block |
||
418 | 418 | $reg = substr($this->culture, 3, 2); |
419 | 419 | $language = $this->findInfo("Languages/{$lang}"); |
420 | 420 | $region = $this->findInfo("Countries/{$reg}"); |
421 | - if($region) |
|
422 | - return $language[0] . ' (' . $region[0] . ')'; |
|
421 | + if ($region) |
|
422 | + return $language[0].' ('.$region[0].')'; |
|
423 | 423 | else |
424 | 424 | return $language[0]; |
425 | 425 | } |
@@ -437,12 +437,12 @@ discard block |
||
437 | 437 | $culture = $this->getInvariantCulture(); |
438 | 438 | |
439 | 439 | $language = $culture->findInfo("Languages/{$lang}"); |
440 | - if(count($language) == 0) |
|
440 | + if (count($language) == 0) |
|
441 | 441 | return $this->culture; |
442 | 442 | |
443 | 443 | $region = $culture->findInfo("Countries/{$reg}"); |
444 | - if($region) |
|
445 | - return $language[0] . ' (' . $region[0] . ')'; |
|
444 | + if ($region) |
|
445 | + return $language[0].' ('.$region[0].')'; |
|
446 | 446 | else |
447 | 447 | return $language[0]; |
448 | 448 | } |
@@ -457,7 +457,7 @@ discard block |
||
457 | 457 | public static function getInvariantCulture() |
458 | 458 | { |
459 | 459 | static $invariant; |
460 | - if($invariant === null) |
|
460 | + if ($invariant === null) |
|
461 | 461 | $invariant = new CultureInfo(); |
462 | 462 | return $invariant; |
463 | 463 | } |
@@ -480,12 +480,12 @@ discard block |
||
480 | 480 | */ |
481 | 481 | public function getNumberFormat() |
482 | 482 | { |
483 | - if($this->numberFormat === null) |
|
483 | + if ($this->numberFormat === null) |
|
484 | 484 | { |
485 | 485 | $elements = $this->findInfo('NumberElements'); |
486 | 486 | $patterns = $this->findInfo('NumberPatterns'); |
487 | 487 | $currencies = $this->getCurrencies(); |
488 | - $data = [ 'NumberElements' => $elements, |
|
488 | + $data = ['NumberElements' => $elements, |
|
489 | 489 | 'NumberPatterns' => $patterns, |
490 | 490 | 'Currencies' => $currencies]; |
491 | 491 | |
@@ -510,7 +510,7 @@ discard block |
||
510 | 510 | */ |
511 | 511 | public function getParent() |
512 | 512 | { |
513 | - if(strlen($this->culture) == 2) |
|
513 | + if (strlen($this->culture) == 2) |
|
514 | 514 | return $this->getInvariantCulture(); |
515 | 515 | |
516 | 516 | $lang = substr($this->culture, 0, 2); |
@@ -537,12 +537,12 @@ discard block |
||
537 | 537 | |
538 | 538 | while (false !== ($entry = $dir->read())) |
539 | 539 | { |
540 | - if(is_file($dataDir . $entry) |
|
540 | + if (is_file($dataDir.$entry) |
|
541 | 541 | && substr($entry, -4) == $dataExt |
542 | - && $entry != 'root' . $dataExt) |
|
542 | + && $entry != 'root'.$dataExt) |
|
543 | 543 | { |
544 | 544 | $culture = substr($entry, 0, -4); |
545 | - if(strlen($culture) == 2) |
|
545 | + if (strlen($culture) == 2) |
|
546 | 546 | $neutral[] = $culture; |
547 | 547 | else |
548 | 548 | $specific[] = $culture; |
@@ -550,7 +550,7 @@ discard block |
||
550 | 550 | } |
551 | 551 | $dir->close(); |
552 | 552 | |
553 | - switch($type) |
|
553 | + switch ($type) |
|
554 | 554 | { |
555 | 555 | case CultureInfo::ALL : |
556 | 556 | $all = array_merge($neutral, $specific); |
@@ -575,10 +575,10 @@ discard block |
||
575 | 575 | */ |
576 | 576 | private function simplify($array) |
577 | 577 | { |
578 | - for($i = 0, $k = count($array); $i < $k; ++$i) |
|
578 | + for ($i = 0, $k = count($array); $i < $k; ++$i) |
|
579 | 579 | { |
580 | 580 | $key = key($array); |
581 | - if(is_array($array[$key]) |
|
581 | + if (is_array($array[$key]) |
|
582 | 582 | && count($array[$key]) == 1) |
583 | 583 | $array[$key] = $array[$key][0]; |
584 | 584 | next($array); |
@@ -139,10 +139,11 @@ discard block |
||
139 | 139 | public function __get($name) |
140 | 140 | { |
141 | 141 | $getProperty = 'get' . $name; |
142 | - if(in_array($getProperty, $this->properties)) |
|
143 | - return $this->$getProperty(); |
|
144 | - else |
|
145 | - throw new Exception('Property ' . $name . ' does not exists.'); |
|
142 | + if(in_array($getProperty, $this->properties)) { |
|
143 | + return $this->$getProperty(); |
|
144 | + } else { |
|
145 | + throw new Exception('Property ' . $name . ' does not exists.'); |
|
146 | + } |
|
146 | 147 | } |
147 | 148 | |
148 | 149 | /** |
@@ -152,10 +153,11 @@ discard block |
||
152 | 153 | public function __set($name, $value) |
153 | 154 | { |
154 | 155 | $setProperty = 'set' . $name; |
155 | - if(in_array($setProperty, $this->properties)) |
|
156 | - $this->$setProperty($value); |
|
157 | - else |
|
158 | - throw new Exception('Property ' . $name . ' can not be set.'); |
|
156 | + if(in_array($setProperty, $this->properties)) { |
|
157 | + $this->$setProperty($value); |
|
158 | + } else { |
|
159 | + throw new Exception('Property ' . $name . ' can not be set.'); |
|
160 | + } |
|
159 | 161 | } |
160 | 162 | |
161 | 163 | |
@@ -171,8 +173,9 @@ discard block |
||
171 | 173 | { |
172 | 174 | $this->properties = get_class_methods($this); |
173 | 175 | |
174 | - if(empty($culture)) |
|
175 | - $culture = 'en'; |
|
176 | + if(empty($culture)) { |
|
177 | + $culture = 'en'; |
|
178 | + } |
|
176 | 179 | |
177 | 180 | $this->dataDir = $this->dataDir(); |
178 | 181 | $this->dataFileExt = $this->fileExt(); |
@@ -209,8 +212,9 @@ discard block |
||
209 | 212 | public static function getInstance($culture) |
210 | 213 | { |
211 | 214 | static $instances = []; |
212 | - if(!isset($instances[$culture])) |
|
213 | - $instances[$culture] = new CultureInfo($culture); |
|
215 | + if(!isset($instances[$culture])) { |
|
216 | + $instances[$culture] = new CultureInfo($culture); |
|
217 | + } |
|
214 | 218 | return $instances[$culture]; |
215 | 219 | } |
216 | 220 | |
@@ -222,8 +226,9 @@ discard block |
||
222 | 226 | */ |
223 | 227 | public static function validCulture($culture) |
224 | 228 | { |
225 | - if(preg_match('/^[_\\w]+$/', $culture)) |
|
226 | - return is_file(self::dataDir() . $culture . self::fileExt()); |
|
229 | + if(preg_match('/^[_\\w]+$/', $culture)) { |
|
230 | + return is_file(self::dataDir() . $culture . self::fileExt()); |
|
231 | + } |
|
227 | 232 | |
228 | 233 | return false; |
229 | 234 | } |
@@ -237,8 +242,9 @@ discard block |
||
237 | 242 | { |
238 | 243 | if(!empty($culture)) |
239 | 244 | { |
240 | - if (!preg_match('/^[_\\w]+$/', $culture)) |
|
241 | - throw new Exception('Invalid culture supplied: ' . $culture); |
|
245 | + if (!preg_match('/^[_\\w]+$/', $culture)) { |
|
246 | + throw new Exception('Invalid culture supplied: ' . $culture); |
|
247 | + } |
|
242 | 248 | } |
243 | 249 | |
244 | 250 | $this->culture = $culture; |
@@ -265,8 +271,9 @@ discard block |
||
265 | 271 | { |
266 | 272 | $filename = $this->dataDir . $file . $this->dataFileExt; |
267 | 273 | |
268 | - if(is_file($filename) == false) |
|
269 | - throw new Exception('Data file for "' . $file . '" was not found.'); |
|
274 | + if(is_file($filename) == false) { |
|
275 | + throw new Exception('Data file for "' . $file . '" was not found.'); |
|
276 | + } |
|
270 | 277 | |
271 | 278 | if(in_array($filename, $this->dataFiles) === false) |
272 | 279 | { |
@@ -275,8 +282,9 @@ discard block |
||
275 | 282 | $data = &$this->getData($filename); |
276 | 283 | $this->data[$file] = &$data; |
277 | 284 | |
278 | - if(isset($data['__ALIAS'])) |
|
279 | - $this->loadCultureData($data['__ALIAS'][0]); |
|
285 | + if(isset($data['__ALIAS'])) { |
|
286 | + $this->loadCultureData($data['__ALIAS'][0]); |
|
287 | + } |
|
280 | 288 | unset($data); |
281 | 289 | } |
282 | 290 | } |
@@ -326,10 +334,11 @@ discard block |
||
326 | 334 | |
327 | 335 | if($info) |
328 | 336 | { |
329 | - if($merge) |
|
330 | - $result = array_merge($info, $result); |
|
331 | - else |
|
332 | - return $info; |
|
337 | + if($merge) { |
|
338 | + $result = array_merge($info, $result); |
|
339 | + } else { |
|
340 | + return $info; |
|
341 | + } |
|
333 | 342 | } |
334 | 343 | } |
335 | 344 | |
@@ -353,10 +362,11 @@ discard block |
||
353 | 362 | for($i = 0, $k = count($index); $i < $k; ++$i) |
354 | 363 | { |
355 | 364 | $value = $index[$i]; |
356 | - if($i < $k - 1 && isset($array[$value])) |
|
357 | - $array = $array[$value]; |
|
358 | - elseif ($i == $k - 1 && isset($array[$value])) |
|
359 | - return $array[$value]; |
|
365 | + if($i < $k - 1 && isset($array[$value])) { |
|
366 | + $array = $array[$value]; |
|
367 | + } elseif ($i == $k - 1 && isset($array[$value])) { |
|
368 | + return $array[$value]; |
|
369 | + } |
|
360 | 370 | } |
361 | 371 | } |
362 | 372 | |
@@ -418,10 +428,11 @@ discard block |
||
418 | 428 | $reg = substr($this->culture, 3, 2); |
419 | 429 | $language = $this->findInfo("Languages/{$lang}"); |
420 | 430 | $region = $this->findInfo("Countries/{$reg}"); |
421 | - if($region) |
|
422 | - return $language[0] . ' (' . $region[0] . ')'; |
|
423 | - else |
|
424 | - return $language[0]; |
|
431 | + if($region) { |
|
432 | + return $language[0] . ' (' . $region[0] . ')'; |
|
433 | + } else { |
|
434 | + return $language[0]; |
|
435 | + } |
|
425 | 436 | } |
426 | 437 | |
427 | 438 | /** |
@@ -437,14 +448,16 @@ discard block |
||
437 | 448 | $culture = $this->getInvariantCulture(); |
438 | 449 | |
439 | 450 | $language = $culture->findInfo("Languages/{$lang}"); |
440 | - if(count($language) == 0) |
|
441 | - return $this->culture; |
|
451 | + if(count($language) == 0) { |
|
452 | + return $this->culture; |
|
453 | + } |
|
442 | 454 | |
443 | 455 | $region = $culture->findInfo("Countries/{$reg}"); |
444 | - if($region) |
|
445 | - return $language[0] . ' (' . $region[0] . ')'; |
|
446 | - else |
|
447 | - return $language[0]; |
|
456 | + if($region) { |
|
457 | + return $language[0] . ' (' . $region[0] . ')'; |
|
458 | + } else { |
|
459 | + return $language[0]; |
|
460 | + } |
|
448 | 461 | } |
449 | 462 | |
450 | 463 | /** |
@@ -457,8 +470,9 @@ discard block |
||
457 | 470 | public static function getInvariantCulture() |
458 | 471 | { |
459 | 472 | static $invariant; |
460 | - if($invariant === null) |
|
461 | - $invariant = new CultureInfo(); |
|
473 | + if($invariant === null) { |
|
474 | + $invariant = new CultureInfo(); |
|
475 | + } |
|
462 | 476 | return $invariant; |
463 | 477 | } |
464 | 478 | |
@@ -510,8 +524,9 @@ discard block |
||
510 | 524 | */ |
511 | 525 | public function getParent() |
512 | 526 | { |
513 | - if(strlen($this->culture) == 2) |
|
514 | - return $this->getInvariantCulture(); |
|
527 | + if(strlen($this->culture) == 2) { |
|
528 | + return $this->getInvariantCulture(); |
|
529 | + } |
|
515 | 530 | |
516 | 531 | $lang = substr($this->culture, 0, 2); |
517 | 532 | return new CultureInfo($lang); |
@@ -542,10 +557,11 @@ discard block |
||
542 | 557 | && $entry != 'root' . $dataExt) |
543 | 558 | { |
544 | 559 | $culture = substr($entry, 0, -4); |
545 | - if(strlen($culture) == 2) |
|
546 | - $neutral[] = $culture; |
|
547 | - else |
|
548 | - $specific[] = $culture; |
|
560 | + if(strlen($culture) == 2) { |
|
561 | + $neutral[] = $culture; |
|
562 | + } else { |
|
563 | + $specific[] = $culture; |
|
564 | + } |
|
549 | 565 | } |
550 | 566 | } |
551 | 567 | $dir->close(); |
@@ -579,8 +595,9 @@ discard block |
||
579 | 595 | { |
580 | 596 | $key = key($array); |
581 | 597 | if(is_array($array[$key]) |
582 | - && count($array[$key]) == 1) |
|
583 | - $array[$key] = $array[$key][0]; |
|
598 | + && count($array[$key]) == 1) { |
|
599 | + $array[$key] = $array[$key][0]; |
|
600 | + } |
|
584 | 601 | next($array); |
585 | 602 | } |
586 | 603 | return $array; |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | /** |
22 | 22 | * Get the encoding utilities |
23 | 23 | */ |
24 | -require_once(dirname(__FILE__) . '/util.php'); |
|
24 | +require_once(dirname(__FILE__).'/util.php'); |
|
25 | 25 | |
26 | 26 | /** |
27 | 27 | * MessageFormat class. |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | * The prefix and suffix to append to untranslated messages. |
77 | 77 | * @var array |
78 | 78 | */ |
79 | - protected $postscript = ['','']; |
|
79 | + protected $postscript = ['', '']; |
|
80 | 80 | |
81 | 81 | /** |
82 | 82 | * Set the default catalogue. |
@@ -130,10 +130,10 @@ discard block |
||
130 | 130 | */ |
131 | 131 | protected function loadCatalogue($catalogue) |
132 | 132 | { |
133 | - if(in_array($catalogue, $this->catagloues)) |
|
133 | + if (in_array($catalogue, $this->catagloues)) |
|
134 | 134 | return; |
135 | 135 | |
136 | - if($this->source->load($catalogue)) |
|
136 | + if ($this->source->load($catalogue)) |
|
137 | 137 | { |
138 | 138 | $this->messages[$catalogue] = $this->source->read(); |
139 | 139 | $this->catagloues[] = $catalogue; |
@@ -155,10 +155,10 @@ discard block |
||
155 | 155 | */ |
156 | 156 | public function format($string, $args = [], $catalogue = null, $charset = null) |
157 | 157 | { |
158 | - if(empty($charset)) $charset = $this->getCharset(); |
|
158 | + if (empty($charset)) $charset = $this->getCharset(); |
|
159 | 159 | |
160 | 160 | //force args as UTF-8 |
161 | - foreach($args as $k => $v) |
|
161 | + foreach ($args as $k => $v) |
|
162 | 162 | $args[$k] = I18N_toUTF8($v, $charset); |
163 | 163 | $s = $this->formatString(I18N_toUTF8($string, $charset), $args, $catalogue); |
164 | 164 | return I18N_toEncoding($s, $charset); |
@@ -174,9 +174,9 @@ discard block |
||
174 | 174 | */ |
175 | 175 | protected function formatString($string, $args = [], $catalogue = null) |
176 | 176 | { |
177 | - if(empty($catalogue)) |
|
177 | + if (empty($catalogue)) |
|
178 | 178 | { |
179 | - if(empty($this->Catalogue)) |
|
179 | + if (empty($this->Catalogue)) |
|
180 | 180 | $catalogue = 'messages'; |
181 | 181 | else |
182 | 182 | $catalogue = $this->Catalogue; |
@@ -184,29 +184,29 @@ discard block |
||
184 | 184 | |
185 | 185 | $this->loadCatalogue($catalogue); |
186 | 186 | |
187 | - if(empty($args)) |
|
187 | + if (empty($args)) |
|
188 | 188 | $args = []; |
189 | 189 | |
190 | - foreach($this->messages[$catalogue] as $variant) |
|
190 | + foreach ($this->messages[$catalogue] as $variant) |
|
191 | 191 | { |
192 | 192 | // foreach of the translation units |
193 | - foreach($variant as $source => $result) |
|
193 | + foreach ($variant as $source => $result) |
|
194 | 194 | { |
195 | 195 | // we found it, so return the target translation |
196 | - if($source == $string) |
|
196 | + if ($source == $string) |
|
197 | 197 | { |
198 | 198 | //check if it contains only strings. |
199 | - if(is_string($result)) |
|
199 | + if (is_string($result)) |
|
200 | 200 | $target = $result; |
201 | 201 | else |
202 | 202 | { |
203 | 203 | $target = $result[0]; |
204 | 204 | } |
205 | 205 | //found, but untranslated |
206 | - if(empty($target)) |
|
206 | + if (empty($target)) |
|
207 | 207 | { |
208 | - return $this->postscript[0] . |
|
209 | - strtr($string, $args) . |
|
208 | + return $this->postscript[0]. |
|
209 | + strtr($string, $args). |
|
210 | 210 | $this->postscript[1]; |
211 | 211 | } |
212 | 212 | else |
@@ -218,8 +218,8 @@ discard block |
||
218 | 218 | // well we did not find the translation string. |
219 | 219 | $this->source->append($string); |
220 | 220 | |
221 | - return $this->postscript[0] . |
|
222 | - strtr($string, $args) . |
|
221 | + return $this->postscript[0]. |
|
222 | + strtr($string, $args). |
|
223 | 223 | $this->postscript[1]; |
224 | 224 | } |
225 | 225 | |
@@ -240,7 +240,7 @@ discard block |
||
240 | 240 | */ |
241 | 241 | public function setUntranslatedPS($postscript) |
242 | 242 | { |
243 | - if(is_array($postscript) && count($postscript) >= 2) |
|
243 | + if (is_array($postscript) && count($postscript) >= 2) |
|
244 | 244 | { |
245 | 245 | $this->postscript[0] = $postscript[0]; |
246 | 246 | $this->postscript[1] = $postscript[1]; |
@@ -130,8 +130,9 @@ discard block |
||
130 | 130 | */ |
131 | 131 | protected function loadCatalogue($catalogue) |
132 | 132 | { |
133 | - if(in_array($catalogue, $this->catagloues)) |
|
134 | - return; |
|
133 | + if(in_array($catalogue, $this->catagloues)) { |
|
134 | + return; |
|
135 | + } |
|
135 | 136 | |
136 | 137 | if($this->source->load($catalogue)) |
137 | 138 | { |
@@ -155,11 +156,14 @@ discard block |
||
155 | 156 | */ |
156 | 157 | public function format($string, $args = [], $catalogue = null, $charset = null) |
157 | 158 | { |
158 | - if(empty($charset)) $charset = $this->getCharset(); |
|
159 | + if(empty($charset)) { |
|
160 | + $charset = $this->getCharset(); |
|
161 | + } |
|
159 | 162 | |
160 | 163 | //force args as UTF-8 |
161 | - foreach($args as $k => $v) |
|
162 | - $args[$k] = I18N_toUTF8($v, $charset); |
|
164 | + foreach($args as $k => $v) { |
|
165 | + $args[$k] = I18N_toUTF8($v, $charset); |
|
166 | + } |
|
163 | 167 | $s = $this->formatString(I18N_toUTF8($string, $charset), $args, $catalogue); |
164 | 168 | return I18N_toEncoding($s, $charset); |
165 | 169 | } |
@@ -176,16 +180,18 @@ discard block |
||
176 | 180 | { |
177 | 181 | if(empty($catalogue)) |
178 | 182 | { |
179 | - if(empty($this->Catalogue)) |
|
180 | - $catalogue = 'messages'; |
|
181 | - else |
|
182 | - $catalogue = $this->Catalogue; |
|
183 | + if(empty($this->Catalogue)) { |
|
184 | + $catalogue = 'messages'; |
|
185 | + } else { |
|
186 | + $catalogue = $this->Catalogue; |
|
187 | + } |
|
183 | 188 | } |
184 | 189 | |
185 | 190 | $this->loadCatalogue($catalogue); |
186 | 191 | |
187 | - if(empty($args)) |
|
188 | - $args = []; |
|
192 | + if(empty($args)) { |
|
193 | + $args = []; |
|
194 | + } |
|
189 | 195 | |
190 | 196 | foreach($this->messages[$catalogue] as $variant) |
191 | 197 | { |
@@ -196,9 +202,9 @@ discard block |
||
196 | 202 | if($source == $string) |
197 | 203 | { |
198 | 204 | //check if it contains only strings. |
199 | - if(is_string($result)) |
|
200 | - $target = $result; |
|
201 | - else |
|
205 | + if(is_string($result)) { |
|
206 | + $target = $result; |
|
207 | + } else |
|
202 | 208 | { |
203 | 209 | $target = $result[0]; |
204 | 210 | } |
@@ -208,9 +214,9 @@ discard block |
||
208 | 214 | return $this->postscript[0] . |
209 | 215 | strtr($string, $args) . |
210 | 216 | $this->postscript[1]; |
217 | + } else { |
|
218 | + return strtr($target, $args); |
|
211 | 219 | } |
212 | - else |
|
213 | - return strtr($target, $args); |
|
214 | 220 | } |
215 | 221 | } |
216 | 222 | } |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | /** |
26 | 26 | * Get the Gettext class. |
27 | 27 | */ |
28 | -require_once(dirname(__FILE__) . '/Gettext/TGettext.php'); |
|
28 | +require_once(dirname(__FILE__).'/Gettext/TGettext.php'); |
|
29 | 29 | |
30 | 30 | /** |
31 | 31 | * MessageSource_gettext class. |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | |
61 | 61 | public function __construct($source) |
62 | 62 | { |
63 | - $this->source = (string)$source; |
|
63 | + $this->source = (string) $source; |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | |
78 | 78 | $results = []; |
79 | 79 | $count = 0; |
80 | - foreach($result['strings'] as $source => $target) |
|
80 | + foreach ($result['strings'] as $source => $target) |
|
81 | 81 | { |
82 | 82 | $results[$source][] = $target; //target |
83 | 83 | $results[$source][] = $count++; //id |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | */ |
105 | 105 | protected function getSource($variant) |
106 | 106 | { |
107 | - return $this->source . '/' . $variant; |
|
107 | + return $this->source.'/'.$variant; |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | /** |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | */ |
116 | 116 | protected function getLastModified($source) |
117 | 117 | { |
118 | - if(is_file($source)) |
|
118 | + if (is_file($source)) |
|
119 | 119 | return filemtime($source); |
120 | 120 | else |
121 | 121 | return 0; |
@@ -129,19 +129,19 @@ discard block |
||
129 | 129 | protected function getCatalogueList($catalogue) |
130 | 130 | { |
131 | 131 | $variants = explode('_', $this->culture); |
132 | - $source = $catalogue . $this->dataExt; |
|
132 | + $source = $catalogue.$this->dataExt; |
|
133 | 133 | |
134 | 134 | $catalogues = [$source]; |
135 | 135 | |
136 | 136 | $variant = null; |
137 | 137 | |
138 | - for($i = 0, $k = count($variants); $i < $k; ++$i) |
|
138 | + for ($i = 0, $k = count($variants); $i < $k; ++$i) |
|
139 | 139 | { |
140 | - if(isset($variants[$i]{0})) |
|
140 | + if (isset($variants[$i]{0})) |
|
141 | 141 | { |
142 | - $variant .= ($variant)?'_' . $variants[$i]:$variants[$i]; |
|
143 | - $catalogues[] = $catalogue . $this->dataSeparator . |
|
144 | - $variant . $this->dataExt; |
|
142 | + $variant .= ($variant) ? '_'.$variants[$i] : $variants[$i]; |
|
143 | + $catalogues[] = $catalogue.$this->dataSeparator. |
|
144 | + $variant.$this->dataExt; |
|
145 | 145 | } |
146 | 146 | } |
147 | 147 | $byDir = $this->getCatalogueByDir($catalogue); |
@@ -164,12 +164,12 @@ discard block |
||
164 | 164 | |
165 | 165 | $variant = null; |
166 | 166 | |
167 | - for($i = 0, $k = count($variants); $i < $k; ++$i) |
|
167 | + for ($i = 0, $k = count($variants); $i < $k; ++$i) |
|
168 | 168 | { |
169 | - if(isset($variants[$i]{0})) |
|
169 | + if (isset($variants[$i]{0})) |
|
170 | 170 | { |
171 | - $variant .= ($variant)?'_' . $variants[$i]:$variants[$i]; |
|
172 | - $catalogues[] = $variant . '/' . $catalogue . $this->dataExt; |
|
171 | + $variant .= ($variant) ? '_'.$variants[$i] : $variants[$i]; |
|
172 | + $catalogues[] = $variant.'/'.$catalogue.$this->dataExt; |
|
173 | 173 | } |
174 | 174 | } |
175 | 175 | return array_reverse($catalogues); |
@@ -185,15 +185,15 @@ discard block |
||
185 | 185 | */ |
186 | 186 | private function getVariants($catalogue = 'messages') |
187 | 187 | { |
188 | - if($catalogue === null) { |
|
188 | + if ($catalogue === null) { |
|
189 | 189 | $catalogue = 'messages'; |
190 | 190 | } |
191 | 191 | |
192 | - foreach($this->getCatalogueList($catalogue) as $variant) |
|
192 | + foreach ($this->getCatalogueList($catalogue) as $variant) |
|
193 | 193 | { |
194 | 194 | $file = $this->getSource($variant); |
195 | 195 | $po = $this->getPOFile($file); |
196 | - if(is_file($file) || is_file($po)) |
|
196 | + if (is_file($file) || is_file($po)) |
|
197 | 197 | return [$variant, $file, $po]; |
198 | 198 | } |
199 | 199 | return false; |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | private function getPOFile($MOFile) |
203 | 203 | { |
204 | 204 | $filebase = substr($MOFile, 0, strlen($MOFile) - strlen($this->dataExt)); |
205 | - return $filebase . $this->poExt; |
|
205 | + return $filebase.$this->poExt; |
|
206 | 206 | } |
207 | 207 | |
208 | 208 | /** |
@@ -216,23 +216,23 @@ discard block |
||
216 | 216 | { |
217 | 217 | $messages = $this->untranslated; |
218 | 218 | |
219 | - if(count($messages) <= 0) return false; |
|
219 | + if (count($messages) <= 0) return false; |
|
220 | 220 | |
221 | 221 | $variants = $this->getVariants($catalogue); |
222 | 222 | |
223 | - if($variants) |
|
223 | + if ($variants) |
|
224 | 224 | list($variant, $MOFile, $POFile) = $variants; |
225 | 225 | else |
226 | 226 | list($variant, $MOFile, $POFile) = $this->createMessageTemplate($catalogue); |
227 | 227 | |
228 | - if(is_writable($MOFile) == false) |
|
228 | + if (is_writable($MOFile) == false) |
|
229 | 229 | throw new TIOException("Unable to save to file {$MOFile}, file must be writable."); |
230 | - if(is_writable($POFile) == false) |
|
230 | + if (is_writable($POFile) == false) |
|
231 | 231 | throw new TIOException("Unable to save to file {$POFile}, file must be writable."); |
232 | 232 | |
233 | 233 | //set the strings as untranslated. |
234 | 234 | $strings = []; |
235 | - foreach($messages as $message) |
|
235 | + foreach ($messages as $message) |
|
236 | 236 | $strings[$message] = ''; |
237 | 237 | |
238 | 238 | //load the PO |
@@ -247,16 +247,16 @@ discard block |
||
247 | 247 | |
248 | 248 | $new = count($result['strings']); |
249 | 249 | |
250 | - if($new > $existing) |
|
250 | + if ($new > $existing) |
|
251 | 251 | { |
252 | 252 | //change the date 2004-12-25 12:26 |
253 | 253 | $result['meta']['PO-Revision-Date'] = @date('Y-m-d H:i:s'); |
254 | 254 | |
255 | 255 | $po->fromArray($result); |
256 | 256 | $mo = $po->toMO(); |
257 | - if($po->save() && $mo->save($MOFile)) |
|
257 | + if ($po->save() && $mo->save($MOFile)) |
|
258 | 258 | { |
259 | - if(!empty($this->cache)) |
|
259 | + if (!empty($this->cache)) |
|
260 | 260 | $this->cache->clean($variant, $this->culture); |
261 | 261 | return true; |
262 | 262 | } |
@@ -275,32 +275,32 @@ discard block |
||
275 | 275 | public function delete($message, $catalogue = 'messages') |
276 | 276 | { |
277 | 277 | $variants = $this->getVariants($catalogue); |
278 | - if($variants) |
|
278 | + if ($variants) |
|
279 | 279 | list($variant, $MOFile, $POFile) = $variants; |
280 | 280 | else |
281 | 281 | return false; |
282 | 282 | |
283 | - if(is_writable($MOFile) == false) |
|
283 | + if (is_writable($MOFile) == false) |
|
284 | 284 | throw new TIOException("Unable to modify file {$MOFile}, file must be writable."); |
285 | - if(is_writable($POFile) == false) |
|
285 | + if (is_writable($POFile) == false) |
|
286 | 286 | throw new TIOException("Unable to modify file {$POFile}, file must be writable."); |
287 | 287 | |
288 | 288 | $po = TGettext::factory('PO', $POFile); |
289 | 289 | $po->load(); |
290 | 290 | $result = $po->toArray(); |
291 | 291 | |
292 | - foreach($result['strings'] as $string => $value) |
|
292 | + foreach ($result['strings'] as $string => $value) |
|
293 | 293 | { |
294 | - if($string == $message) |
|
294 | + if ($string == $message) |
|
295 | 295 | { |
296 | 296 | $result['meta']['PO-Revision-Date'] = @date('Y-m-d H:i:s'); |
297 | 297 | unset($result['strings'][$string]); |
298 | 298 | |
299 | 299 | $po->fromArray($result); |
300 | 300 | $mo = $po->toMO(); |
301 | - if($po->save() && $mo->save($MOFile)) |
|
301 | + if ($po->save() && $mo->save($MOFile)) |
|
302 | 302 | { |
303 | - if(!empty($this->cache)) |
|
303 | + if (!empty($this->cache)) |
|
304 | 304 | $this->cache->clean($variant, $this->culture); |
305 | 305 | return true; |
306 | 306 | } |
@@ -323,14 +323,14 @@ discard block |
||
323 | 323 | public function update($text, $target, $comments, $catalogue = 'messages') |
324 | 324 | { |
325 | 325 | $variants = $this->getVariants($catalogue); |
326 | - if($variants) |
|
326 | + if ($variants) |
|
327 | 327 | list($variant, $MOFile, $POFile) = $variants; |
328 | 328 | else |
329 | 329 | return false; |
330 | 330 | |
331 | - if(is_writable($MOFile) == false) |
|
331 | + if (is_writable($MOFile) == false) |
|
332 | 332 | throw new TIOException("Unable to update file {$MOFile}, file must be writable."); |
333 | - if(is_writable($POFile) == false) |
|
333 | + if (is_writable($POFile) == false) |
|
334 | 334 | throw new TIOException("Unable to update file {$POFile}, file must be writable."); |
335 | 335 | |
336 | 336 | |
@@ -338,9 +338,9 @@ discard block |
||
338 | 338 | $po->load(); |
339 | 339 | $result = $po->toArray(); |
340 | 340 | |
341 | - foreach($result['strings'] as $string => $value) |
|
341 | + foreach ($result['strings'] as $string => $value) |
|
342 | 342 | { |
343 | - if($string == $text) |
|
343 | + if ($string == $text) |
|
344 | 344 | { |
345 | 345 | $result['strings'][$string] = $target; |
346 | 346 | $result['meta']['PO-Revision-Date'] = @date('Y-m-d H:i:s'); |
@@ -348,9 +348,9 @@ discard block |
||
348 | 348 | $po->fromArray($result); |
349 | 349 | $mo = $po->toMO(); |
350 | 350 | |
351 | - if($po->save() && $mo->save($MOFile)) |
|
351 | + if ($po->save() && $mo->save($MOFile)) |
|
352 | 352 | { |
353 | - if(!empty($this->cache)) |
|
353 | + if (!empty($this->cache)) |
|
354 | 354 | $this->cache->clean($variant, $this->culture); |
355 | 355 | return true; |
356 | 356 | } |
@@ -380,31 +380,31 @@ discard block |
||
380 | 380 | */ |
381 | 381 | protected function getCatalogues($dir = null, $variant = null) |
382 | 382 | { |
383 | - $dir = $dir?$dir:$this->source; |
|
383 | + $dir = $dir ? $dir : $this->source; |
|
384 | 384 | $files = scandir($dir); |
385 | 385 | |
386 | 386 | $catalogue = []; |
387 | 387 | |
388 | - foreach($files as $file) |
|
388 | + foreach ($files as $file) |
|
389 | 389 | { |
390 | - if(is_dir($dir . '/' . $file) |
|
390 | + if (is_dir($dir.'/'.$file) |
|
391 | 391 | && preg_match('/^[a-z]{2}(_[A-Z]{2,3})?$/', $file)) |
392 | 392 | { |
393 | 393 | |
394 | 394 | $catalogue = array_merge($catalogue, |
395 | - $this->getCatalogues($dir . '/' . $file, $file)); |
|
395 | + $this->getCatalogues($dir.'/'.$file, $file)); |
|
396 | 396 | } |
397 | 397 | |
398 | 398 | $pos = strpos($file, $this->dataExt); |
399 | 399 | |
400 | - if($pos > 0 |
|
400 | + if ($pos > 0 |
|
401 | 401 | && substr($file, -1 * strlen($this->dataExt)) == $this->dataExt) |
402 | 402 | { |
403 | 403 | $name = substr($file, 0, $pos); |
404 | 404 | $dot = strrpos($name, $this->dataSeparator); |
405 | 405 | $culture = $variant; |
406 | 406 | $cat = $name; |
407 | - if(is_int($dot)) |
|
407 | + if (is_int($dot)) |
|
408 | 408 | { |
409 | 409 | $culture = substr($name, $dot + 1, strlen($name)); |
410 | 410 | $cat = substr($name, 0, $dot); |
@@ -423,7 +423,7 @@ discard block |
||
423 | 423 | |
424 | 424 | protected function createMessageTemplate($catalogue) |
425 | 425 | { |
426 | - if($catalogue === null) { |
|
426 | + if ($catalogue === null) { |
|
427 | 427 | $catalogue = 'messages'; |
428 | 428 | } |
429 | 429 | $variants = $this->getCatalogueList($catalogue); |
@@ -432,12 +432,12 @@ discard block |
||
432 | 432 | $po_file = $this->getPOFile($mo_file); |
433 | 433 | |
434 | 434 | $dir = dirname($mo_file); |
435 | - if(!is_dir($dir)) |
|
435 | + if (!is_dir($dir)) |
|
436 | 436 | { |
437 | 437 | @mkdir($dir); |
438 | 438 | @chmod($dir, PRADO_CHMOD); |
439 | 439 | } |
440 | - if(!is_dir($dir)) |
|
440 | + if (!is_dir($dir)) |
|
441 | 441 | throw new TException("Unable to create directory $dir"); |
442 | 442 | |
443 | 443 | $po = TGettext::factory('PO', $po_file); |
@@ -446,7 +446,7 @@ discard block |
||
446 | 446 | |
447 | 447 | $po->fromArray($result); |
448 | 448 | $mo = $po->toMO(); |
449 | - if($po->save() && $mo->save($mo_file)) |
|
449 | + if ($po->save() && $mo->save($mo_file)) |
|
450 | 450 | return [$variant, $mo_file, $po_file]; |
451 | 451 | else |
452 | 452 | throw new TException("Unable to create file $po_file and $mo_file"); |
@@ -115,10 +115,11 @@ discard block |
||
115 | 115 | */ |
116 | 116 | protected function getLastModified($source) |
117 | 117 | { |
118 | - if(is_file($source)) |
|
119 | - return filemtime($source); |
|
120 | - else |
|
121 | - return 0; |
|
118 | + if(is_file($source)) { |
|
119 | + return filemtime($source); |
|
120 | + } else { |
|
121 | + return 0; |
|
122 | + } |
|
122 | 123 | } |
123 | 124 | |
124 | 125 | /** |
@@ -193,8 +194,9 @@ discard block |
||
193 | 194 | { |
194 | 195 | $file = $this->getSource($variant); |
195 | 196 | $po = $this->getPOFile($file); |
196 | - if(is_file($file) || is_file($po)) |
|
197 | - return [$variant, $file, $po]; |
|
197 | + if(is_file($file) || is_file($po)) { |
|
198 | + return [$variant, $file, $po]; |
|
199 | + } |
|
198 | 200 | } |
199 | 201 | return false; |
200 | 202 | } |
@@ -216,24 +218,30 @@ discard block |
||
216 | 218 | { |
217 | 219 | $messages = $this->untranslated; |
218 | 220 | |
219 | - if(count($messages) <= 0) return false; |
|
221 | + if(count($messages) <= 0) { |
|
222 | + return false; |
|
223 | + } |
|
220 | 224 | |
221 | 225 | $variants = $this->getVariants($catalogue); |
222 | 226 | |
223 | - if($variants) |
|
224 | - list($variant, $MOFile, $POFile) = $variants; |
|
225 | - else |
|
226 | - list($variant, $MOFile, $POFile) = $this->createMessageTemplate($catalogue); |
|
227 | + if($variants) { |
|
228 | + list($variant, $MOFile, $POFile) = $variants; |
|
229 | + } else { |
|
230 | + list($variant, $MOFile, $POFile) = $this->createMessageTemplate($catalogue); |
|
231 | + } |
|
227 | 232 | |
228 | - if(is_writable($MOFile) == false) |
|
229 | - throw new TIOException("Unable to save to file {$MOFile}, file must be writable."); |
|
230 | - if(is_writable($POFile) == false) |
|
231 | - throw new TIOException("Unable to save to file {$POFile}, file must be writable."); |
|
233 | + if(is_writable($MOFile) == false) { |
|
234 | + throw new TIOException("Unable to save to file {$MOFile}, file must be writable."); |
|
235 | + } |
|
236 | + if(is_writable($POFile) == false) { |
|
237 | + throw new TIOException("Unable to save to file {$POFile}, file must be writable."); |
|
238 | + } |
|
232 | 239 | |
233 | 240 | //set the strings as untranslated. |
234 | 241 | $strings = []; |
235 | - foreach($messages as $message) |
|
236 | - $strings[$message] = ''; |
|
242 | + foreach($messages as $message) { |
|
243 | + $strings[$message] = ''; |
|
244 | + } |
|
237 | 245 | |
238 | 246 | //load the PO |
239 | 247 | $po = TGettext::factory('PO', $POFile); |
@@ -256,12 +264,13 @@ discard block |
||
256 | 264 | $mo = $po->toMO(); |
257 | 265 | if($po->save() && $mo->save($MOFile)) |
258 | 266 | { |
259 | - if(!empty($this->cache)) |
|
260 | - $this->cache->clean($variant, $this->culture); |
|
267 | + if(!empty($this->cache)) { |
|
268 | + $this->cache->clean($variant, $this->culture); |
|
269 | + } |
|
261 | 270 | return true; |
271 | + } else { |
|
272 | + return false; |
|
262 | 273 | } |
263 | - else |
|
264 | - return false; |
|
265 | 274 | } |
266 | 275 | return false; |
267 | 276 | } |
@@ -275,15 +284,18 @@ discard block |
||
275 | 284 | public function delete($message, $catalogue = 'messages') |
276 | 285 | { |
277 | 286 | $variants = $this->getVariants($catalogue); |
278 | - if($variants) |
|
279 | - list($variant, $MOFile, $POFile) = $variants; |
|
280 | - else |
|
281 | - return false; |
|
287 | + if($variants) { |
|
288 | + list($variant, $MOFile, $POFile) = $variants; |
|
289 | + } else { |
|
290 | + return false; |
|
291 | + } |
|
282 | 292 | |
283 | - if(is_writable($MOFile) == false) |
|
284 | - throw new TIOException("Unable to modify file {$MOFile}, file must be writable."); |
|
285 | - if(is_writable($POFile) == false) |
|
286 | - throw new TIOException("Unable to modify file {$POFile}, file must be writable."); |
|
293 | + if(is_writable($MOFile) == false) { |
|
294 | + throw new TIOException("Unable to modify file {$MOFile}, file must be writable."); |
|
295 | + } |
|
296 | + if(is_writable($POFile) == false) { |
|
297 | + throw new TIOException("Unable to modify file {$POFile}, file must be writable."); |
|
298 | + } |
|
287 | 299 | |
288 | 300 | $po = TGettext::factory('PO', $POFile); |
289 | 301 | $po->load(); |
@@ -300,12 +312,13 @@ discard block |
||
300 | 312 | $mo = $po->toMO(); |
301 | 313 | if($po->save() && $mo->save($MOFile)) |
302 | 314 | { |
303 | - if(!empty($this->cache)) |
|
304 | - $this->cache->clean($variant, $this->culture); |
|
315 | + if(!empty($this->cache)) { |
|
316 | + $this->cache->clean($variant, $this->culture); |
|
317 | + } |
|
305 | 318 | return true; |
319 | + } else { |
|
320 | + return false; |
|
306 | 321 | } |
307 | - else |
|
308 | - return false; |
|
309 | 322 | } |
310 | 323 | } |
311 | 324 | |
@@ -323,15 +336,18 @@ discard block |
||
323 | 336 | public function update($text, $target, $comments, $catalogue = 'messages') |
324 | 337 | { |
325 | 338 | $variants = $this->getVariants($catalogue); |
326 | - if($variants) |
|
327 | - list($variant, $MOFile, $POFile) = $variants; |
|
328 | - else |
|
329 | - return false; |
|
339 | + if($variants) { |
|
340 | + list($variant, $MOFile, $POFile) = $variants; |
|
341 | + } else { |
|
342 | + return false; |
|
343 | + } |
|
330 | 344 | |
331 | - if(is_writable($MOFile) == false) |
|
332 | - throw new TIOException("Unable to update file {$MOFile}, file must be writable."); |
|
333 | - if(is_writable($POFile) == false) |
|
334 | - throw new TIOException("Unable to update file {$POFile}, file must be writable."); |
|
345 | + if(is_writable($MOFile) == false) { |
|
346 | + throw new TIOException("Unable to update file {$MOFile}, file must be writable."); |
|
347 | + } |
|
348 | + if(is_writable($POFile) == false) { |
|
349 | + throw new TIOException("Unable to update file {$POFile}, file must be writable."); |
|
350 | + } |
|
335 | 351 | |
336 | 352 | |
337 | 353 | $po = TGettext::factory('PO', $POFile); |
@@ -350,12 +366,13 @@ discard block |
||
350 | 366 | |
351 | 367 | if($po->save() && $mo->save($MOFile)) |
352 | 368 | { |
353 | - if(!empty($this->cache)) |
|
354 | - $this->cache->clean($variant, $this->culture); |
|
369 | + if(!empty($this->cache)) { |
|
370 | + $this->cache->clean($variant, $this->culture); |
|
371 | + } |
|
355 | 372 | return true; |
373 | + } else { |
|
374 | + return false; |
|
356 | 375 | } |
357 | - else |
|
358 | - return false; |
|
359 | 376 | } |
360 | 377 | } |
361 | 378 | |
@@ -437,8 +454,9 @@ discard block |
||
437 | 454 | @mkdir($dir); |
438 | 455 | @chmod($dir, PRADO_CHMOD); |
439 | 456 | } |
440 | - if(!is_dir($dir)) |
|
441 | - throw new TException("Unable to create directory $dir"); |
|
457 | + if(!is_dir($dir)) { |
|
458 | + throw new TException("Unable to create directory $dir"); |
|
459 | + } |
|
442 | 460 | |
443 | 461 | $po = TGettext::factory('PO', $po_file); |
444 | 462 | $result['meta']['PO-Revision-Date'] = @date('Y-m-d H:i:s'); |
@@ -446,10 +464,11 @@ discard block |
||
446 | 464 | |
447 | 465 | $po->fromArray($result); |
448 | 466 | $mo = $po->toMO(); |
449 | - if($po->save() && $mo->save($mo_file)) |
|
450 | - return [$variant, $mo_file, $po_file]; |
|
451 | - else |
|
452 | - throw new TException("Unable to create file $po_file and $mo_file"); |
|
467 | + if($po->save() && $mo->save($mo_file)) { |
|
468 | + return [$variant, $mo_file, $po_file]; |
|
469 | + } else { |
|
470 | + throw new TException("Unable to create file $po_file and $mo_file"); |
|
471 | + } |
|
453 | 472 | } |
454 | 473 | } |
455 | 474 |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | */ |
24 | 24 | use Exception; |
25 | 25 | |
26 | -require_once(dirname(__FILE__) . '/CultureInfo.php'); |
|
26 | +require_once(dirname(__FILE__).'/CultureInfo.php'); |
|
27 | 27 | |
28 | 28 | |
29 | 29 | /** |
@@ -98,11 +98,11 @@ discard block |
||
98 | 98 | */ |
99 | 99 | public function __get($name) |
100 | 100 | { |
101 | - $getProperty = 'get' . $name; |
|
102 | - if(in_array($getProperty, $this->properties)) |
|
101 | + $getProperty = 'get'.$name; |
|
102 | + if (in_array($getProperty, $this->properties)) |
|
103 | 103 | return $this->$getProperty(); |
104 | 104 | else |
105 | - throw new Exception('Property ' . $name . ' does not exists.'); |
|
105 | + throw new Exception('Property '.$name.' does not exists.'); |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | /** |
@@ -111,11 +111,11 @@ discard block |
||
111 | 111 | */ |
112 | 112 | public function __set($name, $value) |
113 | 113 | { |
114 | - $setProperty = 'set' . $name; |
|
115 | - if(in_array($setProperty, $this->properties)) |
|
114 | + $setProperty = 'set'.$name; |
|
115 | + if (in_array($setProperty, $this->properties)) |
|
116 | 116 | $this->$setProperty($value); |
117 | 117 | else |
118 | - throw new Exception('Property ' . $name . ' can not be set.'); |
|
118 | + throw new Exception('Property '.$name.' can not be set.'); |
|
119 | 119 | } |
120 | 120 | |
121 | 121 | /** |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | { |
132 | 132 | $this->properties = get_class_methods($this); |
133 | 133 | |
134 | - if(empty($data)) |
|
134 | + if (empty($data)) |
|
135 | 135 | throw new Exception('Please provide the ICU data to initialize.'); |
136 | 136 | |
137 | 137 | $this->data = $data; |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | public static function getInvariantInfo() |
155 | 155 | { |
156 | 156 | static $invariant; |
157 | - if($invariant === null) |
|
157 | + if ($invariant === null) |
|
158 | 158 | { |
159 | 159 | $culture = CultureInfo::getInvariantCulture(); |
160 | 160 | $invariant = $culture->getDateTimeFormat(); |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | |
174 | 174 | if ($culture instanceof CultureInfo) |
175 | 175 | return $culture->getDateTimeFormat(); |
176 | - elseif(is_string($culture)) |
|
176 | + elseif (is_string($culture)) |
|
177 | 177 | { |
178 | 178 | $cultureInfo = CultureInfo::getInstance($culture); |
179 | 179 | return $cultureInfo->getDateTimeFormat(); |
@@ -512,7 +512,7 @@ discard block |
||
512 | 512 | public function formatDateTime($date, $time) |
513 | 513 | { |
514 | 514 | $pattern = $this->getDateTimeOrderPattern(); |
515 | - return str_replace(['{0}','{1}'], [$time, $date], $pattern); |
|
515 | + return str_replace(['{0}', '{1}'], [$time, $date], $pattern); |
|
516 | 516 | } |
517 | 517 | |
518 | 518 | } |
@@ -99,10 +99,11 @@ discard block |
||
99 | 99 | public function __get($name) |
100 | 100 | { |
101 | 101 | $getProperty = 'get' . $name; |
102 | - if(in_array($getProperty, $this->properties)) |
|
103 | - return $this->$getProperty(); |
|
104 | - else |
|
105 | - throw new Exception('Property ' . $name . ' does not exists.'); |
|
102 | + if(in_array($getProperty, $this->properties)) { |
|
103 | + return $this->$getProperty(); |
|
104 | + } else { |
|
105 | + throw new Exception('Property ' . $name . ' does not exists.'); |
|
106 | + } |
|
106 | 107 | } |
107 | 108 | |
108 | 109 | /** |
@@ -112,10 +113,11 @@ discard block |
||
112 | 113 | public function __set($name, $value) |
113 | 114 | { |
114 | 115 | $setProperty = 'set' . $name; |
115 | - if(in_array($setProperty, $this->properties)) |
|
116 | - $this->$setProperty($value); |
|
117 | - else |
|
118 | - throw new Exception('Property ' . $name . ' can not be set.'); |
|
116 | + if(in_array($setProperty, $this->properties)) { |
|
117 | + $this->$setProperty($value); |
|
118 | + } else { |
|
119 | + throw new Exception('Property ' . $name . ' can not be set.'); |
|
120 | + } |
|
119 | 121 | } |
120 | 122 | |
121 | 123 | /** |
@@ -131,8 +133,9 @@ discard block |
||
131 | 133 | { |
132 | 134 | $this->properties = get_class_methods($this); |
133 | 135 | |
134 | - if(empty($data)) |
|
135 | - throw new Exception('Please provide the ICU data to initialize.'); |
|
136 | + if(empty($data)) { |
|
137 | + throw new Exception('Please provide the ICU data to initialize.'); |
|
138 | + } |
|
136 | 139 | |
137 | 140 | $this->data = $data; |
138 | 141 | } |
@@ -171,14 +174,13 @@ discard block |
||
171 | 174 | public static function getInstance($culture = null) |
172 | 175 | { |
173 | 176 | |
174 | - if ($culture instanceof CultureInfo) |
|
175 | - return $culture->getDateTimeFormat(); |
|
176 | - elseif(is_string($culture)) |
|
177 | + if ($culture instanceof CultureInfo) { |
|
178 | + return $culture->getDateTimeFormat(); |
|
179 | + } elseif(is_string($culture)) |
|
177 | 180 | { |
178 | 181 | $cultureInfo = CultureInfo::getInstance($culture); |
179 | 182 | return $cultureInfo->getDateTimeFormat(); |
180 | - } |
|
181 | - else |
|
183 | + } else |
|
182 | 184 | { |
183 | 185 | $cultureInfo = CultureInfo::getInvariantCulture(); |
184 | 186 | return $cultureInfo->getDateTimeFormat(); |
@@ -294,10 +296,11 @@ discard block |
||
294 | 296 | */ |
295 | 297 | public function getAbbreviatedMonthNames() |
296 | 298 | { |
297 | - if (isset($this->data['monthNames']['format']['abbreviated'])) |
|
298 | - return $this->data['monthNames']['format']['abbreviated']; |
|
299 | - else |
|
300 | - return $this->data['monthNames']['format']['wide']; |
|
299 | + if (isset($this->data['monthNames']['format']['abbreviated'])) { |
|
300 | + return $this->data['monthNames']['format']['abbreviated']; |
|
301 | + } else { |
|
302 | + return $this->data['monthNames']['format']['wide']; |
|
303 | + } |
|
301 | 304 | } |
302 | 305 | |
303 | 306 | /** |
@@ -233,7 +233,7 @@ discard block |
||
233 | 233 | */ |
234 | 234 | public function __construct($options = [null]) |
235 | 235 | { |
236 | - $availableOptions = [ 'automaticSerialization', |
|
236 | + $availableOptions = ['automaticSerialization', |
|
237 | 237 | 'fileNameProtection', |
238 | 238 | 'memoryCaching', |
239 | 239 | 'onlyMemoryCaching', |
@@ -245,9 +245,9 @@ discard block |
||
245 | 245 | 'writeControl', |
246 | 246 | 'readControl', |
247 | 247 | 'readControlType']; |
248 | - foreach($options as $key => $value) { |
|
249 | - if(in_array($key, $availableOptions)) { |
|
250 | - $property = '_' . $key; |
|
248 | + foreach ($options as $key => $value) { |
|
249 | + if (in_array($key, $availableOptions)) { |
|
250 | + $property = '_'.$key; |
|
251 | 251 | $this->$property = $value; |
252 | 252 | } |
253 | 253 | } |
@@ -375,9 +375,9 @@ discard block |
||
375 | 375 | public function clean($group = false) |
376 | 376 | { |
377 | 377 | if ($this->_fileNameProtection) { |
378 | - $motif = ($group) ? 'cache_' . md5($group) . '_' : 'cache_'; |
|
378 | + $motif = ($group) ? 'cache_'.md5($group).'_' : 'cache_'; |
|
379 | 379 | } else { |
380 | - $motif = ($group) ? 'cache_' . $group . '_' : 'cache_'; |
|
380 | + $motif = ($group) ? 'cache_'.$group.'_' : 'cache_'; |
|
381 | 381 | } |
382 | 382 | if ($this->_memoryCaching) { |
383 | 383 | while (list($key, $value) = each($this->_memoryCaching)) { |
@@ -397,7 +397,7 @@ discard block |
||
397 | 397 | } |
398 | 398 | while ($file = readdir($dh)) { |
399 | 399 | if (($file != '.') && ($file != '..')) { |
400 | - $file = $this->_cacheDir . $file; |
|
400 | + $file = $this->_cacheDir.$file; |
|
401 | 401 | if (is_file($file)) { |
402 | 402 | if (strpos($file, $motif, 0)) { |
403 | 403 | if (!@unlink($file)) { |
@@ -510,10 +510,10 @@ discard block |
||
510 | 510 | public function _setFileName($id, $group) |
511 | 511 | { |
512 | 512 | if ($this->_fileNameProtection) { |
513 | - $this->_file = ($this->_cacheDir . 'cache_' . md5($group) . '_' |
|
513 | + $this->_file = ($this->_cacheDir.'cache_'.md5($group).'_' |
|
514 | 514 | . md5($id)); |
515 | 515 | } else { |
516 | - $this->_file = $this->_cacheDir . 'cache_' . $group . '_' . $id; |
|
516 | + $this->_file = $this->_cacheDir.'cache_'.$group.'_'.$id; |
|
517 | 517 | } |
518 | 518 | } |
519 | 519 | |
@@ -614,7 +614,7 @@ discard block |
||
614 | 614 | case 'strlen': |
615 | 615 | return sprintf('% 32d', strlen($data)); |
616 | 616 | default: |
617 | - $this->raiseError('Unknown controlType ! ' . |
|
617 | + $this->raiseError('Unknown controlType ! '. |
|
618 | 618 | '(available values are only \'md5\', \'crc32\', \'strlen\')', -5); |
619 | 619 | } |
620 | 620 | } |
@@ -531,7 +531,9 @@ discard block |
||
531 | 531 | public function _read() |
532 | 532 | { |
533 | 533 | $fp = @fopen($this->_file, "rb"); |
534 | - if ($this->_fileLocking) @flock($fp, LOCK_SH); |
|
534 | + if ($this->_fileLocking) { |
|
535 | + @flock($fp, LOCK_SH); |
|
536 | + } |
|
535 | 537 | if ($fp) { |
536 | 538 | // because the filesize can be cached by PHP itself... |
537 | 539 | clearstatcache(); |
@@ -541,7 +543,9 @@ discard block |
||
541 | 543 | $length = $length - 32; |
542 | 544 | } |
543 | 545 | $data = @fread($fp, $length); |
544 | - if ($this->_fileLocking) @flock($fp, LOCK_UN); |
|
546 | + if ($this->_fileLocking) { |
|
547 | + @flock($fp, LOCK_UN); |
|
548 | + } |
|
545 | 549 | @fclose($fp); |
546 | 550 | if ($this->_readControl) { |
547 | 551 | $hashData = $this->_hash($data, $this->_readControlType); |
@@ -567,13 +571,17 @@ discard block |
||
567 | 571 | { |
568 | 572 | $fp = @fopen($this->_file, "wb"); |
569 | 573 | if ($fp) { |
570 | - if ($this->_fileLocking) @flock($fp, LOCK_EX); |
|
574 | + if ($this->_fileLocking) { |
|
575 | + @flock($fp, LOCK_EX); |
|
576 | + } |
|
571 | 577 | if ($this->_readControl) { |
572 | 578 | @fwrite($fp, $this->_hash($data, $this->_readControlType), 32); |
573 | 579 | } |
574 | 580 | $len = strlen($data); |
575 | 581 | @fwrite($fp, $data, $len); |
576 | - if ($this->_fileLocking) @flock($fp, LOCK_UN); |
|
582 | + if ($this->_fileLocking) { |
|
583 | + @flock($fp, LOCK_UN); |
|
584 | + } |
|
577 | 585 | @fclose($fp); |
578 | 586 | return true; |
579 | 587 | } |
@@ -23,12 +23,12 @@ discard block |
||
23 | 23 | use Exception; |
24 | 24 | use Prado\Prado; |
25 | 25 | |
26 | -require_once(dirname(__FILE__) . '/DateTimeFormatInfo.php'); |
|
26 | +require_once(dirname(__FILE__).'/DateTimeFormatInfo.php'); |
|
27 | 27 | |
28 | 28 | /** |
29 | 29 | * Get the encoding utilities |
30 | 30 | */ |
31 | -require_once(dirname(__FILE__) . '/util.php'); |
|
31 | +require_once(dirname(__FILE__).'/util.php'); |
|
32 | 32 | |
33 | 33 | /** |
34 | 34 | * DateFormat class. |
@@ -94,11 +94,11 @@ discard block |
||
94 | 94 | */ |
95 | 95 | public function __construct($formatInfo = null) |
96 | 96 | { |
97 | - if($formatInfo === null) |
|
97 | + if ($formatInfo === null) |
|
98 | 98 | $this->formatInfo = DateTimeFormatInfo::getInvariantInfo(); |
99 | - elseif($formatInfo instanceof CultureInfo) |
|
99 | + elseif ($formatInfo instanceof CultureInfo) |
|
100 | 100 | $this->formatInfo = $formatInfo->DateTimeFormat; |
101 | - elseif($formatInfo instanceof DateTimeFormatInfo) |
|
101 | + elseif ($formatInfo instanceof DateTimeFormatInfo) |
|
102 | 102 | $this->formatInfo = $formatInfo; |
103 | 103 | else |
104 | 104 | $this->formatInfo = DateTimeFormatInfo::getInstance($formatInfo); |
@@ -115,10 +115,10 @@ discard block |
||
115 | 115 | { |
116 | 116 | if (is_numeric($time)) //assumes unix epoch |
117 | 117 | $time = floatval($time); |
118 | - elseif(is_string($time)) |
|
118 | + elseif (is_string($time)) |
|
119 | 119 | $time = @strtotime($time); |
120 | 120 | |
121 | - if($pattern === null) |
|
121 | + if ($pattern === null) |
|
122 | 122 | $pattern = 'F'; |
123 | 123 | |
124 | 124 | $date = new \DateTime; |
@@ -128,33 +128,33 @@ discard block |
||
128 | 128 | |
129 | 129 | $tokens = $this->getTokens($pattern); |
130 | 130 | |
131 | - for($i = 0, $k = count($tokens); $i < $k; ++$i) |
|
131 | + for ($i = 0, $k = count($tokens); $i < $k; ++$i) |
|
132 | 132 | { |
133 | 133 | $pattern = $tokens[$i]; |
134 | - if($pattern{0} == "'" |
|
134 | + if ($pattern{0} == "'" |
|
135 | 135 | && $pattern{strlen($pattern) - 1} == "'") |
136 | 136 | { |
137 | 137 | $sub = preg_replace('/(^\')|(\'$)/', '', $pattern); |
138 | 138 | $tokens[$i] = str_replace('``````', '\'', $sub); |
139 | 139 | } |
140 | - elseif($pattern == '``````') |
|
140 | + elseif ($pattern == '``````') |
|
141 | 141 | { |
142 | 142 | $tokens[$i] = '\''; |
143 | 143 | } |
144 | 144 | else |
145 | 145 | { |
146 | 146 | $function = $this->getFunctionName($pattern); |
147 | - if($function != null) |
|
147 | + if ($function != null) |
|
148 | 148 | { |
149 | - $fName = 'get' . $function; |
|
150 | - if(in_array($fName, $this->methods)) |
|
149 | + $fName = 'get'.$function; |
|
150 | + if (in_array($fName, $this->methods)) |
|
151 | 151 | { |
152 | 152 | $rs = $this->$fName($date, $pattern); |
153 | 153 | $tokens[$i] = $rs; |
154 | 154 | } |
155 | 155 | else |
156 | 156 | throw new |
157 | - Exception('function ' . $function . ' not found.'); |
|
157 | + Exception('function '.$function.' not found.'); |
|
158 | 158 | } |
159 | 159 | } |
160 | 160 | } |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | */ |
170 | 170 | protected function getFunctionName($token) |
171 | 171 | { |
172 | - if(isset($this->tokens[$token{0}])) |
|
172 | + if (isset($this->tokens[$token{0}])) |
|
173 | 173 | return $this->tokens[$token{0}]; |
174 | 174 | } |
175 | 175 | |
@@ -186,14 +186,14 @@ discard block |
||
186 | 186 | */ |
187 | 187 | protected function getPattern($pattern) |
188 | 188 | { |
189 | - if(is_array($pattern) && count($pattern) == 2) |
|
189 | + if (is_array($pattern) && count($pattern) == 2) |
|
190 | 190 | { |
191 | 191 | return $this->formatInfo->formatDateTime( |
192 | 192 | $this->getPattern($pattern[0]), |
193 | 193 | $this->getPattern($pattern[1])); |
194 | 194 | } |
195 | 195 | |
196 | - switch($pattern) |
|
196 | + switch ($pattern) |
|
197 | 197 | { |
198 | 198 | case 'd': |
199 | 199 | return $this->formatInfo->ShortDatePattern; |
@@ -282,9 +282,9 @@ discard block |
||
282 | 282 | $text = false; |
283 | 283 | $pattern = preg_replace("/''/", '``````', $pattern); |
284 | 284 | |
285 | - for($i = 0; $i < strlen($pattern); $i++) |
|
285 | + for ($i = 0; $i < strlen($pattern); $i++) |
|
286 | 286 | { |
287 | - if($char == null || $pattern{$i} == $char || $text) |
|
287 | + if ($char == null || $pattern{$i} == $char || $text) |
|
288 | 288 | { |
289 | 289 | $token .= $pattern{$i}; |
290 | 290 | } |
@@ -294,11 +294,11 @@ discard block |
||
294 | 294 | $token = $pattern{$i}; |
295 | 295 | } |
296 | 296 | |
297 | - if($pattern{$i} == "'" && $text == false) |
|
297 | + if ($pattern{$i} == "'" && $text == false) |
|
298 | 298 | $text = true; |
299 | - elseif($text && $pattern{$i} == "'" && $char == "'") |
|
299 | + elseif ($text && $pattern{$i} == "'" && $char == "'") |
|
300 | 300 | $text = true; |
301 | - elseif($text && $char != "'" && $pattern{$i} == "'") |
|
301 | + elseif ($text && $char != "'" && $pattern{$i} == "'") |
|
302 | 302 | $text = false; |
303 | 303 | |
304 | 304 | $char = $pattern{$i}; |
@@ -318,7 +318,7 @@ discard block |
||
318 | 318 | */ |
319 | 319 | protected function getYear($date, $pattern = 'yyyy') |
320 | 320 | { |
321 | - switch($pattern) |
|
321 | + switch ($pattern) |
|
322 | 322 | { |
323 | 323 | case 'yy': |
324 | 324 | return $date->format('y'); |
@@ -341,7 +341,7 @@ discard block |
||
341 | 341 | */ |
342 | 342 | protected function getMonth($date, $pattern = 'M') |
343 | 343 | { |
344 | - switch($pattern) |
|
344 | + switch ($pattern) |
|
345 | 345 | { |
346 | 346 | case 'M': |
347 | 347 | return $date->format('n'); |
@@ -369,7 +369,7 @@ discard block |
||
369 | 369 | protected function getDayInWeek($date, $pattern = 'EEEE') |
370 | 370 | { |
371 | 371 | $day = $date->format('w'); |
372 | - switch($pattern) |
|
372 | + switch ($pattern) |
|
373 | 373 | { |
374 | 374 | case 'E': |
375 | 375 | return $day; |
@@ -393,7 +393,7 @@ discard block |
||
393 | 393 | */ |
394 | 394 | protected function getDay($date, $pattern = 'd') |
395 | 395 | { |
396 | - switch($pattern) |
|
396 | + switch ($pattern) |
|
397 | 397 | { |
398 | 398 | case 'd': |
399 | 399 | return $date->format('j'); |
@@ -414,11 +414,11 @@ discard block |
||
414 | 414 | */ |
415 | 415 | protected function getEra($date, $pattern = 'G') |
416 | 416 | { |
417 | - if($pattern != 'G') |
|
417 | + if ($pattern != 'G') |
|
418 | 418 | throw new Exception('The pattern for era is "G".'); |
419 | 419 | |
420 | 420 | $year = $date->format('Y'); |
421 | - if($year > 0) |
|
421 | + if ($year > 0) |
|
422 | 422 | return $this->formatInfo->getEra(1); |
423 | 423 | else |
424 | 424 | return $this->formatInfo->getEra(0); |
@@ -433,7 +433,7 @@ discard block |
||
433 | 433 | */ |
434 | 434 | protected function getHour24($date, $pattern = 'H') |
435 | 435 | { |
436 | - switch($pattern) |
|
436 | + switch ($pattern) |
|
437 | 437 | { |
438 | 438 | case 'H': |
439 | 439 | return $date->format('G'); |
@@ -452,11 +452,11 @@ discard block |
||
452 | 452 | */ |
453 | 453 | protected function getAMPM($date, $pattern = 'a') |
454 | 454 | { |
455 | - if($pattern != 'a') |
|
455 | + if ($pattern != 'a') |
|
456 | 456 | throw new Exception('The pattern for AM/PM marker is "a".'); |
457 | 457 | |
458 | 458 | $hour = $date->format('G'); |
459 | - $ampm = (int)($hour / 12); |
|
459 | + $ampm = (int) ($hour / 12); |
|
460 | 460 | return $this->formatInfo->AMPMMarkers[$ampm]; |
461 | 461 | } |
462 | 462 | |
@@ -469,7 +469,7 @@ discard block |
||
469 | 469 | */ |
470 | 470 | protected function getHour12($date, $pattern = 'h') |
471 | 471 | { |
472 | - switch($pattern) |
|
472 | + switch ($pattern) |
|
473 | 473 | { |
474 | 474 | case 'h': |
475 | 475 | return $date->format('g'); |
@@ -489,7 +489,7 @@ discard block |
||
489 | 489 | */ |
490 | 490 | protected function getMinutes($date, $pattern = 'm') |
491 | 491 | { |
492 | - switch($pattern) |
|
492 | + switch ($pattern) |
|
493 | 493 | { |
494 | 494 | case 'm': |
495 | 495 | return (int) $date->format('i'); |
@@ -509,7 +509,7 @@ discard block |
||
509 | 509 | */ |
510 | 510 | protected function getSeconds($date, $pattern = 's') |
511 | 511 | { |
512 | - switch($pattern) |
|
512 | + switch ($pattern) |
|
513 | 513 | { |
514 | 514 | case 's': |
515 | 515 | return (int) $date->format('s'); |
@@ -529,7 +529,7 @@ discard block |
||
529 | 529 | */ |
530 | 530 | protected function getTimeZone($date, $pattern = 'z') |
531 | 531 | { |
532 | - if($pattern != 'z') |
|
532 | + if ($pattern != 'z') |
|
533 | 533 | throw new Exception('The pattern for time zone is "z".'); |
534 | 534 | |
535 | 535 | return $date->format('T'); |
@@ -543,7 +543,7 @@ discard block |
||
543 | 543 | */ |
544 | 544 | protected function getDayInYear($date, $pattern = 'D') |
545 | 545 | { |
546 | - if($pattern != 'D') |
|
546 | + if ($pattern != 'D') |
|
547 | 547 | throw new Exception('The pattern for day in year is "D".'); |
548 | 548 | |
549 | 549 | return $date->format('z'); |
@@ -575,7 +575,7 @@ discard block |
||
575 | 575 | */ |
576 | 576 | protected function getWeekInYear($date, $pattern = 'w') |
577 | 577 | { |
578 | - if($pattern != 'w') |
|
578 | + if ($pattern != 'w') |
|
579 | 579 | throw new Exception('The pattern for week in year is "w".'); |
580 | 580 | |
581 | 581 | return $date->format('W'); |
@@ -588,7 +588,7 @@ discard block |
||
588 | 588 | */ |
589 | 589 | protected function getWeekInMonth($date, $pattern = 'W') |
590 | 590 | { |
591 | - if($pattern != 'W') |
|
591 | + if ($pattern != 'W') |
|
592 | 592 | throw new Exception('The pattern for week in month is "W".'); |
593 | 593 | |
594 | 594 | $firstInMonth = clone($date); |
@@ -604,7 +604,7 @@ discard block |
||
604 | 604 | */ |
605 | 605 | protected function getHourInDay($date, $pattern = 'k') |
606 | 606 | { |
607 | - if($pattern != 'k') |
|
607 | + if ($pattern != 'k') |
|
608 | 608 | throw new Exception('The pattern for hour in day is "k".'); |
609 | 609 | |
610 | 610 | return $date->format('G') + 1; |
@@ -618,7 +618,7 @@ discard block |
||
618 | 618 | */ |
619 | 619 | protected function getHourInAMPM($date, $pattern = 'K') |
620 | 620 | { |
621 | - if($pattern != 'K') |
|
621 | + if ($pattern != 'K') |
|
622 | 622 | throw new Exception('The pattern for hour in AM/PM is "K".'); |
623 | 623 | |
624 | 624 | return $date->format('g') + 1; |
@@ -94,14 +94,15 @@ discard block |
||
94 | 94 | */ |
95 | 95 | public function __construct($formatInfo = null) |
96 | 96 | { |
97 | - if($formatInfo === null) |
|
98 | - $this->formatInfo = DateTimeFormatInfo::getInvariantInfo(); |
|
99 | - elseif($formatInfo instanceof CultureInfo) |
|
100 | - $this->formatInfo = $formatInfo->DateTimeFormat; |
|
101 | - elseif($formatInfo instanceof DateTimeFormatInfo) |
|
102 | - $this->formatInfo = $formatInfo; |
|
103 | - else |
|
104 | - $this->formatInfo = DateTimeFormatInfo::getInstance($formatInfo); |
|
97 | + if($formatInfo === null) { |
|
98 | + $this->formatInfo = DateTimeFormatInfo::getInvariantInfo(); |
|
99 | + } elseif($formatInfo instanceof CultureInfo) { |
|
100 | + $this->formatInfo = $formatInfo->DateTimeFormat; |
|
101 | + } elseif($formatInfo instanceof DateTimeFormatInfo) { |
|
102 | + $this->formatInfo = $formatInfo; |
|
103 | + } else { |
|
104 | + $this->formatInfo = DateTimeFormatInfo::getInstance($formatInfo); |
|
105 | + } |
|
105 | 106 | |
106 | 107 | $this->methods = get_class_methods($this); |
107 | 108 | } |
@@ -113,13 +114,16 @@ discard block |
||
113 | 114 | */ |
114 | 115 | public function format($time, $pattern = 'F', $charset = 'UTF-8') |
115 | 116 | { |
116 | - if (is_numeric($time)) //assumes unix epoch |
|
117 | + if (is_numeric($time)) { |
|
118 | + //assumes unix epoch |
|
117 | 119 | $time = floatval($time); |
118 | - elseif(is_string($time)) |
|
119 | - $time = @strtotime($time); |
|
120 | + } elseif(is_string($time)) { |
|
121 | + $time = @strtotime($time); |
|
122 | + } |
|
120 | 123 | |
121 | - if($pattern === null) |
|
122 | - $pattern = 'F'; |
|
124 | + if($pattern === null) { |
|
125 | + $pattern = 'F'; |
|
126 | + } |
|
123 | 127 | |
124 | 128 | $date = new \DateTime; |
125 | 129 | $date->setTimestamp($time); |
@@ -136,12 +140,10 @@ discard block |
||
136 | 140 | { |
137 | 141 | $sub = preg_replace('/(^\')|(\'$)/', '', $pattern); |
138 | 142 | $tokens[$i] = str_replace('``````', '\'', $sub); |
139 | - } |
|
140 | - elseif($pattern == '``````') |
|
143 | + } elseif($pattern == '``````') |
|
141 | 144 | { |
142 | 145 | $tokens[$i] = '\''; |
143 | - } |
|
144 | - else |
|
146 | + } else |
|
145 | 147 | { |
146 | 148 | $function = $this->getFunctionName($pattern); |
147 | 149 | if($function != null) |
@@ -151,10 +153,10 @@ discard block |
||
151 | 153 | { |
152 | 154 | $rs = $this->$fName($date, $pattern); |
153 | 155 | $tokens[$i] = $rs; |
154 | - } |
|
155 | - else |
|
156 | - throw new |
|
156 | + } else { |
|
157 | + throw new |
|
157 | 158 | Exception('function ' . $function . ' not found.'); |
159 | + } |
|
158 | 160 | } |
159 | 161 | } |
160 | 162 | } |
@@ -169,8 +171,9 @@ discard block |
||
169 | 171 | */ |
170 | 172 | protected function getFunctionName($token) |
171 | 173 | { |
172 | - if(isset($this->tokens[$token{0}])) |
|
173 | - return $this->tokens[$token{0}]; |
|
174 | + if(isset($this->tokens[$token{0}])) { |
|
175 | + return $this->tokens[$token{0}]; |
|
176 | + } |
|
174 | 177 | } |
175 | 178 | |
176 | 179 | /** |
@@ -287,19 +290,19 @@ discard block |
||
287 | 290 | if($char == null || $pattern{$i} == $char || $text) |
288 | 291 | { |
289 | 292 | $token .= $pattern{$i}; |
290 | - } |
|
291 | - else |
|
293 | + } else |
|
292 | 294 | { |
293 | 295 | $tokens[] = str_replace("", "'", $token); |
294 | 296 | $token = $pattern{$i}; |
295 | 297 | } |
296 | 298 | |
297 | - if($pattern{$i} == "'" && $text == false) |
|
298 | - $text = true; |
|
299 | - elseif($text && $pattern{$i} == "'" && $char == "'") |
|
300 | - $text = true; |
|
301 | - elseif($text && $char != "'" && $pattern{$i} == "'") |
|
302 | - $text = false; |
|
299 | + if($pattern{$i} == "'" && $text == false) { |
|
300 | + $text = true; |
|
301 | + } elseif($text && $pattern{$i} == "'" && $char == "'") { |
|
302 | + $text = true; |
|
303 | + } elseif($text && $char != "'" && $pattern{$i} == "'") { |
|
304 | + $text = false; |
|
305 | + } |
|
303 | 306 | |
304 | 307 | $char = $pattern{$i}; |
305 | 308 | |
@@ -414,14 +417,16 @@ discard block |
||
414 | 417 | */ |
415 | 418 | protected function getEra($date, $pattern = 'G') |
416 | 419 | { |
417 | - if($pattern != 'G') |
|
418 | - throw new Exception('The pattern for era is "G".'); |
|
420 | + if($pattern != 'G') { |
|
421 | + throw new Exception('The pattern for era is "G".'); |
|
422 | + } |
|
419 | 423 | |
420 | 424 | $year = $date->format('Y'); |
421 | - if($year > 0) |
|
422 | - return $this->formatInfo->getEra(1); |
|
423 | - else |
|
424 | - return $this->formatInfo->getEra(0); |
|
425 | + if($year > 0) { |
|
426 | + return $this->formatInfo->getEra(1); |
|
427 | + } else { |
|
428 | + return $this->formatInfo->getEra(0); |
|
429 | + } |
|
425 | 430 | } |
426 | 431 | |
427 | 432 | /** |
@@ -452,8 +457,9 @@ discard block |
||
452 | 457 | */ |
453 | 458 | protected function getAMPM($date, $pattern = 'a') |
454 | 459 | { |
455 | - if($pattern != 'a') |
|
456 | - throw new Exception('The pattern for AM/PM marker is "a".'); |
|
460 | + if($pattern != 'a') { |
|
461 | + throw new Exception('The pattern for AM/PM marker is "a".'); |
|
462 | + } |
|
457 | 463 | |
458 | 464 | $hour = $date->format('G'); |
459 | 465 | $ampm = (int)($hour / 12); |
@@ -529,8 +535,9 @@ discard block |
||
529 | 535 | */ |
530 | 536 | protected function getTimeZone($date, $pattern = 'z') |
531 | 537 | { |
532 | - if($pattern != 'z') |
|
533 | - throw new Exception('The pattern for time zone is "z".'); |
|
538 | + if($pattern != 'z') { |
|
539 | + throw new Exception('The pattern for time zone is "z".'); |
|
540 | + } |
|
534 | 541 | |
535 | 542 | return $date->format('T'); |
536 | 543 | } |
@@ -543,8 +550,9 @@ discard block |
||
543 | 550 | */ |
544 | 551 | protected function getDayInYear($date, $pattern = 'D') |
545 | 552 | { |
546 | - if($pattern != 'D') |
|
547 | - throw new Exception('The pattern for day in year is "D".'); |
|
553 | + if($pattern != 'D') { |
|
554 | + throw new Exception('The pattern for day in year is "D".'); |
|
555 | + } |
|
548 | 556 | |
549 | 557 | return $date->format('z'); |
550 | 558 | } |
@@ -575,8 +583,9 @@ discard block |
||
575 | 583 | */ |
576 | 584 | protected function getWeekInYear($date, $pattern = 'w') |
577 | 585 | { |
578 | - if($pattern != 'w') |
|
579 | - throw new Exception('The pattern for week in year is "w".'); |
|
586 | + if($pattern != 'w') { |
|
587 | + throw new Exception('The pattern for week in year is "w".'); |
|
588 | + } |
|
580 | 589 | |
581 | 590 | return $date->format('W'); |
582 | 591 | } |
@@ -588,8 +597,9 @@ discard block |
||
588 | 597 | */ |
589 | 598 | protected function getWeekInMonth($date, $pattern = 'W') |
590 | 599 | { |
591 | - if($pattern != 'W') |
|
592 | - throw new Exception('The pattern for week in month is "W".'); |
|
600 | + if($pattern != 'W') { |
|
601 | + throw new Exception('The pattern for week in month is "W".'); |
|
602 | + } |
|
593 | 603 | |
594 | 604 | $firstInMonth = clone($date); |
595 | 605 | $firstInMonth->setDate($firstInMonth->format('Y'), $firstInMonth->format('m'), 1); |
@@ -604,8 +614,9 @@ discard block |
||
604 | 614 | */ |
605 | 615 | protected function getHourInDay($date, $pattern = 'k') |
606 | 616 | { |
607 | - if($pattern != 'k') |
|
608 | - throw new Exception('The pattern for hour in day is "k".'); |
|
617 | + if($pattern != 'k') { |
|
618 | + throw new Exception('The pattern for hour in day is "k".'); |
|
619 | + } |
|
609 | 620 | |
610 | 621 | return $date->format('G') + 1; |
611 | 622 | } |
@@ -618,8 +629,9 @@ discard block |
||
618 | 629 | */ |
619 | 630 | protected function getHourInAMPM($date, $pattern = 'K') |
620 | 631 | { |
621 | - if($pattern != 'K') |
|
622 | - throw new Exception('The pattern for hour in AM/PM is "K".'); |
|
632 | + if($pattern != 'K') { |
|
633 | + throw new Exception('The pattern for hour in AM/PM is "K".'); |
|
634 | + } |
|
623 | 635 | |
624 | 636 | return $date->format('g') + 1; |
625 | 637 | } |
@@ -22,12 +22,12 @@ discard block |
||
22 | 22 | */ |
23 | 23 | use Exception; |
24 | 24 | |
25 | -require_once(dirname(__FILE__) . '/IMessageSource.php'); |
|
25 | +require_once(dirname(__FILE__).'/IMessageSource.php'); |
|
26 | 26 | |
27 | 27 | /** |
28 | 28 | * Get the MessageCache class file. |
29 | 29 | */ |
30 | -require_once(dirname(__FILE__) . '/MessageCache.php'); |
|
30 | +require_once(dirname(__FILE__).'/MessageCache.php'); |
|
31 | 31 | |
32 | 32 | /** |
33 | 33 | * Abstract MessageSource class. |
@@ -126,18 +126,18 @@ discard block |
||
126 | 126 | */ |
127 | 127 | public static function &factory($type, $source = '.', $filename = '') |
128 | 128 | { |
129 | - $types = ['XLIFF','PHP','gettext','Database']; |
|
129 | + $types = ['XLIFF', 'PHP', 'gettext', 'Database']; |
|
130 | 130 | |
131 | - if(empty($filename) && !in_array($type, $types)) |
|
132 | - throw new Exception('Invalid type "' . $type . '", valid types are ' . |
|
131 | + if (empty($filename) && !in_array($type, $types)) |
|
132 | + throw new Exception('Invalid type "'.$type.'", valid types are '. |
|
133 | 133 | implode(', ', $types)); |
134 | 134 | |
135 | - $class = 'MessageSource_' . $type; |
|
135 | + $class = 'MessageSource_'.$type; |
|
136 | 136 | |
137 | - if(empty($filename)) |
|
138 | - $filename = dirname(__FILE__) . '/' . $class . '.php'; |
|
137 | + if (empty($filename)) |
|
138 | + $filename = dirname(__FILE__).'/'.$class.'.php'; |
|
139 | 139 | |
140 | - if(is_file($filename) == false) |
|
140 | + if (is_file($filename) == false) |
|
141 | 141 | throw new Exception("File $filename not found"); |
142 | 142 | |
143 | 143 | include_once $filename; |
@@ -172,33 +172,33 @@ discard block |
||
172 | 172 | |
173 | 173 | $this->messages = []; |
174 | 174 | |
175 | - foreach($variants as $variant) |
|
175 | + foreach ($variants as $variant) |
|
176 | 176 | { |
177 | 177 | $source = $this->getSource($variant); |
178 | 178 | |
179 | - if($this->isValidSource($source) == false) continue; |
|
179 | + if ($this->isValidSource($source) == false) continue; |
|
180 | 180 | |
181 | 181 | $loadData = true; |
182 | 182 | |
183 | - if($this->cache) |
|
183 | + if ($this->cache) |
|
184 | 184 | { |
185 | 185 | $data = $this->cache->get($variant, |
186 | 186 | $this->culture, $this->getLastModified($source)); |
187 | 187 | |
188 | - if(is_array($data)) |
|
188 | + if (is_array($data)) |
|
189 | 189 | { |
190 | 190 | $this->messages[$variant] = $data; |
191 | 191 | $loadData = false; |
192 | 192 | } |
193 | 193 | unset($data); |
194 | 194 | } |
195 | - if($loadData) |
|
195 | + if ($loadData) |
|
196 | 196 | { |
197 | 197 | $data = &$this->loadData($source); |
198 | - if(is_array($data)) |
|
198 | + if (is_array($data)) |
|
199 | 199 | { |
200 | 200 | $this->messages[$variant] = $data; |
201 | - if($this->cache) |
|
201 | + if ($this->cache) |
|
202 | 202 | $this->cache->save($data, $variant, $this->culture); |
203 | 203 | } |
204 | 204 | unset($data); |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | */ |
244 | 244 | public function append($message) |
245 | 245 | { |
246 | - if(!in_array($message, $this->untranslated)) |
|
246 | + if (!in_array($message, $this->untranslated)) |
|
247 | 247 | $this->untranslated[] = $message; |
248 | 248 | } |
249 | 249 |
@@ -128,17 +128,20 @@ discard block |
||
128 | 128 | { |
129 | 129 | $types = ['XLIFF','PHP','gettext','Database']; |
130 | 130 | |
131 | - if(empty($filename) && !in_array($type, $types)) |
|
132 | - throw new Exception('Invalid type "' . $type . '", valid types are ' . |
|
131 | + if(empty($filename) && !in_array($type, $types)) { |
|
132 | + throw new Exception('Invalid type "' . $type . '", valid types are ' . |
|
133 | 133 | implode(', ', $types)); |
134 | + } |
|
134 | 135 | |
135 | 136 | $class = 'MessageSource_' . $type; |
136 | 137 | |
137 | - if(empty($filename)) |
|
138 | - $filename = dirname(__FILE__) . '/' . $class . '.php'; |
|
138 | + if(empty($filename)) { |
|
139 | + $filename = dirname(__FILE__) . '/' . $class . '.php'; |
|
140 | + } |
|
139 | 141 | |
140 | - if(is_file($filename) == false) |
|
141 | - throw new Exception("File $filename not found"); |
|
142 | + if(is_file($filename) == false) { |
|
143 | + throw new Exception("File $filename not found"); |
|
144 | + } |
|
142 | 145 | |
143 | 146 | include_once $filename; |
144 | 147 | |
@@ -176,7 +179,9 @@ discard block |
||
176 | 179 | { |
177 | 180 | $source = $this->getSource($variant); |
178 | 181 | |
179 | - if($this->isValidSource($source) == false) continue; |
|
182 | + if($this->isValidSource($source) == false) { |
|
183 | + continue; |
|
184 | + } |
|
180 | 185 | |
181 | 186 | $loadData = true; |
182 | 187 | |
@@ -198,8 +203,9 @@ discard block |
||
198 | 203 | if(is_array($data)) |
199 | 204 | { |
200 | 205 | $this->messages[$variant] = $data; |
201 | - if($this->cache) |
|
202 | - $this->cache->save($data, $variant, $this->culture); |
|
206 | + if($this->cache) { |
|
207 | + $this->cache->save($data, $variant, $this->culture); |
|
208 | + } |
|
203 | 209 | } |
204 | 210 | unset($data); |
205 | 211 | } |
@@ -243,8 +249,9 @@ discard block |
||
243 | 249 | */ |
244 | 250 | public function append($message) |
245 | 251 | { |
246 | - if(!in_array($message, $this->untranslated)) |
|
247 | - $this->untranslated[] = $message; |
|
252 | + if(!in_array($message, $this->untranslated)) { |
|
253 | + $this->untranslated[] = $message; |
|
254 | + } |
|
248 | 255 | } |
249 | 256 | |
250 | 257 | /** |