@@ -165,6 +165,9 @@ |
||
165 | 165 | return false; |
166 | 166 | } |
167 | 167 | |
168 | + /** |
|
169 | + * @param string $set |
|
170 | + */ |
|
168 | 171 | protected function isValidSetNotation($number, $set) |
169 | 172 | { |
170 | 173 | $str = '$result = '.str_replace('n', '$number', $set).';'; |
@@ -114,27 +114,27 @@ discard block |
||
114 | 114 | */ |
115 | 115 | function isValid($number, $set) |
116 | 116 | { |
117 | - $n = preg_match_all($this->validate,$set,$matches,PREG_SET_ORDER); |
|
117 | + $n = preg_match_all($this->validate, $set, $matches, PREG_SET_ORDER); |
|
118 | 118 | |
119 | - if($n < 3) throw new Exception("Invalid set \"{$set}\""); |
|
119 | + if ($n < 3) throw new Exception("Invalid set \"{$set}\""); |
|
120 | 120 | |
121 | - if(preg_match('/\{\s*n:([^\}]+)\}/', $set, $def)) |
|
121 | + if (preg_match('/\{\s*n:([^\}]+)\}/', $set, $def)) |
|
122 | 122 | { |
123 | 123 | return $this->isValidSetNotation($number, $def[1]); |
124 | 124 | } |
125 | 125 | |
126 | 126 | $leftBracket = $matches[0][0]; |
127 | - $rightBracket = $matches[$n-1][0]; |
|
127 | + $rightBracket = $matches[$n - 1][0]; |
|
128 | 128 | |
129 | 129 | $i = 0; |
130 | 130 | $elements = array(); |
131 | - foreach($matches as $match) |
|
131 | + foreach ($matches as $match) |
|
132 | 132 | { |
133 | 133 | $string = $match[0]; |
134 | - if($i != 0 && $i != $n-1 && $string !== ',') |
|
134 | + if ($i != 0 && $i != $n - 1 && $string !== ',') |
|
135 | 135 | { |
136 | - if($string == '-Inf') |
|
137 | - $elements[] = -1*$this->inf; |
|
136 | + if ($string == '-Inf') |
|
137 | + $elements[] = -1 * $this->inf; |
|
138 | 138 | else if ($string == '+Inf' || $string == 'Inf') |
139 | 139 | $elements[] = $this->inf; |
140 | 140 | else |
@@ -145,35 +145,35 @@ discard block |
||
145 | 145 | $total = count($elements); |
146 | 146 | $number = floatval($number); |
147 | 147 | |
148 | - if($leftBracket == '{' && $rightBracket == '}') |
|
148 | + if ($leftBracket == '{' && $rightBracket == '}') |
|
149 | 149 | return in_array($number, $elements); |
150 | 150 | |
151 | 151 | $left = false; |
152 | - if($leftBracket == '[') |
|
152 | + if ($leftBracket == '[') |
|
153 | 153 | $left = $number >= $elements[0]; |
154 | 154 | else if ($leftBracket == '(') |
155 | 155 | $left = $number > $elements[0]; |
156 | 156 | |
157 | 157 | $right = false; |
158 | - if($rightBracket==']') |
|
159 | - $right = $number <= $elements[$total-1]; |
|
160 | - else if($rightBracket == ')') |
|
161 | - $right = $number < $elements[$total-1]; |
|
158 | + if ($rightBracket == ']') |
|
159 | + $right = $number <= $elements[$total - 1]; |
|
160 | + else if ($rightBracket == ')') |
|
161 | + $right = $number < $elements[$total - 1]; |
|
162 | 162 | |
163 | - if($left && $right) return true; |
|
163 | + if ($left && $right) return true; |
|
164 | 164 | |
165 | 165 | return false; |
166 | 166 | } |
167 | 167 | |
168 | 168 | protected function isValidSetNotation($number, $set) |
169 | 169 | { |
170 | - $str = '$result = '.str_replace('n', '$number', $set).';'; |
|
170 | + $str = '$result = ' . str_replace('n', '$number', $set) . ';'; |
|
171 | 171 | try |
172 | 172 | { |
173 | 173 | eval($str); |
174 | 174 | return $result; |
175 | 175 | } |
176 | - catch(Exception $e) |
|
176 | + catch (Exception $e) |
|
177 | 177 | { |
178 | 178 | return false; |
179 | 179 | } |
@@ -187,17 +187,17 @@ discard block |
||
187 | 187 | */ |
188 | 188 | function parse($string) |
189 | 189 | { |
190 | - $n = preg_match_all($this->parse,$string,$matches, PREG_OFFSET_CAPTURE); |
|
190 | + $n = preg_match_all($this->parse, $string, $matches, PREG_OFFSET_CAPTURE); |
|
191 | 191 | $sets = array(); |
192 | - foreach($matches[1] as $match) |
|
192 | + foreach ($matches[1] as $match) |
|
193 | 193 | $sets[] = $match[0]; |
194 | 194 | $offset = $matches[0]; |
195 | 195 | $strings = array(); |
196 | - for($i = 0; $i < $n; $i++) |
|
196 | + for ($i = 0; $i < $n; $i++) |
|
197 | 197 | { |
198 | 198 | $len = strlen($offset[$i][0]); |
199 | - $begin = $i == 0? $len : $offset[$i][1] + $len; |
|
200 | - $end = $i == $n-1 ? strlen($string) : $offset[$i+1][1]; |
|
199 | + $begin = $i == 0 ? $len : $offset[$i][1] + $len; |
|
200 | + $end = $i == $n - 1 ? strlen($string) : $offset[$i + 1][1]; |
|
201 | 201 | $strings[] = substr($string, $begin, $end - $begin); |
202 | 202 | } |
203 | 203 | return array($sets, $strings); |
@@ -214,9 +214,9 @@ discard block |
||
214 | 214 | { |
215 | 215 | list($sets, $strings) = $this->parse($string); |
216 | 216 | $total = count($sets); |
217 | - for($i = 0; $i < $total; $i++) |
|
217 | + for ($i = 0; $i < $total; $i++) |
|
218 | 218 | { |
219 | - if($this->isValid($number, $sets[$i])) |
|
219 | + if ($this->isValid($number, $sets[$i])) |
|
220 | 220 | return $strings[$i]; |
221 | 221 | } |
222 | 222 | return false; |
@@ -116,7 +116,9 @@ discard block |
||
116 | 116 | { |
117 | 117 | $n = preg_match_all($this->validate,$set,$matches,PREG_SET_ORDER); |
118 | 118 | |
119 | - if($n < 3) throw new Exception("Invalid set \"{$set}\""); |
|
119 | + if($n < 3) { |
|
120 | + throw new Exception("Invalid set \"{$set}\""); |
|
121 | + } |
|
120 | 122 | |
121 | 123 | if(preg_match('/\{\s*n:([^\}]+)\}/', $set, $def)) |
122 | 124 | { |
@@ -133,34 +135,40 @@ discard block |
||
133 | 135 | $string = $match[0]; |
134 | 136 | if($i != 0 && $i != $n-1 && $string !== ',') |
135 | 137 | { |
136 | - if($string == '-Inf') |
|
137 | - $elements[] = -1*$this->inf; |
|
138 | - else if ($string == '+Inf' || $string == 'Inf') |
|
139 | - $elements[] = $this->inf; |
|
140 | - else |
|
141 | - $elements[] = floatval($string); |
|
138 | + if($string == '-Inf') { |
|
139 | + $elements[] = -1*$this->inf; |
|
140 | + } else if ($string == '+Inf' || $string == 'Inf') { |
|
141 | + $elements[] = $this->inf; |
|
142 | + } else { |
|
143 | + $elements[] = floatval($string); |
|
144 | + } |
|
142 | 145 | } |
143 | 146 | $i++; |
144 | 147 | } |
145 | 148 | $total = count($elements); |
146 | 149 | $number = floatval($number); |
147 | 150 | |
148 | - if($leftBracket == '{' && $rightBracket == '}') |
|
149 | - return in_array($number, $elements); |
|
151 | + if($leftBracket == '{' && $rightBracket == '}') { |
|
152 | + return in_array($number, $elements); |
|
153 | + } |
|
150 | 154 | |
151 | 155 | $left = false; |
152 | - if($leftBracket == '[') |
|
153 | - $left = $number >= $elements[0]; |
|
154 | - else if ($leftBracket == '(') |
|
155 | - $left = $number > $elements[0]; |
|
156 | + if($leftBracket == '[') { |
|
157 | + $left = $number >= $elements[0]; |
|
158 | + } else if ($leftBracket == '(') { |
|
159 | + $left = $number > $elements[0]; |
|
160 | + } |
|
156 | 161 | |
157 | 162 | $right = false; |
158 | - if($rightBracket==']') |
|
159 | - $right = $number <= $elements[$total-1]; |
|
160 | - else if($rightBracket == ')') |
|
161 | - $right = $number < $elements[$total-1]; |
|
163 | + if($rightBracket==']') { |
|
164 | + $right = $number <= $elements[$total-1]; |
|
165 | + } else if($rightBracket == ')') { |
|
166 | + $right = $number < $elements[$total-1]; |
|
167 | + } |
|
162 | 168 | |
163 | - if($left && $right) return true; |
|
169 | + if($left && $right) { |
|
170 | + return true; |
|
171 | + } |
|
164 | 172 | |
165 | 173 | return false; |
166 | 174 | } |
@@ -172,8 +180,7 @@ discard block |
||
172 | 180 | { |
173 | 181 | eval($str); |
174 | 182 | return $result; |
175 | - } |
|
176 | - catch(Exception $e) |
|
183 | + } catch(Exception $e) |
|
177 | 184 | { |
178 | 185 | return false; |
179 | 186 | } |
@@ -189,8 +196,9 @@ discard block |
||
189 | 196 | { |
190 | 197 | $n = preg_match_all($this->parse,$string,$matches, PREG_OFFSET_CAPTURE); |
191 | 198 | $sets = array(); |
192 | - foreach($matches[1] as $match) |
|
193 | - $sets[] = $match[0]; |
|
199 | + foreach($matches[1] as $match) { |
|
200 | + $sets[] = $match[0]; |
|
201 | + } |
|
194 | 202 | $offset = $matches[0]; |
195 | 203 | $strings = array(); |
196 | 204 | for($i = 0; $i < $n; $i++) |
@@ -216,8 +224,9 @@ discard block |
||
216 | 224 | $total = count($sets); |
217 | 225 | for($i = 0; $i < $total; $i++) |
218 | 226 | { |
219 | - if($this->isValid($number, $sets[$i])) |
|
220 | - return $strings[$i]; |
|
227 | + if($this->isValid($number, $sets[$i])) { |
|
228 | + return $strings[$i]; |
|
229 | + } |
|
221 | 230 | } |
222 | 231 | return false; |
223 | 232 | } |
@@ -200,6 +200,7 @@ discard block |
||
200 | 200 | |
201 | 201 | /** |
202 | 202 | * Gets the CultureInfo that for this culture string |
203 | + * @param string $culture |
|
203 | 204 | * @return CultureInfo invariant culture info is "en". |
204 | 205 | */ |
205 | 206 | public static function getInstance($culture) |
@@ -228,6 +229,7 @@ discard block |
||
228 | 229 | * Set the culture for the current instance. The culture indentifier |
229 | 230 | * must be of the form "<language>_(country/region)". |
230 | 231 | * @param string culture identifier, e.g. "fr_FR_EURO". |
232 | + * @param string $culture |
|
231 | 233 | */ |
232 | 234 | protected function setCulture($culture) |
233 | 235 | { |
@@ -243,6 +245,7 @@ discard block |
||
243 | 245 | /** |
244 | 246 | * Load the ICU culture data for the specific culture identifier. |
245 | 247 | * @param string the culture identifier. |
248 | + * @param string $culture |
|
246 | 249 | */ |
247 | 250 | protected function loadCultureData($culture) |
248 | 251 | { |
@@ -283,6 +286,7 @@ discard block |
||
283 | 286 | * The data files are cached in a static variable inside |
284 | 287 | * this function. |
285 | 288 | * @param string the ICU data filename |
289 | + * @param string $filename |
|
286 | 290 | * @return array ICU data |
287 | 291 | */ |
288 | 292 | protected function &getData($filename) |
@@ -386,6 +390,7 @@ discard block |
||
386 | 390 | /** |
387 | 391 | * Set the date time format information. |
388 | 392 | * @param DateTimeFormatInfo the new date time format info. |
393 | + * @param DateTimeFormatInfo $dateTimeFormat |
|
389 | 394 | */ |
390 | 395 | function setDateTimeFormat($dateTimeFormat) |
391 | 396 | { |
@@ -493,6 +498,7 @@ discard block |
||
493 | 498 | /** |
494 | 499 | * Set the number format information. |
495 | 500 | * @param NumberFormatInfo the new number format info. |
501 | + * @param NumberFormatInfo $numberFormat |
|
496 | 502 | */ |
497 | 503 | function setNumberFormat($numberFormat) |
498 | 504 | { |
@@ -199,9 +199,9 @@ |
||
199 | 199 | } |
200 | 200 | |
201 | 201 | /** |
202 | - * Gets the CultureInfo that for this culture string |
|
203 | - * @return CultureInfo invariant culture info is "en". |
|
204 | - */ |
|
202 | + * Gets the CultureInfo that for this culture string |
|
203 | + * @return CultureInfo invariant culture info is "en". |
|
204 | + */ |
|
205 | 205 | public static function getInstance($culture) |
206 | 206 | { |
207 | 207 | static $instances = array(); |
@@ -134,11 +134,11 @@ discard block |
||
134 | 134 | */ |
135 | 135 | function __get($name) |
136 | 136 | { |
137 | - $getProperty = 'get'.$name; |
|
138 | - if(in_array($getProperty, $this->properties)) |
|
137 | + $getProperty = 'get' . $name; |
|
138 | + if (in_array($getProperty, $this->properties)) |
|
139 | 139 | return $this->$getProperty(); |
140 | 140 | else |
141 | - throw new Exception('Property '.$name.' does not exists.'); |
|
141 | + throw new Exception('Property ' . $name . ' does not exists.'); |
|
142 | 142 | } |
143 | 143 | |
144 | 144 | /** |
@@ -147,11 +147,11 @@ discard block |
||
147 | 147 | */ |
148 | 148 | function __set($name, $value) |
149 | 149 | { |
150 | - $setProperty = 'set'.$name; |
|
151 | - if(in_array($setProperty, $this->properties)) |
|
150 | + $setProperty = 'set' . $name; |
|
151 | + if (in_array($setProperty, $this->properties)) |
|
152 | 152 | $this->$setProperty($value); |
153 | 153 | else |
154 | - throw new Exception('Property '.$name.' can not be set.'); |
|
154 | + throw new Exception('Property ' . $name . ' can not be set.'); |
|
155 | 155 | } |
156 | 156 | |
157 | 157 | |
@@ -163,11 +163,11 @@ discard block |
||
163 | 163 | * @param string a culture name, e.g. "en_AU". |
164 | 164 | * @return return new CultureInfo. |
165 | 165 | */ |
166 | - function __construct($culture='en') |
|
166 | + function __construct($culture = 'en') |
|
167 | 167 | { |
168 | 168 | $this->properties = get_class_methods($this); |
169 | 169 | |
170 | - if(empty($culture)) |
|
170 | + if (empty($culture)) |
|
171 | 171 | $culture = 'en'; |
172 | 172 | |
173 | 173 | $this->dataDir = $this->dataDir(); |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | */ |
187 | 187 | protected static function dataDir() |
188 | 188 | { |
189 | - return dirname(__FILE__).'/data/'; |
|
189 | + return dirname(__FILE__) . '/data/'; |
|
190 | 190 | } |
191 | 191 | |
192 | 192 | /** |
@@ -205,7 +205,7 @@ discard block |
||
205 | 205 | public static function getInstance($culture) |
206 | 206 | { |
207 | 207 | static $instances = array(); |
208 | - if(!isset($instances[$culture])) |
|
208 | + if (!isset($instances[$culture])) |
|
209 | 209 | $instances[$culture] = new CultureInfo($culture); |
210 | 210 | return $instances[$culture]; |
211 | 211 | } |
@@ -218,8 +218,8 @@ discard block |
||
218 | 218 | */ |
219 | 219 | public static function validCulture($culture) |
220 | 220 | { |
221 | - if(preg_match('/^[_\\w]+$/', $culture)) |
|
222 | - return is_file(self::dataDir().$culture.self::fileExt()); |
|
221 | + if (preg_match('/^[_\\w]+$/', $culture)) |
|
222 | + return is_file(self::dataDir() . $culture . self::fileExt()); |
|
223 | 223 | |
224 | 224 | return false; |
225 | 225 | } |
@@ -231,7 +231,7 @@ discard block |
||
231 | 231 | */ |
232 | 232 | protected function setCulture($culture) |
233 | 233 | { |
234 | - if(!empty($culture)) |
|
234 | + if (!empty($culture)) |
|
235 | 235 | { |
236 | 236 | if (!preg_match('/^[_\\w]+$/', $culture)) |
237 | 237 | throw new Exception('Invalid culture supplied: ' . $culture); |
@@ -246,32 +246,32 @@ discard block |
||
246 | 246 | */ |
247 | 247 | protected function loadCultureData($culture) |
248 | 248 | { |
249 | - $file_parts = explode('_',$culture); |
|
249 | + $file_parts = explode('_', $culture); |
|
250 | 250 | $current_part = $file_parts[0]; |
251 | 251 | |
252 | 252 | $files = array($current_part); |
253 | 253 | |
254 | - for($i = 1, $k = count($file_parts); $i < $k; ++$i) |
|
254 | + for ($i = 1, $k = count($file_parts); $i < $k; ++$i) |
|
255 | 255 | { |
256 | - $current_part .= '_'.$file_parts[$i]; |
|
256 | + $current_part .= '_' . $file_parts[$i]; |
|
257 | 257 | $files[] = $current_part; |
258 | 258 | } |
259 | 259 | |
260 | - foreach($files as $file) |
|
260 | + foreach ($files as $file) |
|
261 | 261 | { |
262 | - $filename = $this->dataDir.$file.$this->dataFileExt; |
|
262 | + $filename = $this->dataDir . $file . $this->dataFileExt; |
|
263 | 263 | |
264 | - if(is_file($filename) == false) |
|
265 | - throw new Exception('Data file for "'.$file.'" was not found.'); |
|
264 | + if (is_file($filename) == false) |
|
265 | + throw new Exception('Data file for "' . $file . '" was not found.'); |
|
266 | 266 | |
267 | - if(in_array($filename, $this->dataFiles) === false) |
|
267 | + if (in_array($filename, $this->dataFiles) === false) |
|
268 | 268 | { |
269 | 269 | array_unshift($this->dataFiles, $file); |
270 | 270 | |
271 | 271 | $data = &$this->getData($filename); |
272 | 272 | $this->data[$file] = &$data; |
273 | 273 | |
274 | - if(isset($data['__ALIAS'])) |
|
274 | + if (isset($data['__ALIAS'])) |
|
275 | 275 | $this->loadCultureData($data['__ALIAS'][0]); |
276 | 276 | unset($data); |
277 | 277 | } |
@@ -290,7 +290,7 @@ discard block |
||
290 | 290 | static $data = array(); |
291 | 291 | static $files = array(); |
292 | 292 | |
293 | - if(!in_array($filename, $files)) |
|
293 | + if (!in_array($filename, $files)) |
|
294 | 294 | { |
295 | 295 | $data[$filename] = unserialize(file_get_contents($filename)); |
296 | 296 | $files[] = $filename; |
@@ -313,17 +313,17 @@ discard block |
||
313 | 313 | * @param boolean merge the data from its parents. |
314 | 314 | * @return mixed the specific ICU data. |
315 | 315 | */ |
316 | - protected function findInfo($path='/', $merge=false) |
|
316 | + protected function findInfo($path = '/', $merge = false) |
|
317 | 317 | { |
318 | 318 | $result = array(); |
319 | - foreach($this->dataFiles as $section) |
|
319 | + foreach ($this->dataFiles as $section) |
|
320 | 320 | { |
321 | 321 | $info = $this->searchArray($this->data[$section], $path); |
322 | 322 | |
323 | - if($info) |
|
323 | + if ($info) |
|
324 | 324 | { |
325 | - if($merge) |
|
326 | - $result = array_merge($info,$result); |
|
325 | + if ($merge) |
|
326 | + $result = array_merge($info, $result); |
|
327 | 327 | else |
328 | 328 | return $info; |
329 | 329 | } |
@@ -340,18 +340,18 @@ discard block |
||
340 | 340 | * @param string slash "/" separated array path. |
341 | 341 | * @return mixed the value array using the path |
342 | 342 | */ |
343 | - private function searchArray($info, $path='/') |
|
343 | + private function searchArray($info, $path = '/') |
|
344 | 344 | { |
345 | - $index = explode('/',$path); |
|
345 | + $index = explode('/', $path); |
|
346 | 346 | |
347 | 347 | $array = $info; |
348 | 348 | |
349 | - for($i = 0, $k = count($index); $i < $k; ++$i) |
|
349 | + for ($i = 0, $k = count($index); $i < $k; ++$i) |
|
350 | 350 | { |
351 | 351 | $value = $index[$i]; |
352 | - if($i < $k-1 && isset($array[$value])) |
|
352 | + if ($i < $k - 1 && isset($array[$value])) |
|
353 | 353 | $array = $array[$value]; |
354 | - else if ($i == $k-1 && isset($array[$value])) |
|
354 | + else if ($i == $k - 1 && isset($array[$value])) |
|
355 | 355 | return $array[$value]; |
356 | 356 | } |
357 | 357 | } |
@@ -373,7 +373,7 @@ discard block |
||
373 | 373 | */ |
374 | 374 | function getDateTimeFormat() |
375 | 375 | { |
376 | - if($this->dateTimeFormat === null) |
|
376 | + if ($this->dateTimeFormat === null) |
|
377 | 377 | { |
378 | 378 | $calendar = $this->getCalendar(); |
379 | 379 | $info = $this->findInfo("calendar/{$calendar}", true); |
@@ -410,12 +410,12 @@ discard block |
||
410 | 410 | */ |
411 | 411 | function getNativeName() |
412 | 412 | { |
413 | - $lang = substr($this->culture,0,2); |
|
414 | - $reg = substr($this->culture,3,2); |
|
413 | + $lang = substr($this->culture, 0, 2); |
|
414 | + $reg = substr($this->culture, 3, 2); |
|
415 | 415 | $language = $this->findInfo("Languages/{$lang}"); |
416 | 416 | $region = $this->findInfo("Countries/{$reg}"); |
417 | - if($region) |
|
418 | - return $language[0].' ('.$region[0].')'; |
|
417 | + if ($region) |
|
418 | + return $language[0] . ' (' . $region[0] . ')'; |
|
419 | 419 | else |
420 | 420 | return $language[0]; |
421 | 421 | } |
@@ -428,17 +428,17 @@ discard block |
||
428 | 428 | */ |
429 | 429 | function getEnglishName() |
430 | 430 | { |
431 | - $lang = substr($this->culture,0,2); |
|
432 | - $reg = substr($this->culture,3,2); |
|
431 | + $lang = substr($this->culture, 0, 2); |
|
432 | + $reg = substr($this->culture, 3, 2); |
|
433 | 433 | $culture = $this->getInvariantCulture(); |
434 | 434 | |
435 | 435 | $language = $culture->findInfo("Languages/{$lang}"); |
436 | - if(count($language) == 0) |
|
436 | + if (count($language) == 0) |
|
437 | 437 | return $this->culture; |
438 | 438 | |
439 | 439 | $region = $culture->findInfo("Countries/{$reg}"); |
440 | - if($region) |
|
441 | - return $language[0].' ('.$region[0].')'; |
|
440 | + if ($region) |
|
441 | + return $language[0] . ' (' . $region[0] . ')'; |
|
442 | 442 | else |
443 | 443 | return $language[0]; |
444 | 444 | } |
@@ -453,7 +453,7 @@ discard block |
||
453 | 453 | static function getInvariantCulture() |
454 | 454 | { |
455 | 455 | static $invariant; |
456 | - if($invariant === null) |
|
456 | + if ($invariant === null) |
|
457 | 457 | $invariant = new CultureInfo(); |
458 | 458 | return $invariant; |
459 | 459 | } |
@@ -476,12 +476,12 @@ discard block |
||
476 | 476 | */ |
477 | 477 | function getNumberFormat() |
478 | 478 | { |
479 | - if($this->numberFormat === null) |
|
479 | + if ($this->numberFormat === null) |
|
480 | 480 | { |
481 | 481 | $elements = $this->findInfo('NumberElements'); |
482 | 482 | $patterns = $this->findInfo('NumberPatterns'); |
483 | 483 | $currencies = $this->getCurrencies(); |
484 | - $data = array( 'NumberElements'=>$elements, |
|
484 | + $data = array('NumberElements'=>$elements, |
|
485 | 485 | 'NumberPatterns'=>$patterns, |
486 | 486 | 'Currencies' => $currencies); |
487 | 487 | |
@@ -506,10 +506,10 @@ discard block |
||
506 | 506 | */ |
507 | 507 | function getParent() |
508 | 508 | { |
509 | - if(strlen($this->culture) == 2) |
|
509 | + if (strlen($this->culture) == 2) |
|
510 | 510 | return $this->getInvariantCulture(); |
511 | 511 | |
512 | - $lang = substr($this->culture,0,2); |
|
512 | + $lang = substr($this->culture, 0, 2); |
|
513 | 513 | return new CultureInfo($lang); |
514 | 514 | } |
515 | 515 | |
@@ -522,7 +522,7 @@ discard block |
||
522 | 522 | * or CultureInfo::SPECIFIC. |
523 | 523 | * @return array list of culture information available. |
524 | 524 | */ |
525 | - static function getCultures($type=CultureInfo::ALL) |
|
525 | + static function getCultures($type = CultureInfo::ALL) |
|
526 | 526 | { |
527 | 527 | $dataDir = CultureInfo::dataDir(); |
528 | 528 | $dataExt = CultureInfo::fileExt(); |
@@ -533,12 +533,12 @@ discard block |
||
533 | 533 | |
534 | 534 | while (false !== ($entry = $dir->read())) |
535 | 535 | { |
536 | - if(is_file($dataDir.$entry) |
|
537 | - && substr($entry,-4) == $dataExt |
|
538 | - && $entry != 'root'.$dataExt) |
|
536 | + if (is_file($dataDir . $entry) |
|
537 | + && substr($entry, -4) == $dataExt |
|
538 | + && $entry != 'root' . $dataExt) |
|
539 | 539 | { |
540 | - $culture = substr($entry,0,-4); |
|
541 | - if(strlen($culture) == 2) |
|
540 | + $culture = substr($entry, 0, -4); |
|
541 | + if (strlen($culture) == 2) |
|
542 | 542 | $neutral[] = $culture; |
543 | 543 | else |
544 | 544 | $specific[] = $culture; |
@@ -546,10 +546,10 @@ discard block |
||
546 | 546 | } |
547 | 547 | $dir->close(); |
548 | 548 | |
549 | - switch($type) |
|
549 | + switch ($type) |
|
550 | 550 | { |
551 | 551 | case CultureInfo::ALL : |
552 | - $all = array_merge($neutral, $specific); |
|
552 | + $all = array_merge($neutral, $specific); |
|
553 | 553 | sort($all); |
554 | 554 | return $all; |
555 | 555 | break; |
@@ -571,10 +571,10 @@ discard block |
||
571 | 571 | */ |
572 | 572 | private function simplify($array) |
573 | 573 | { |
574 | - for($i = 0, $k = count($array); $i<$k; ++$i) |
|
574 | + for ($i = 0, $k = count($array); $i < $k; ++$i) |
|
575 | 575 | { |
576 | 576 | $key = key($array); |
577 | - if(is_array($array[$key]) |
|
577 | + if (is_array($array[$key]) |
|
578 | 578 | && count($array[$key]) == 1) |
579 | 579 | $array[$key] = $array[$key][0]; |
580 | 580 | next($array); |
@@ -588,7 +588,7 @@ discard block |
||
588 | 588 | */ |
589 | 589 | function getCountries() |
590 | 590 | { |
591 | - return $this->simplify($this->findInfo('Countries',true)); |
|
591 | + return $this->simplify($this->findInfo('Countries', true)); |
|
592 | 592 | } |
593 | 593 | |
594 | 594 | /** |
@@ -597,7 +597,7 @@ discard block |
||
597 | 597 | */ |
598 | 598 | function getCurrencies() |
599 | 599 | { |
600 | - return $this->findInfo('Currencies',true); |
|
600 | + return $this->findInfo('Currencies', true); |
|
601 | 601 | } |
602 | 602 | |
603 | 603 | /** |
@@ -606,7 +606,7 @@ discard block |
||
606 | 606 | */ |
607 | 607 | function getLanguages() |
608 | 608 | { |
609 | - return $this->simplify($this->findInfo('Languages',true)); |
|
609 | + return $this->simplify($this->findInfo('Languages', true)); |
|
610 | 610 | } |
611 | 611 | |
612 | 612 | /** |
@@ -615,7 +615,7 @@ discard block |
||
615 | 615 | */ |
616 | 616 | function getScripts() |
617 | 617 | { |
618 | - return $this->simplify($this->findInfo('Scripts',true)); |
|
618 | + return $this->simplify($this->findInfo('Scripts', true)); |
|
619 | 619 | } |
620 | 620 | |
621 | 621 | /** |
@@ -624,7 +624,7 @@ discard block |
||
624 | 624 | */ |
625 | 625 | function getTimeZones() |
626 | 626 | { |
627 | - return $this->simplify($this->findInfo('zoneStrings',true)); |
|
627 | + return $this->simplify($this->findInfo('zoneStrings', true)); |
|
628 | 628 | } |
629 | 629 | } |
630 | 630 |
@@ -135,10 +135,11 @@ discard block |
||
135 | 135 | function __get($name) |
136 | 136 | { |
137 | 137 | $getProperty = 'get'.$name; |
138 | - if(in_array($getProperty, $this->properties)) |
|
139 | - return $this->$getProperty(); |
|
140 | - else |
|
141 | - throw new Exception('Property '.$name.' does not exists.'); |
|
138 | + if(in_array($getProperty, $this->properties)) { |
|
139 | + return $this->$getProperty(); |
|
140 | + } else { |
|
141 | + throw new Exception('Property '.$name.' does not exists.'); |
|
142 | + } |
|
142 | 143 | } |
143 | 144 | |
144 | 145 | /** |
@@ -148,10 +149,11 @@ discard block |
||
148 | 149 | function __set($name, $value) |
149 | 150 | { |
150 | 151 | $setProperty = 'set'.$name; |
151 | - if(in_array($setProperty, $this->properties)) |
|
152 | - $this->$setProperty($value); |
|
153 | - else |
|
154 | - throw new Exception('Property '.$name.' can not be set.'); |
|
152 | + if(in_array($setProperty, $this->properties)) { |
|
153 | + $this->$setProperty($value); |
|
154 | + } else { |
|
155 | + throw new Exception('Property '.$name.' can not be set.'); |
|
156 | + } |
|
155 | 157 | } |
156 | 158 | |
157 | 159 | |
@@ -167,8 +169,9 @@ discard block |
||
167 | 169 | { |
168 | 170 | $this->properties = get_class_methods($this); |
169 | 171 | |
170 | - if(empty($culture)) |
|
171 | - $culture = 'en'; |
|
172 | + if(empty($culture)) { |
|
173 | + $culture = 'en'; |
|
174 | + } |
|
172 | 175 | |
173 | 176 | $this->dataDir = $this->dataDir(); |
174 | 177 | $this->dataFileExt = $this->fileExt(); |
@@ -205,8 +208,9 @@ discard block |
||
205 | 208 | public static function getInstance($culture) |
206 | 209 | { |
207 | 210 | static $instances = array(); |
208 | - if(!isset($instances[$culture])) |
|
209 | - $instances[$culture] = new CultureInfo($culture); |
|
211 | + if(!isset($instances[$culture])) { |
|
212 | + $instances[$culture] = new CultureInfo($culture); |
|
213 | + } |
|
210 | 214 | return $instances[$culture]; |
211 | 215 | } |
212 | 216 | |
@@ -218,8 +222,9 @@ discard block |
||
218 | 222 | */ |
219 | 223 | public static function validCulture($culture) |
220 | 224 | { |
221 | - if(preg_match('/^[_\\w]+$/', $culture)) |
|
222 | - return is_file(self::dataDir().$culture.self::fileExt()); |
|
225 | + if(preg_match('/^[_\\w]+$/', $culture)) { |
|
226 | + return is_file(self::dataDir().$culture.self::fileExt()); |
|
227 | + } |
|
223 | 228 | |
224 | 229 | return false; |
225 | 230 | } |
@@ -233,8 +238,9 @@ discard block |
||
233 | 238 | { |
234 | 239 | if(!empty($culture)) |
235 | 240 | { |
236 | - if (!preg_match('/^[_\\w]+$/', $culture)) |
|
237 | - throw new Exception('Invalid culture supplied: ' . $culture); |
|
241 | + if (!preg_match('/^[_\\w]+$/', $culture)) { |
|
242 | + throw new Exception('Invalid culture supplied: ' . $culture); |
|
243 | + } |
|
238 | 244 | } |
239 | 245 | |
240 | 246 | $this->culture = $culture; |
@@ -261,8 +267,9 @@ discard block |
||
261 | 267 | { |
262 | 268 | $filename = $this->dataDir.$file.$this->dataFileExt; |
263 | 269 | |
264 | - if(is_file($filename) == false) |
|
265 | - throw new Exception('Data file for "'.$file.'" was not found.'); |
|
270 | + if(is_file($filename) == false) { |
|
271 | + throw new Exception('Data file for "'.$file.'" was not found.'); |
|
272 | + } |
|
266 | 273 | |
267 | 274 | if(in_array($filename, $this->dataFiles) === false) |
268 | 275 | { |
@@ -271,8 +278,9 @@ discard block |
||
271 | 278 | $data = &$this->getData($filename); |
272 | 279 | $this->data[$file] = &$data; |
273 | 280 | |
274 | - if(isset($data['__ALIAS'])) |
|
275 | - $this->loadCultureData($data['__ALIAS'][0]); |
|
281 | + if(isset($data['__ALIAS'])) { |
|
282 | + $this->loadCultureData($data['__ALIAS'][0]); |
|
283 | + } |
|
276 | 284 | unset($data); |
277 | 285 | } |
278 | 286 | } |
@@ -322,10 +330,11 @@ discard block |
||
322 | 330 | |
323 | 331 | if($info) |
324 | 332 | { |
325 | - if($merge) |
|
326 | - $result = array_merge($info,$result); |
|
327 | - else |
|
328 | - return $info; |
|
333 | + if($merge) { |
|
334 | + $result = array_merge($info,$result); |
|
335 | + } else { |
|
336 | + return $info; |
|
337 | + } |
|
329 | 338 | } |
330 | 339 | } |
331 | 340 | |
@@ -349,10 +358,11 @@ discard block |
||
349 | 358 | for($i = 0, $k = count($index); $i < $k; ++$i) |
350 | 359 | { |
351 | 360 | $value = $index[$i]; |
352 | - if($i < $k-1 && isset($array[$value])) |
|
353 | - $array = $array[$value]; |
|
354 | - else if ($i == $k-1 && isset($array[$value])) |
|
355 | - return $array[$value]; |
|
361 | + if($i < $k-1 && isset($array[$value])) { |
|
362 | + $array = $array[$value]; |
|
363 | + } else if ($i == $k-1 && isset($array[$value])) { |
|
364 | + return $array[$value]; |
|
365 | + } |
|
356 | 366 | } |
357 | 367 | } |
358 | 368 | |
@@ -414,10 +424,11 @@ discard block |
||
414 | 424 | $reg = substr($this->culture,3,2); |
415 | 425 | $language = $this->findInfo("Languages/{$lang}"); |
416 | 426 | $region = $this->findInfo("Countries/{$reg}"); |
417 | - if($region) |
|
418 | - return $language[0].' ('.$region[0].')'; |
|
419 | - else |
|
420 | - return $language[0]; |
|
427 | + if($region) { |
|
428 | + return $language[0].' ('.$region[0].')'; |
|
429 | + } else { |
|
430 | + return $language[0]; |
|
431 | + } |
|
421 | 432 | } |
422 | 433 | |
423 | 434 | /** |
@@ -433,14 +444,16 @@ discard block |
||
433 | 444 | $culture = $this->getInvariantCulture(); |
434 | 445 | |
435 | 446 | $language = $culture->findInfo("Languages/{$lang}"); |
436 | - if(count($language) == 0) |
|
437 | - return $this->culture; |
|
447 | + if(count($language) == 0) { |
|
448 | + return $this->culture; |
|
449 | + } |
|
438 | 450 | |
439 | 451 | $region = $culture->findInfo("Countries/{$reg}"); |
440 | - if($region) |
|
441 | - return $language[0].' ('.$region[0].')'; |
|
442 | - else |
|
443 | - return $language[0]; |
|
452 | + if($region) { |
|
453 | + return $language[0].' ('.$region[0].')'; |
|
454 | + } else { |
|
455 | + return $language[0]; |
|
456 | + } |
|
444 | 457 | } |
445 | 458 | |
446 | 459 | /** |
@@ -453,8 +466,9 @@ discard block |
||
453 | 466 | static function getInvariantCulture() |
454 | 467 | { |
455 | 468 | static $invariant; |
456 | - if($invariant === null) |
|
457 | - $invariant = new CultureInfo(); |
|
469 | + if($invariant === null) { |
|
470 | + $invariant = new CultureInfo(); |
|
471 | + } |
|
458 | 472 | return $invariant; |
459 | 473 | } |
460 | 474 | |
@@ -506,8 +520,9 @@ discard block |
||
506 | 520 | */ |
507 | 521 | function getParent() |
508 | 522 | { |
509 | - if(strlen($this->culture) == 2) |
|
510 | - return $this->getInvariantCulture(); |
|
523 | + if(strlen($this->culture) == 2) { |
|
524 | + return $this->getInvariantCulture(); |
|
525 | + } |
|
511 | 526 | |
512 | 527 | $lang = substr($this->culture,0,2); |
513 | 528 | return new CultureInfo($lang); |
@@ -538,10 +553,11 @@ discard block |
||
538 | 553 | && $entry != 'root'.$dataExt) |
539 | 554 | { |
540 | 555 | $culture = substr($entry,0,-4); |
541 | - if(strlen($culture) == 2) |
|
542 | - $neutral[] = $culture; |
|
543 | - else |
|
544 | - $specific[] = $culture; |
|
556 | + if(strlen($culture) == 2) { |
|
557 | + $neutral[] = $culture; |
|
558 | + } else { |
|
559 | + $specific[] = $culture; |
|
560 | + } |
|
545 | 561 | } |
546 | 562 | } |
547 | 563 | $dir->close(); |
@@ -575,8 +591,9 @@ discard block |
||
575 | 591 | { |
576 | 592 | $key = key($array); |
577 | 593 | if(is_array($array[$key]) |
578 | - && count($array[$key]) == 1) |
|
579 | - $array[$key] = $array[$key][0]; |
|
594 | + && count($array[$key]) == 1) { |
|
595 | + $array[$key] = $array[$key][0]; |
|
596 | + } |
|
580 | 597 | next($array); |
581 | 598 | } |
582 | 599 | return $array; |
@@ -87,6 +87,7 @@ discard block |
||
87 | 87 | * Initialize a new DateFormat. |
88 | 88 | * @param mixed either, null, a CultureInfo instance, |
89 | 89 | * a DateTimeFormatInfo instance, or a locale. |
90 | + * @param string $formatInfo |
|
90 | 91 | * @return DateFormat instance |
91 | 92 | */ |
92 | 93 | function __construct($formatInfo=null) |
@@ -179,6 +180,7 @@ discard block |
||
179 | 180 | * DateTimeFormatInfo::formatDateTime |
180 | 181 | * See the tutorial documentation for futher details on the patterns. |
181 | 182 | * @param mixed a pattern. |
183 | + * @param string $pattern |
|
182 | 184 | * @return string a pattern. |
183 | 185 | * @see DateTimeFormatInfo::formatDateTime() |
184 | 186 | */ |
@@ -269,6 +271,7 @@ discard block |
||
269 | 271 | * Any substrings, starting and ending with a single quote (') |
270 | 272 | * will be treated as a single token. |
271 | 273 | * @param string pattern. |
274 | + * @param string $pattern |
|
272 | 275 | * @return array string tokens in an array. |
273 | 276 | */ |
274 | 277 | protected function getTokens($pattern) |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | |
80 | 80 | /** |
81 | 81 | * The DateTimeFormatInfo, containing culture specific patterns and names. |
82 | - * @var DateTimeFormatInfo |
|
82 | + * @var DateTimeFormatInfo |
|
83 | 83 | */ |
84 | 84 | protected $formatInfo; |
85 | 85 | |
@@ -308,8 +308,8 @@ discard block |
||
308 | 308 | |
309 | 309 | /** |
310 | 310 | * Get the year. |
311 | - * "yy" will return the last two digits of year. |
|
312 | - * "yyyy" will return the full integer year. |
|
311 | + * "yy" will return the last two digits of year. |
|
312 | + * "yyyy" will return the full integer year. |
|
313 | 313 | * @param array getdate format. |
314 | 314 | * @param string a pattern. |
315 | 315 | * @return string year |
@@ -330,10 +330,10 @@ discard block |
||
330 | 330 | |
331 | 331 | /** |
332 | 332 | * Get the month. |
333 | - * "M" will return integer 1 through 12 |
|
334 | - * "MM" will return the narrow month name, e.g. "J" |
|
335 | - * "MMM" will return the abrreviated month name, e.g. "Jan" |
|
336 | - * "MMMM" will return the month name, e.g. "January" |
|
333 | + * "M" will return integer 1 through 12 |
|
334 | + * "MM" will return the narrow month name, e.g. "J" |
|
335 | + * "MMM" will return the abrreviated month name, e.g. "Jan" |
|
336 | + * "MMMM" will return the month name, e.g. "January" |
|
337 | 337 | * @param array getdate format. |
338 | 338 | * @param string a pattern. |
339 | 339 | * @return string month name |
@@ -361,10 +361,10 @@ discard block |
||
361 | 361 | |
362 | 362 | /** |
363 | 363 | * Get the day of the week. |
364 | - * "E" will return integer 0 (for Sunday) through 6 (for Saturday). |
|
365 | - * "EE" will return the narrow day of the week, e.g. "M" |
|
366 | - * "EEE" will return the abrreviated day of the week, e.g. "Mon" |
|
367 | - * "EEEE" will return the day of the week, e.g. "Monday" |
|
364 | + * "E" will return integer 0 (for Sunday) through 6 (for Saturday). |
|
365 | + * "EE" will return the narrow day of the week, e.g. "M" |
|
366 | + * "EEE" will return the abrreviated day of the week, e.g. "Mon" |
|
367 | + * "EEEE" will return the day of the week, e.g. "Monday" |
|
368 | 368 | * @param array getdate format. |
369 | 369 | * @param string a pattern. |
370 | 370 | * @return string day of the week. |
@@ -394,7 +394,7 @@ discard block |
||
394 | 394 | |
395 | 395 | /** |
396 | 396 | * Get the day of the month. |
397 | - * "d" for non-padding, "dd" will always return 2 characters. |
|
397 | + * "d" for non-padding, "dd" will always return 2 characters. |
|
398 | 398 | * @param array getdate format. |
399 | 399 | * @param string a pattern. |
400 | 400 | * @return string day of the month |
@@ -581,14 +581,14 @@ discard block |
||
581 | 581 | protected function getDayInMonth($date, $pattern='FF') |
582 | 582 | { |
583 | 583 | switch ($pattern) { |
584 | - case 'F': |
|
585 | - return @date('j', @mktime(0, 0, 0, $date['mon'], $date['mday'], $date['year'])); |
|
586 | - break; |
|
587 | - case 'FF': |
|
588 | - return @date('d', @mktime(0, 0, 0, $date['mon'], $date['mday'], $date['year'])); |
|
589 | - break; |
|
590 | - default: |
|
591 | - throw new Exception('The pattern for day in month is "F" or "FF".'); |
|
584 | + case 'F': |
|
585 | + return @date('j', @mktime(0, 0, 0, $date['mon'], $date['mday'], $date['year'])); |
|
586 | + break; |
|
587 | + case 'FF': |
|
588 | + return @date('d', @mktime(0, 0, 0, $date['mon'], $date['mday'], $date['year'])); |
|
589 | + break; |
|
590 | + default: |
|
591 | + throw new Exception('The pattern for day in month is "F" or "FF".'); |
|
592 | 592 | } |
593 | 593 | } |
594 | 594 |
@@ -19,12 +19,12 @@ discard block |
||
19 | 19 | /** |
20 | 20 | * Get the DateTimeFormatInfo class. |
21 | 21 | */ |
22 | -require_once(dirname(__FILE__).'/DateTimeFormatInfo.php'); |
|
22 | +require_once(dirname(__FILE__) . '/DateTimeFormatInfo.php'); |
|
23 | 23 | |
24 | 24 | /** |
25 | 25 | * Get the encoding utilities |
26 | 26 | */ |
27 | -require_once(dirname(__FILE__).'/util.php'); |
|
27 | +require_once(dirname(__FILE__) . '/util.php'); |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * DateFormat class. |
@@ -89,13 +89,13 @@ discard block |
||
89 | 89 | * a DateTimeFormatInfo instance, or a locale. |
90 | 90 | * @return DateFormat instance |
91 | 91 | */ |
92 | - function __construct($formatInfo=null) |
|
92 | + function __construct($formatInfo = null) |
|
93 | 93 | { |
94 | - if($formatInfo === null) |
|
94 | + if ($formatInfo === null) |
|
95 | 95 | $this->formatInfo = DateTimeFormatInfo::getInvariantInfo(); |
96 | - else if($formatInfo instanceof CultureInfo) |
|
96 | + else if ($formatInfo instanceof CultureInfo) |
|
97 | 97 | $this->formatInfo = $formatInfo->DateTimeFormat; |
98 | - else if($formatInfo instanceof DateTimeFormatInfo) |
|
98 | + else if ($formatInfo instanceof DateTimeFormatInfo) |
|
99 | 99 | $this->formatInfo = $formatInfo; |
100 | 100 | else |
101 | 101 | $this->formatInfo = DateTimeFormatInfo::getInstance($formatInfo); |
@@ -108,14 +108,14 @@ discard block |
||
108 | 108 | * @param mixed the time as integer or string in strtotime format. |
109 | 109 | * @return string formatted date time. |
110 | 110 | */ |
111 | - public function format($time, $pattern='F', $charset='UTF-8') |
|
111 | + public function format($time, $pattern = 'F', $charset = 'UTF-8') |
|
112 | 112 | { |
113 | 113 | if (is_numeric($time)) //assumes unix epoch |
114 | 114 | $time = floatval($time); |
115 | - else if(is_string($time)) |
|
115 | + else if (is_string($time)) |
|
116 | 116 | $time = @strtotime($time); |
117 | 117 | |
118 | - if($pattern === null) |
|
118 | + if ($pattern === null) |
|
119 | 119 | $pattern = 'F'; |
120 | 120 | |
121 | 121 | $s = Prado::createComponent('System.Util.TDateTimeStamp'); |
@@ -126,38 +126,38 @@ discard block |
||
126 | 126 | |
127 | 127 | $tokens = $this->getTokens($pattern); |
128 | 128 | |
129 | - for($i = 0, $k = count($tokens); $i<$k; ++$i) |
|
129 | + for ($i = 0, $k = count($tokens); $i < $k; ++$i) |
|
130 | 130 | { |
131 | 131 | $pattern = $tokens[$i]; |
132 | - if($pattern{0} == "'" |
|
133 | - && $pattern{strlen($pattern)-1} == "'") |
|
132 | + if ($pattern{0} == "'" |
|
133 | + && $pattern{strlen($pattern) - 1} == "'") |
|
134 | 134 | { |
135 | - $sub = preg_replace('/(^\')|(\'$)/','',$pattern); |
|
136 | - $tokens[$i] = str_replace('``````','\'',$sub); |
|
135 | + $sub = preg_replace('/(^\')|(\'$)/', '', $pattern); |
|
136 | + $tokens[$i] = str_replace('``````', '\'', $sub); |
|
137 | 137 | } |
138 | - else if($pattern == '``````') |
|
138 | + else if ($pattern == '``````') |
|
139 | 139 | { |
140 | 140 | $tokens[$i] = '\''; |
141 | 141 | } |
142 | 142 | else |
143 | 143 | { |
144 | 144 | $function = $this->getFunctionName($pattern); |
145 | - if($function != null) |
|
145 | + if ($function != null) |
|
146 | 146 | { |
147 | - $fName = 'get'.$function; |
|
148 | - if(in_array($fName, $this->methods)) |
|
147 | + $fName = 'get' . $function; |
|
148 | + if (in_array($fName, $this->methods)) |
|
149 | 149 | { |
150 | 150 | $rs = $this->$fName($date, $pattern); |
151 | 151 | $tokens[$i] = $rs; |
152 | 152 | } |
153 | 153 | else |
154 | 154 | throw new |
155 | - Exception('function '.$function.' not found.'); |
|
155 | + Exception('function ' . $function . ' not found.'); |
|
156 | 156 | } |
157 | 157 | } |
158 | 158 | } |
159 | 159 | |
160 | - return I18N_toEncoding(implode('',$tokens), $charset); |
|
160 | + return I18N_toEncoding(implode('', $tokens), $charset); |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | /** |
@@ -167,7 +167,7 @@ discard block |
||
167 | 167 | */ |
168 | 168 | protected function getFunctionName($token) |
169 | 169 | { |
170 | - if(isset($this->tokens[$token{0}])) |
|
170 | + if (isset($this->tokens[$token{0}])) |
|
171 | 171 | return $this->tokens[$token{0}]; |
172 | 172 | } |
173 | 173 | |
@@ -184,14 +184,14 @@ discard block |
||
184 | 184 | */ |
185 | 185 | protected function getPattern($pattern) |
186 | 186 | { |
187 | - if(is_array($pattern) && count($pattern) == 2) |
|
187 | + if (is_array($pattern) && count($pattern) == 2) |
|
188 | 188 | { |
189 | 189 | return $this->formatInfo->formatDateTime( |
190 | 190 | $this->getPattern($pattern[0]), |
191 | 191 | $this->getPattern($pattern[1])); |
192 | 192 | } |
193 | 193 | |
194 | - switch($pattern) |
|
194 | + switch ($pattern) |
|
195 | 195 | { |
196 | 196 | case 'd': |
197 | 197 | return $this->formatInfo->ShortDatePattern; |
@@ -280,23 +280,23 @@ discard block |
||
280 | 280 | $text = false; |
281 | 281 | $pattern = preg_replace("/''/", '``````', $pattern); |
282 | 282 | |
283 | - for($i = 0; $i < strlen($pattern); $i++) |
|
283 | + for ($i = 0; $i < strlen($pattern); $i++) |
|
284 | 284 | { |
285 | - if($char==null || $pattern{$i} == $char || $text) |
|
285 | + if ($char == null || $pattern{$i} == $char || $text) |
|
286 | 286 | { |
287 | 287 | $token .= $pattern{$i}; |
288 | 288 | } |
289 | 289 | else |
290 | 290 | { |
291 | - $tokens[] = str_replace("","'",$token); |
|
291 | + $tokens[] = str_replace("", "'", $token); |
|
292 | 292 | $token = $pattern{$i}; |
293 | 293 | } |
294 | 294 | |
295 | - if($pattern{$i} == "'" && $text == false) |
|
295 | + if ($pattern{$i} == "'" && $text == false) |
|
296 | 296 | $text = true; |
297 | - else if($text && $pattern{$i} == "'" && $char == "'") |
|
297 | + else if ($text && $pattern{$i} == "'" && $char == "'") |
|
298 | 298 | $text = true; |
299 | - else if($text && $char != "'" && $pattern{$i} == "'") |
|
299 | + else if ($text && $char != "'" && $pattern{$i} == "'") |
|
300 | 300 | $text = false; |
301 | 301 | |
302 | 302 | $char = $pattern{$i}; |
@@ -314,13 +314,13 @@ discard block |
||
314 | 314 | * @param string a pattern. |
315 | 315 | * @return string year |
316 | 316 | */ |
317 | - protected function getYear($date, $pattern='yyyy') |
|
317 | + protected function getYear($date, $pattern = 'yyyy') |
|
318 | 318 | { |
319 | 319 | $year = $date['year']; |
320 | - switch($pattern) |
|
320 | + switch ($pattern) |
|
321 | 321 | { |
322 | 322 | case 'yy': |
323 | - return substr($year,2); |
|
323 | + return substr($year, 2); |
|
324 | 324 | case 'yyyy': |
325 | 325 | return $year; |
326 | 326 | default: |
@@ -338,23 +338,23 @@ discard block |
||
338 | 338 | * @param string a pattern. |
339 | 339 | * @return string month name |
340 | 340 | */ |
341 | - protected function getMonth($date, $pattern='M') |
|
341 | + protected function getMonth($date, $pattern = 'M') |
|
342 | 342 | { |
343 | 343 | $month = $date['mon']; |
344 | 344 | |
345 | - switch($pattern) |
|
345 | + switch ($pattern) |
|
346 | 346 | { |
347 | 347 | case 'M': |
348 | 348 | return $month; |
349 | 349 | case 'MM': |
350 | - return str_pad($month, 2,'0',STR_PAD_LEFT); |
|
350 | + return str_pad($month, 2, '0', STR_PAD_LEFT); |
|
351 | 351 | case 'MMM': |
352 | - return $this->formatInfo->AbbreviatedMonthNames[$month-1]; |
|
352 | + return $this->formatInfo->AbbreviatedMonthNames[$month - 1]; |
|
353 | 353 | break; |
354 | 354 | case 'MMMM': |
355 | - return $this->formatInfo->MonthNames[$month-1]; |
|
355 | + return $this->formatInfo->MonthNames[$month - 1]; |
|
356 | 356 | default: |
357 | - throw new Exception('The pattern for month '. |
|
357 | + throw new Exception('The pattern for month ' . |
|
358 | 358 | 'is "M", "MM", "MMM", or "MMMM".'); |
359 | 359 | } |
360 | 360 | } |
@@ -369,11 +369,11 @@ discard block |
||
369 | 369 | * @param string a pattern. |
370 | 370 | * @return string day of the week. |
371 | 371 | */ |
372 | - protected function getDayInWeek($date, $pattern='EEEE') |
|
372 | + protected function getDayInWeek($date, $pattern = 'EEEE') |
|
373 | 373 | { |
374 | 374 | $day = $date['wday']; |
375 | 375 | |
376 | - switch($pattern) |
|
376 | + switch ($pattern) |
|
377 | 377 | { |
378 | 378 | case 'E': |
379 | 379 | return $day; |
@@ -387,7 +387,7 @@ discard block |
||
387 | 387 | return $this->formatInfo->DayNames[$day]; |
388 | 388 | break; |
389 | 389 | default: |
390 | - throw new Exception('The pattern for day of the week '. |
|
390 | + throw new Exception('The pattern for day of the week ' . |
|
391 | 391 | 'is "E", "EE", "EEE", or "EEEE".'); |
392 | 392 | } |
393 | 393 | } |
@@ -399,18 +399,18 @@ discard block |
||
399 | 399 | * @param string a pattern. |
400 | 400 | * @return string day of the month |
401 | 401 | */ |
402 | - protected function getDay($date, $pattern='d') |
|
402 | + protected function getDay($date, $pattern = 'd') |
|
403 | 403 | { |
404 | 404 | $day = $date['mday']; |
405 | 405 | |
406 | - switch($pattern) |
|
406 | + switch ($pattern) |
|
407 | 407 | { |
408 | 408 | case 'd': |
409 | 409 | return $day; |
410 | 410 | case 'dd': |
411 | - return str_pad($day, 2,'0',STR_PAD_LEFT); |
|
411 | + return str_pad($day, 2, '0', STR_PAD_LEFT); |
|
412 | 412 | default: |
413 | - throw new Exception('The pattern for day of '. |
|
413 | + throw new Exception('The pattern for day of ' . |
|
414 | 414 | 'the month is "d" or "dd".'); |
415 | 415 | } |
416 | 416 | } |
@@ -423,14 +423,14 @@ discard block |
||
423 | 423 | * @param string a pattern. |
424 | 424 | * @return string era |
425 | 425 | */ |
426 | - protected function getEra($date, $pattern='G') |
|
426 | + protected function getEra($date, $pattern = 'G') |
|
427 | 427 | { |
428 | 428 | |
429 | - if($pattern != 'G') |
|
429 | + if ($pattern != 'G') |
|
430 | 430 | throw new Exception('The pattern for era is "G".'); |
431 | 431 | |
432 | 432 | $year = $date['year']; |
433 | - if($year > 0) |
|
433 | + if ($year > 0) |
|
434 | 434 | return $this->formatInfo->getEra(1); |
435 | 435 | else |
436 | 436 | return $this->formatInfo->getEra(0); |
@@ -443,18 +443,18 @@ discard block |
||
443 | 443 | * @param string a pattern. |
444 | 444 | * @return string hours in 24 hour format. |
445 | 445 | */ |
446 | - protected function getHour24($date, $pattern='H') |
|
446 | + protected function getHour24($date, $pattern = 'H') |
|
447 | 447 | { |
448 | 448 | $hour = $date['hours']; |
449 | 449 | |
450 | - switch($pattern) |
|
450 | + switch ($pattern) |
|
451 | 451 | { |
452 | 452 | case 'H': |
453 | 453 | return $hour; |
454 | 454 | case 'HH': |
455 | - return str_pad($hour, 2,'0',STR_PAD_LEFT); |
|
455 | + return str_pad($hour, 2, '0', STR_PAD_LEFT); |
|
456 | 456 | default: |
457 | - throw new Exception('The pattern for 24 hour '. |
|
457 | + throw new Exception('The pattern for 24 hour ' . |
|
458 | 458 | 'format is "H" or "HH".'); |
459 | 459 | } |
460 | 460 | } |
@@ -465,13 +465,13 @@ discard block |
||
465 | 465 | * @param string a pattern. |
466 | 466 | * @return string AM or PM designator |
467 | 467 | */ |
468 | - protected function getAMPM($date, $pattern='a') |
|
468 | + protected function getAMPM($date, $pattern = 'a') |
|
469 | 469 | { |
470 | - if($pattern != 'a') |
|
470 | + if ($pattern != 'a') |
|
471 | 471 | throw new Exception('The pattern for AM/PM marker is "a".'); |
472 | 472 | |
473 | 473 | $hour = $date['hours']; |
474 | - $ampm = (int)($hour/12); |
|
474 | + $ampm = (int) ($hour / 12); |
|
475 | 475 | return $this->formatInfo->AMPMMarkers[$ampm]; |
476 | 476 | } |
477 | 477 | |
@@ -482,19 +482,19 @@ discard block |
||
482 | 482 | * @param string a pattern. |
483 | 483 | * @return string hours in 12 hour format. |
484 | 484 | */ |
485 | - protected function getHour12($date, $pattern='h') |
|
485 | + protected function getHour12($date, $pattern = 'h') |
|
486 | 486 | { |
487 | 487 | $hour = $date['hours']; |
488 | - $hour = ($hour==12|$hour==0)?12:($hour)%12; |
|
488 | + $hour = ($hour == 12 | $hour == 0) ? 12 : ($hour) % 12; |
|
489 | 489 | |
490 | - switch($pattern) |
|
490 | + switch ($pattern) |
|
491 | 491 | { |
492 | 492 | case 'h': |
493 | 493 | return $hour; |
494 | 494 | case 'hh': |
495 | - return str_pad($hour, 2,'0',STR_PAD_LEFT); |
|
495 | + return str_pad($hour, 2, '0', STR_PAD_LEFT); |
|
496 | 496 | default: |
497 | - throw new Exception('The pattern for 24 hour '. |
|
497 | + throw new Exception('The pattern for 24 hour ' . |
|
498 | 498 | 'format is "H" or "HH".'); |
499 | 499 | } |
500 | 500 | } |
@@ -506,16 +506,16 @@ discard block |
||
506 | 506 | * @param string a pattern. |
507 | 507 | * @return string minutes. |
508 | 508 | */ |
509 | - protected function getMinutes($date, $pattern='m') |
|
509 | + protected function getMinutes($date, $pattern = 'm') |
|
510 | 510 | { |
511 | 511 | $minutes = $date['minutes']; |
512 | 512 | |
513 | - switch($pattern) |
|
513 | + switch ($pattern) |
|
514 | 514 | { |
515 | 515 | case 'm': |
516 | 516 | return $minutes; |
517 | 517 | case 'mm': |
518 | - return str_pad($minutes, 2,'0',STR_PAD_LEFT); |
|
518 | + return str_pad($minutes, 2, '0', STR_PAD_LEFT); |
|
519 | 519 | default: |
520 | 520 | throw new Exception('The pattern for minutes is "m" or "mm".'); |
521 | 521 | } |
@@ -528,16 +528,16 @@ discard block |
||
528 | 528 | * @param string a pattern. |
529 | 529 | * @return string seconds |
530 | 530 | */ |
531 | - protected function getSeconds($date, $pattern='s') |
|
531 | + protected function getSeconds($date, $pattern = 's') |
|
532 | 532 | { |
533 | 533 | $seconds = $date['seconds']; |
534 | 534 | |
535 | - switch($pattern) |
|
535 | + switch ($pattern) |
|
536 | 536 | { |
537 | 537 | case 's': |
538 | 538 | return $seconds; |
539 | 539 | case 'ss': |
540 | - return str_pad($seconds, 2,'0',STR_PAD_LEFT); |
|
540 | + return str_pad($seconds, 2, '0', STR_PAD_LEFT); |
|
541 | 541 | default: |
542 | 542 | throw new Exception('The pattern for seconds is "s" or "ss".'); |
543 | 543 | } |
@@ -550,9 +550,9 @@ discard block |
||
550 | 550 | * @param string a pattern. |
551 | 551 | * @return string time zone |
552 | 552 | */ |
553 | - protected function getTimeZone($date, $pattern='z') |
|
553 | + protected function getTimeZone($date, $pattern = 'z') |
|
554 | 554 | { |
555 | - if($pattern != 'z') |
|
555 | + if ($pattern != 'z') |
|
556 | 556 | throw new Exception('The pattern for time zone is "z".'); |
557 | 557 | |
558 | 558 | return @date('T', @mktime($date['hours'], $date['minutes'], $date['seconds'], $date['mon'], $date['mday'], $date['year'])); |
@@ -564,9 +564,9 @@ discard block |
||
564 | 564 | * @param string a pattern. |
565 | 565 | * @return int hours in AM/PM format. |
566 | 566 | */ |
567 | - protected function getDayInYear($date, $pattern='D') |
|
567 | + protected function getDayInYear($date, $pattern = 'D') |
|
568 | 568 | { |
569 | - if($pattern != 'D') |
|
569 | + if ($pattern != 'D') |
|
570 | 570 | throw new Exception('The pattern for day in year is "D".'); |
571 | 571 | |
572 | 572 | return $date['yday']; |
@@ -578,7 +578,7 @@ discard block |
||
578 | 578 | * @param string a pattern. |
579 | 579 | * @return int day in month |
580 | 580 | */ |
581 | - protected function getDayInMonth($date, $pattern='FF') |
|
581 | + protected function getDayInMonth($date, $pattern = 'FF') |
|
582 | 582 | { |
583 | 583 | switch ($pattern) { |
584 | 584 | case 'F': |
@@ -598,9 +598,9 @@ discard block |
||
598 | 598 | * @param string a pattern. |
599 | 599 | * @return int week in year |
600 | 600 | */ |
601 | - protected function getWeekInYear($date, $pattern='w') |
|
601 | + protected function getWeekInYear($date, $pattern = 'w') |
|
602 | 602 | { |
603 | - if($pattern != 'w') |
|
603 | + if ($pattern != 'w') |
|
604 | 604 | throw new Exception('The pattern for week in year is "w".'); |
605 | 605 | |
606 | 606 | return @date('W', @mktime(0, 0, 0, $date['mon'], $date['mday'], $date['year'])); |
@@ -611,9 +611,9 @@ discard block |
||
611 | 611 | * @param array getdate format. |
612 | 612 | * @return int week in month |
613 | 613 | */ |
614 | - protected function getWeekInMonth($date, $pattern='W') |
|
614 | + protected function getWeekInMonth($date, $pattern = 'W') |
|
615 | 615 | { |
616 | - if($pattern != 'W') |
|
616 | + if ($pattern != 'W') |
|
617 | 617 | throw new Exception('The pattern for week in month is "W".'); |
618 | 618 | |
619 | 619 | return @date('W', @mktime(0, 0, 0, $date['mon'], $date['mday'], $date['year'])) - date('W', mktime(0, 0, 0, $date['mon'], 1, $date['year'])); |
@@ -625,12 +625,12 @@ discard block |
||
625 | 625 | * @param string a pattern. |
626 | 626 | * @return int hours [1-24] |
627 | 627 | */ |
628 | - protected function getHourInDay($date, $pattern='k') |
|
628 | + protected function getHourInDay($date, $pattern = 'k') |
|
629 | 629 | { |
630 | - if($pattern != 'k') |
|
630 | + if ($pattern != 'k') |
|
631 | 631 | throw new Exception('The pattern for hour in day is "k".'); |
632 | 632 | |
633 | - return $date['hours']+1; |
|
633 | + return $date['hours'] + 1; |
|
634 | 634 | } |
635 | 635 | |
636 | 636 | /** |
@@ -639,12 +639,12 @@ discard block |
||
639 | 639 | * @param string a pattern. |
640 | 640 | * @return int hours in AM/PM format. |
641 | 641 | */ |
642 | - protected function getHourInAMPM($date, $pattern='K') |
|
642 | + protected function getHourInAMPM($date, $pattern = 'K') |
|
643 | 643 | { |
644 | - if($pattern != 'K') |
|
644 | + if ($pattern != 'K') |
|
645 | 645 | throw new Exception('The pattern for hour in AM/PM is "K".'); |
646 | 646 | |
647 | - return ($date['hours']+1)%12; |
|
647 | + return ($date['hours'] + 1) % 12; |
|
648 | 648 | } |
649 | 649 | |
650 | 650 | } |
@@ -91,14 +91,15 @@ discard block |
||
91 | 91 | */ |
92 | 92 | function __construct($formatInfo=null) |
93 | 93 | { |
94 | - if($formatInfo === null) |
|
95 | - $this->formatInfo = DateTimeFormatInfo::getInvariantInfo(); |
|
96 | - else if($formatInfo instanceof CultureInfo) |
|
97 | - $this->formatInfo = $formatInfo->DateTimeFormat; |
|
98 | - else if($formatInfo instanceof DateTimeFormatInfo) |
|
99 | - $this->formatInfo = $formatInfo; |
|
100 | - else |
|
101 | - $this->formatInfo = DateTimeFormatInfo::getInstance($formatInfo); |
|
94 | + if($formatInfo === null) { |
|
95 | + $this->formatInfo = DateTimeFormatInfo::getInvariantInfo(); |
|
96 | + } else if($formatInfo instanceof CultureInfo) { |
|
97 | + $this->formatInfo = $formatInfo->DateTimeFormat; |
|
98 | + } else if($formatInfo instanceof DateTimeFormatInfo) { |
|
99 | + $this->formatInfo = $formatInfo; |
|
100 | + } else { |
|
101 | + $this->formatInfo = DateTimeFormatInfo::getInstance($formatInfo); |
|
102 | + } |
|
102 | 103 | |
103 | 104 | $this->methods = get_class_methods($this); |
104 | 105 | } |
@@ -110,13 +111,16 @@ discard block |
||
110 | 111 | */ |
111 | 112 | public function format($time, $pattern='F', $charset='UTF-8') |
112 | 113 | { |
113 | - if (is_numeric($time)) //assumes unix epoch |
|
114 | + if (is_numeric($time)) { |
|
115 | + //assumes unix epoch |
|
114 | 116 | $time = floatval($time); |
115 | - else if(is_string($time)) |
|
116 | - $time = @strtotime($time); |
|
117 | + } else if(is_string($time)) { |
|
118 | + $time = @strtotime($time); |
|
119 | + } |
|
117 | 120 | |
118 | - if($pattern === null) |
|
119 | - $pattern = 'F'; |
|
121 | + if($pattern === null) { |
|
122 | + $pattern = 'F'; |
|
123 | + } |
|
120 | 124 | |
121 | 125 | $s = Prado::createComponent('System.Util.TDateTimeStamp'); |
122 | 126 | |
@@ -134,12 +138,10 @@ discard block |
||
134 | 138 | { |
135 | 139 | $sub = preg_replace('/(^\')|(\'$)/','',$pattern); |
136 | 140 | $tokens[$i] = str_replace('``````','\'',$sub); |
137 | - } |
|
138 | - else if($pattern == '``````') |
|
141 | + } else if($pattern == '``````') |
|
139 | 142 | { |
140 | 143 | $tokens[$i] = '\''; |
141 | - } |
|
142 | - else |
|
144 | + } else |
|
143 | 145 | { |
144 | 146 | $function = $this->getFunctionName($pattern); |
145 | 147 | if($function != null) |
@@ -149,10 +151,10 @@ discard block |
||
149 | 151 | { |
150 | 152 | $rs = $this->$fName($date, $pattern); |
151 | 153 | $tokens[$i] = $rs; |
152 | - } |
|
153 | - else |
|
154 | - throw new |
|
154 | + } else { |
|
155 | + throw new |
|
155 | 156 | Exception('function '.$function.' not found.'); |
157 | + } |
|
156 | 158 | } |
157 | 159 | } |
158 | 160 | } |
@@ -167,8 +169,9 @@ discard block |
||
167 | 169 | */ |
168 | 170 | protected function getFunctionName($token) |
169 | 171 | { |
170 | - if(isset($this->tokens[$token{0}])) |
|
171 | - return $this->tokens[$token{0}]; |
|
172 | + if(isset($this->tokens[$token{0}])) { |
|
173 | + return $this->tokens[$token{0}]; |
|
174 | + } |
|
172 | 175 | } |
173 | 176 | |
174 | 177 | /** |
@@ -285,19 +288,19 @@ discard block |
||
285 | 288 | if($char==null || $pattern{$i} == $char || $text) |
286 | 289 | { |
287 | 290 | $token .= $pattern{$i}; |
288 | - } |
|
289 | - else |
|
291 | + } else |
|
290 | 292 | { |
291 | 293 | $tokens[] = str_replace("","'",$token); |
292 | 294 | $token = $pattern{$i}; |
293 | 295 | } |
294 | 296 | |
295 | - if($pattern{$i} == "'" && $text == false) |
|
296 | - $text = true; |
|
297 | - else if($text && $pattern{$i} == "'" && $char == "'") |
|
298 | - $text = true; |
|
299 | - else if($text && $char != "'" && $pattern{$i} == "'") |
|
300 | - $text = false; |
|
297 | + if($pattern{$i} == "'" && $text == false) { |
|
298 | + $text = true; |
|
299 | + } else if($text && $pattern{$i} == "'" && $char == "'") { |
|
300 | + $text = true; |
|
301 | + } else if($text && $char != "'" && $pattern{$i} == "'") { |
|
302 | + $text = false; |
|
303 | + } |
|
301 | 304 | |
302 | 305 | $char = $pattern{$i}; |
303 | 306 | |
@@ -426,14 +429,16 @@ discard block |
||
426 | 429 | protected function getEra($date, $pattern='G') |
427 | 430 | { |
428 | 431 | |
429 | - if($pattern != 'G') |
|
430 | - throw new Exception('The pattern for era is "G".'); |
|
432 | + if($pattern != 'G') { |
|
433 | + throw new Exception('The pattern for era is "G".'); |
|
434 | + } |
|
431 | 435 | |
432 | 436 | $year = $date['year']; |
433 | - if($year > 0) |
|
434 | - return $this->formatInfo->getEra(1); |
|
435 | - else |
|
436 | - return $this->formatInfo->getEra(0); |
|
437 | + if($year > 0) { |
|
438 | + return $this->formatInfo->getEra(1); |
|
439 | + } else { |
|
440 | + return $this->formatInfo->getEra(0); |
|
441 | + } |
|
437 | 442 | } |
438 | 443 | |
439 | 444 | /** |
@@ -467,8 +472,9 @@ discard block |
||
467 | 472 | */ |
468 | 473 | protected function getAMPM($date, $pattern='a') |
469 | 474 | { |
470 | - if($pattern != 'a') |
|
471 | - throw new Exception('The pattern for AM/PM marker is "a".'); |
|
475 | + if($pattern != 'a') { |
|
476 | + throw new Exception('The pattern for AM/PM marker is "a".'); |
|
477 | + } |
|
472 | 478 | |
473 | 479 | $hour = $date['hours']; |
474 | 480 | $ampm = (int)($hour/12); |
@@ -552,8 +558,9 @@ discard block |
||
552 | 558 | */ |
553 | 559 | protected function getTimeZone($date, $pattern='z') |
554 | 560 | { |
555 | - if($pattern != 'z') |
|
556 | - throw new Exception('The pattern for time zone is "z".'); |
|
561 | + if($pattern != 'z') { |
|
562 | + throw new Exception('The pattern for time zone is "z".'); |
|
563 | + } |
|
557 | 564 | |
558 | 565 | return @date('T', @mktime($date['hours'], $date['minutes'], $date['seconds'], $date['mon'], $date['mday'], $date['year'])); |
559 | 566 | } |
@@ -566,8 +573,9 @@ discard block |
||
566 | 573 | */ |
567 | 574 | protected function getDayInYear($date, $pattern='D') |
568 | 575 | { |
569 | - if($pattern != 'D') |
|
570 | - throw new Exception('The pattern for day in year is "D".'); |
|
576 | + if($pattern != 'D') { |
|
577 | + throw new Exception('The pattern for day in year is "D".'); |
|
578 | + } |
|
571 | 579 | |
572 | 580 | return $date['yday']; |
573 | 581 | } |
@@ -600,8 +608,9 @@ discard block |
||
600 | 608 | */ |
601 | 609 | protected function getWeekInYear($date, $pattern='w') |
602 | 610 | { |
603 | - if($pattern != 'w') |
|
604 | - throw new Exception('The pattern for week in year is "w".'); |
|
611 | + if($pattern != 'w') { |
|
612 | + throw new Exception('The pattern for week in year is "w".'); |
|
613 | + } |
|
605 | 614 | |
606 | 615 | return @date('W', @mktime(0, 0, 0, $date['mon'], $date['mday'], $date['year'])); |
607 | 616 | } |
@@ -613,8 +622,9 @@ discard block |
||
613 | 622 | */ |
614 | 623 | protected function getWeekInMonth($date, $pattern='W') |
615 | 624 | { |
616 | - if($pattern != 'W') |
|
617 | - throw new Exception('The pattern for week in month is "W".'); |
|
625 | + if($pattern != 'W') { |
|
626 | + throw new Exception('The pattern for week in month is "W".'); |
|
627 | + } |
|
618 | 628 | |
619 | 629 | return @date('W', @mktime(0, 0, 0, $date['mon'], $date['mday'], $date['year'])) - date('W', mktime(0, 0, 0, $date['mon'], 1, $date['year'])); |
620 | 630 | } |
@@ -627,8 +637,9 @@ discard block |
||
627 | 637 | */ |
628 | 638 | protected function getHourInDay($date, $pattern='k') |
629 | 639 | { |
630 | - if($pattern != 'k') |
|
631 | - throw new Exception('The pattern for hour in day is "k".'); |
|
640 | + if($pattern != 'k') { |
|
641 | + throw new Exception('The pattern for hour in day is "k".'); |
|
642 | + } |
|
632 | 643 | |
633 | 644 | return $date['hours']+1; |
634 | 645 | } |
@@ -641,8 +652,9 @@ discard block |
||
641 | 652 | */ |
642 | 653 | protected function getHourInAMPM($date, $pattern='K') |
643 | 654 | { |
644 | - if($pattern != 'K') |
|
645 | - throw new Exception('The pattern for hour in AM/PM is "K".'); |
|
655 | + if($pattern != 'K') { |
|
656 | + throw new Exception('The pattern for hour in AM/PM is "K".'); |
|
657 | + } |
|
646 | 658 | |
647 | 659 | return ($date['hours']+1)%12; |
648 | 660 | } |
@@ -340,6 +340,7 @@ |
||
340 | 340 | /** |
341 | 341 | * A string containing the name of the era. |
342 | 342 | * @param int era The integer representing the era. |
343 | + * @param integer $era |
|
343 | 344 | * @return string the era name. |
344 | 345 | */ |
345 | 346 | function getEra($era) |
@@ -149,46 +149,46 @@ discard block |
||
149 | 149 | * (invariant). |
150 | 150 | * @return DateTimeFormatInfo default DateTimeFormatInfo. |
151 | 151 | */ |
152 | - static function getInvariantInfo() |
|
153 | - { |
|
154 | - static $invariant; |
|
152 | + static function getInvariantInfo() |
|
153 | + { |
|
154 | + static $invariant; |
|
155 | 155 | if($invariant === null) |
156 | - { |
|
157 | - $culture = CultureInfo::getInvariantCulture(); |
|
158 | - $invariant = $culture->getDateTimeFormat(); |
|
159 | - } |
|
156 | + { |
|
157 | + $culture = CultureInfo::getInvariantCulture(); |
|
158 | + $invariant = $culture->getDateTimeFormat(); |
|
159 | + } |
|
160 | 160 | return $invariant; |
161 | - } |
|
162 | - |
|
163 | - /** |
|
164 | - * Returns the DateTimeFormatInfo associated with the specified culture. |
|
165 | - * @param CultureInfo the culture that gets the DateTimeFormat property. |
|
166 | - * @return DateTimeFormatInfo DateTimeFormatInfo for the specified |
|
167 | - * culture. |
|
168 | - */ |
|
169 | - static function getInstance($culture=null) |
|
170 | - { |
|
171 | - |
|
172 | - if ($culture instanceof CultureInfo) |
|
173 | - return $culture->getDateTimeFormat(); |
|
174 | - else if(is_string($culture)) |
|
175 | - { |
|
176 | - $cultureInfo = CultureInfo::getInstance($culture); |
|
177 | - return $cultureInfo->getDateTimeFormat(); |
|
178 | - } |
|
179 | - else |
|
180 | - { |
|
161 | + } |
|
162 | + |
|
163 | + /** |
|
164 | + * Returns the DateTimeFormatInfo associated with the specified culture. |
|
165 | + * @param CultureInfo the culture that gets the DateTimeFormat property. |
|
166 | + * @return DateTimeFormatInfo DateTimeFormatInfo for the specified |
|
167 | + * culture. |
|
168 | + */ |
|
169 | + static function getInstance($culture=null) |
|
170 | + { |
|
171 | + |
|
172 | + if ($culture instanceof CultureInfo) |
|
173 | + return $culture->getDateTimeFormat(); |
|
174 | + else if(is_string($culture)) |
|
175 | + { |
|
176 | + $cultureInfo = CultureInfo::getInstance($culture); |
|
177 | + return $cultureInfo->getDateTimeFormat(); |
|
178 | + } |
|
179 | + else |
|
180 | + { |
|
181 | 181 | $cultureInfo = CultureInfo::getInvariantCulture(); |
182 | - return $cultureInfo->getDateTimeFormat(); |
|
183 | - } |
|
184 | - } |
|
182 | + return $cultureInfo->getDateTimeFormat(); |
|
183 | + } |
|
184 | + } |
|
185 | 185 | |
186 | 186 | /** |
187 | 187 | * A one-dimensional array of type String containing |
188 | 188 | * the culture-specific abbreviated names of the days |
189 | 189 | * of the week. The array for InvariantInfo contains |
190 | 190 | * "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", and "Sat". |
191 | - * @return array abbreviated day names |
|
191 | + * @return array abbreviated day names |
|
192 | 192 | */ |
193 | 193 | function getAbbreviatedDayNames() |
194 | 194 | { |
@@ -196,37 +196,37 @@ discard block |
||
196 | 196 | //return $this->data['dayNames/format/abbreviated']; |
197 | 197 | } |
198 | 198 | |
199 | - /** |
|
200 | - * Set the abbreviated day names. The value should be |
|
201 | - * an array of string starting with Sunday and ends in Saturady. |
|
202 | - * For example, |
|
203 | - * <code>array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");</code> |
|
204 | - * @param array abbreviated day names. |
|
205 | - */ |
|
206 | - function setAbbreviatedDayNames($value) |
|
207 | - { |
|
208 | - $this->data['dayNames']['format']['abbreviated'] = $value; |
|
209 | - } |
|
199 | + /** |
|
200 | + * Set the abbreviated day names. The value should be |
|
201 | + * an array of string starting with Sunday and ends in Saturady. |
|
202 | + * For example, |
|
203 | + * <code>array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");</code> |
|
204 | + * @param array abbreviated day names. |
|
205 | + */ |
|
206 | + function setAbbreviatedDayNames($value) |
|
207 | + { |
|
208 | + $this->data['dayNames']['format']['abbreviated'] = $value; |
|
209 | + } |
|
210 | 210 | |
211 | 211 | /** |
212 | 212 | * A one-dimensional array of type String containing |
213 | 213 | * the culture-specific narrow names of the days |
214 | 214 | * of the week. The array for InvariantInfo contains |
215 | 215 | * "S", "M", "T", "W", "T", "F", and "S". |
216 | - * @return array narrow day names |
|
216 | + * @return array narrow day names |
|
217 | 217 | */ |
218 | 218 | function getNarrowDayNames() |
219 | 219 | { |
220 | 220 | return $this->data['dayNames']['format']['narrow']; |
221 | 221 | } |
222 | 222 | |
223 | - /** |
|
224 | - * Set the narrow day names. The value should be |
|
225 | - * an array of string starting with Sunday and ends in Saturady. |
|
226 | - * For example, |
|
227 | - * <code>array("S", "M", "T", "W", "T", "F", "S");</code> |
|
228 | - * @param array narrow day names. |
|
229 | - */ |
|
223 | + /** |
|
224 | + * Set the narrow day names. The value should be |
|
225 | + * an array of string starting with Sunday and ends in Saturady. |
|
226 | + * For example, |
|
227 | + * <code>array("S", "M", "T", "W", "T", "F", "S");</code> |
|
228 | + * @param array narrow day names. |
|
229 | + */ |
|
230 | 230 | function setNarrowDayNames($value) |
231 | 231 | { |
232 | 232 | $this->data['dayNames']['format']['narrow'] = $value; |
@@ -237,7 +237,7 @@ discard block |
||
237 | 237 | * culture-specific full names of the days of the week. |
238 | 238 | * The array for InvariantInfo contains "Sunday", "Monday", |
239 | 239 | * "Tuesday", "Wednesday", "Thursday", "Friday", and "Saturday". |
240 | - * @return array day names |
|
240 | + * @return array day names |
|
241 | 241 | */ |
242 | 242 | function getDayNames() |
243 | 243 | { |
@@ -245,14 +245,14 @@ discard block |
||
245 | 245 | } |
246 | 246 | |
247 | 247 | |
248 | - /** |
|
249 | - * Set the day names. The value should be |
|
250 | - * an array of string starting with Sunday and ends in Saturady. |
|
251 | - * For example, |
|
252 | - * <code>array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", |
|
253 | - * "Friday", "Saturday".);</code> |
|
254 | - * @param array day names. |
|
255 | - */ |
|
248 | + /** |
|
249 | + * Set the day names. The value should be |
|
250 | + * an array of string starting with Sunday and ends in Saturady. |
|
251 | + * For example, |
|
252 | + * <code>array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", |
|
253 | + * "Friday", "Saturday".);</code> |
|
254 | + * @param array day names. |
|
255 | + */ |
|
256 | 256 | function setDayNames($value) |
257 | 257 | { |
258 | 258 | $this->data['dayNames']['format']['wide'] = $value; |
@@ -270,17 +270,17 @@ discard block |
||
270 | 270 | return $this->data['monthNames']['format']['narrow']; |
271 | 271 | } |
272 | 272 | |
273 | - /** |
|
274 | - * Set the narrow month names. The value should be |
|
275 | - * an array of string starting with J and ends in D. |
|
276 | - * For example, |
|
277 | - * <code>array("J","F","M","A","M","J","J","A","S","O","N","D");</code> |
|
278 | - * @param array month names. |
|
279 | - */ |
|
280 | - function setNarrowMonthNames($value) |
|
281 | - { |
|
282 | - $this->data['monthNames']['format']['narrow'] = $value; |
|
283 | - } |
|
273 | + /** |
|
274 | + * Set the narrow month names. The value should be |
|
275 | + * an array of string starting with J and ends in D. |
|
276 | + * For example, |
|
277 | + * <code>array("J","F","M","A","M","J","J","A","S","O","N","D");</code> |
|
278 | + * @param array month names. |
|
279 | + */ |
|
280 | + function setNarrowMonthNames($value) |
|
281 | + { |
|
282 | + $this->data['monthNames']['format']['narrow'] = $value; |
|
283 | + } |
|
284 | 284 | |
285 | 285 | /** |
286 | 286 | * A one-dimensional array of type String containing the |
@@ -298,18 +298,18 @@ discard block |
||
298 | 298 | return $this->data['monthNames']['format']['wide']; |
299 | 299 | } |
300 | 300 | |
301 | - /** |
|
302 | - * Set the abbreviated month names. The value should be |
|
303 | - * an array of string starting with Jan and ends in Dec. |
|
304 | - * For example, |
|
305 | - * <code>array("Jan", "Feb", "Mar", "Apr", "May", "Jun", |
|
306 | - * "Jul", "Aug", "Sep","Oct","Nov","Dec");</code> |
|
307 | - * @param array month names. |
|
308 | - */ |
|
309 | - function setAbbreviatedMonthNames($value) |
|
310 | - { |
|
311 | - $this->data['monthNames']['format']['abbreviated'] = $value; |
|
312 | - } |
|
301 | + /** |
|
302 | + * Set the abbreviated month names. The value should be |
|
303 | + * an array of string starting with Jan and ends in Dec. |
|
304 | + * For example, |
|
305 | + * <code>array("Jan", "Feb", "Mar", "Apr", "May", "Jun", |
|
306 | + * "Jul", "Aug", "Sep","Oct","Nov","Dec");</code> |
|
307 | + * @param array month names. |
|
308 | + */ |
|
309 | + function setAbbreviatedMonthNames($value) |
|
310 | + { |
|
311 | + $this->data['monthNames']['format']['abbreviated'] = $value; |
|
312 | + } |
|
313 | 313 | |
314 | 314 | /** |
315 | 315 | * A one-dimensional array of type String containing the |
@@ -324,18 +324,18 @@ discard block |
||
324 | 324 | return $this->data['monthNames']['format']['wide']; |
325 | 325 | } |
326 | 326 | |
327 | - /** |
|
328 | - * Set the month names. The value should be |
|
329 | - * an array of string starting with Janurary and ends in December. |
|
330 | - * For example, |
|
331 | - * <code>array("January", "February", "March", "April", "May", "June", |
|
332 | - * "July", "August", "September","October","November","December");</code> |
|
333 | - * @param array month names. |
|
334 | - */ |
|
335 | - function setMonthNames($value) |
|
336 | - { |
|
337 | - $this->data['monthNames']['format']['wide'] = $value; |
|
338 | - } |
|
327 | + /** |
|
328 | + * Set the month names. The value should be |
|
329 | + * an array of string starting with Janurary and ends in December. |
|
330 | + * For example, |
|
331 | + * <code>array("January", "February", "March", "April", "May", "June", |
|
332 | + * "July", "August", "September","October","November","December");</code> |
|
333 | + * @param array month names. |
|
334 | + */ |
|
335 | + function setMonthNames($value) |
|
336 | + { |
|
337 | + $this->data['monthNames']['format']['wide'] = $value; |
|
338 | + } |
|
339 | 339 | |
340 | 340 | /** |
341 | 341 | * A string containing the name of the era. |
@@ -359,16 +359,16 @@ discard block |
||
359 | 359 | return $result[0]; |
360 | 360 | } |
361 | 361 | |
362 | - /** |
|
363 | - * Set the AM Designator. For example, 'AM'. |
|
364 | - * @param string AM designator. |
|
365 | - */ |
|
366 | - function setAMDesignator($value) |
|
367 | - { |
|
368 | - $markers = $this->getAMPMMarkers(); |
|
369 | - $markers[0] = $value; |
|
370 | - $this->setAMPMMarkers($markers); |
|
371 | - } |
|
362 | + /** |
|
363 | + * Set the AM Designator. For example, 'AM'. |
|
364 | + * @param string AM designator. |
|
365 | + */ |
|
366 | + function setAMDesignator($value) |
|
367 | + { |
|
368 | + $markers = $this->getAMPMMarkers(); |
|
369 | + $markers[0] = $value; |
|
370 | + $this->setAMPMMarkers($markers); |
|
371 | + } |
|
372 | 372 | |
373 | 373 | /** |
374 | 374 | * The string designator for hours that are "post meridiem" (after noon). |
@@ -381,41 +381,41 @@ discard block |
||
381 | 381 | return $result[1]; |
382 | 382 | } |
383 | 383 | |
384 | - /** |
|
385 | - * Set the PM Designator. For example, 'PM'. |
|
386 | - * @param string PM designator. |
|
387 | - */ |
|
388 | - function setPMDesignator($value) |
|
389 | - { |
|
390 | - $markers = $this->getAMPMMarkers(); |
|
391 | - $markers[1] = $value; |
|
392 | - $this->setAMPMMarkers($markers); |
|
393 | - } |
|
394 | - |
|
395 | - /** |
|
396 | - * Get the AM and PM markers array. |
|
397 | - * Default InvariantInfo for AM and PM is <code>array('AM','PM');</code> |
|
398 | - * @return array AM and PM markers |
|
399 | - */ |
|
400 | - function getAMPMMarkers() |
|
384 | + /** |
|
385 | + * Set the PM Designator. For example, 'PM'. |
|
386 | + * @param string PM designator. |
|
387 | + */ |
|
388 | + function setPMDesignator($value) |
|
389 | + { |
|
390 | + $markers = $this->getAMPMMarkers(); |
|
391 | + $markers[1] = $value; |
|
392 | + $this->setAMPMMarkers($markers); |
|
393 | + } |
|
394 | + |
|
395 | + /** |
|
396 | + * Get the AM and PM markers array. |
|
397 | + * Default InvariantInfo for AM and PM is <code>array('AM','PM');</code> |
|
398 | + * @return array AM and PM markers |
|
399 | + */ |
|
400 | + function getAMPMMarkers() |
|
401 | 401 | { |
402 | 402 | return $this->data['AmPmMarkers']; |
403 | 403 | } |
404 | 404 | |
405 | - /** |
|
406 | - * Set the AM and PM markers array. |
|
407 | - * For example <code>array('AM','PM');</code> |
|
408 | - * @param array AM and PM markers |
|
409 | - */ |
|
410 | - function setAMPMMarkers($value) |
|
411 | - { |
|
412 | - $this->data['AmPmMarkers'] = $value; |
|
413 | - } |
|
405 | + /** |
|
406 | + * Set the AM and PM markers array. |
|
407 | + * For example <code>array('AM','PM');</code> |
|
408 | + * @param array AM and PM markers |
|
409 | + */ |
|
410 | + function setAMPMMarkers($value) |
|
411 | + { |
|
412 | + $this->data['AmPmMarkers'] = $value; |
|
413 | + } |
|
414 | 414 | |
415 | 415 | /** |
416 | 416 | * Returns the full time pattern "HH:mm:ss z" (default). |
417 | - * This is culture sensitive. |
|
418 | - * @return string pattern "HH:mm:ss z". |
|
417 | + * This is culture sensitive. |
|
418 | + * @return string pattern "HH:mm:ss z". |
|
419 | 419 | */ |
420 | 420 | function getFullTimePattern() |
421 | 421 | { |
@@ -424,8 +424,8 @@ discard block |
||
424 | 424 | |
425 | 425 | /** |
426 | 426 | * Returns the long time pattern "HH:mm:ss z" (default). |
427 | - * This is culture sensitive. |
|
428 | - * @return string pattern "HH:mm:ss z". |
|
427 | + * This is culture sensitive. |
|
428 | + * @return string pattern "HH:mm:ss z". |
|
429 | 429 | */ |
430 | 430 | function getLongTimePattern() |
431 | 431 | { |
@@ -434,8 +434,8 @@ discard block |
||
434 | 434 | |
435 | 435 | /** |
436 | 436 | * Returns the medium time pattern "HH:mm:ss" (default). |
437 | - * This is culture sensitive. |
|
438 | - * @return string pattern "HH:mm:ss". |
|
437 | + * This is culture sensitive. |
|
438 | + * @return string pattern "HH:mm:ss". |
|
439 | 439 | */ |
440 | 440 | function getMediumTimePattern() |
441 | 441 | { |
@@ -444,8 +444,8 @@ discard block |
||
444 | 444 | |
445 | 445 | /** |
446 | 446 | * Returns the short time pattern "HH:mm" (default). |
447 | - * This is culture sensitive. |
|
448 | - * @return string pattern "HH:mm". |
|
447 | + * This is culture sensitive. |
|
448 | + * @return string pattern "HH:mm". |
|
449 | 449 | */ |
450 | 450 | function getShortTimePattern() |
451 | 451 | { |
@@ -454,8 +454,8 @@ discard block |
||
454 | 454 | |
455 | 455 | /** |
456 | 456 | * Returns the full date pattern "EEEE, yyyy MMMM dd" (default). |
457 | - * This is culture sensitive. |
|
458 | - * @return string pattern "EEEE, yyyy MMMM dd". |
|
457 | + * This is culture sensitive. |
|
458 | + * @return string pattern "EEEE, yyyy MMMM dd". |
|
459 | 459 | */ |
460 | 460 | function getFullDatePattern() |
461 | 461 | { |
@@ -464,8 +464,8 @@ discard block |
||
464 | 464 | |
465 | 465 | /** |
466 | 466 | * Returns the long date pattern "yyyy MMMM d" (default). |
467 | - * This is culture sensitive. |
|
468 | - * @return string pattern "yyyy MMMM d". |
|
467 | + * This is culture sensitive. |
|
468 | + * @return string pattern "yyyy MMMM d". |
|
469 | 469 | */ |
470 | 470 | function getLongDatePattern() |
471 | 471 | { |
@@ -474,8 +474,8 @@ discard block |
||
474 | 474 | |
475 | 475 | /** |
476 | 476 | * Returns the medium date pattern "yyyy MMMM d" (default). |
477 | - * This is culture sensitive. |
|
478 | - * @return string pattern "yyyy MMM d". |
|
477 | + * This is culture sensitive. |
|
478 | + * @return string pattern "yyyy MMM d". |
|
479 | 479 | */ |
480 | 480 | function getMediumDatePattern() |
481 | 481 | { |
@@ -484,28 +484,28 @@ discard block |
||
484 | 484 | |
485 | 485 | /** |
486 | 486 | * Returns the short date pattern "yy/MM/dd" (default). |
487 | - * This is culture sensitive. |
|
488 | - * @return string pattern "yy/MM/dd". |
|
487 | + * This is culture sensitive. |
|
488 | + * @return string pattern "yy/MM/dd". |
|
489 | 489 | */ |
490 | 490 | function getShortDatePattern() |
491 | 491 | { |
492 | 492 | return $this->data['DateTimePatterns'][7]; |
493 | 493 | } |
494 | 494 | |
495 | - /** |
|
496 | - * Returns the date time order pattern, "{1} {0}" (default). |
|
497 | - * This is culture sensitive. |
|
498 | - * @return string pattern "{1} {0}". |
|
499 | - */ |
|
500 | - function getDateTimeOrderPattern() |
|
501 | - { |
|
502 | - return $this->data['DateTimePatterns'][8]; |
|
503 | - } |
|
495 | + /** |
|
496 | + * Returns the date time order pattern, "{1} {0}" (default). |
|
497 | + * This is culture sensitive. |
|
498 | + * @return string pattern "{1} {0}". |
|
499 | + */ |
|
500 | + function getDateTimeOrderPattern() |
|
501 | + { |
|
502 | + return $this->data['DateTimePatterns'][8]; |
|
503 | + } |
|
504 | 504 | |
505 | 505 | /** |
506 | 506 | * Formats the date and time in a culture sensitive paterrn. |
507 | - * The default is "Date Time". |
|
508 | - * @return string date and time formated |
|
507 | + * The default is "Date Time". |
|
508 | + * @return string date and time formated |
|
509 | 509 | */ |
510 | 510 | function formatDateTime($date, $time) |
511 | 511 | { |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | /** |
21 | 21 | * Get the CultureInfo class. |
22 | 22 | */ |
23 | -require_once(dirname(__FILE__).'/CultureInfo.php'); |
|
23 | +require_once(dirname(__FILE__) . '/CultureInfo.php'); |
|
24 | 24 | |
25 | 25 | |
26 | 26 | /** |
@@ -96,11 +96,11 @@ discard block |
||
96 | 96 | */ |
97 | 97 | function __get($name) |
98 | 98 | { |
99 | - $getProperty = 'get'.$name; |
|
100 | - if(in_array($getProperty, $this->properties)) |
|
99 | + $getProperty = 'get' . $name; |
|
100 | + if (in_array($getProperty, $this->properties)) |
|
101 | 101 | return $this->$getProperty(); |
102 | 102 | else |
103 | - throw new Exception('Property '.$name.' does not exists.'); |
|
103 | + throw new Exception('Property ' . $name . ' does not exists.'); |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | /** |
@@ -109,11 +109,11 @@ discard block |
||
109 | 109 | */ |
110 | 110 | function __set($name, $value) |
111 | 111 | { |
112 | - $setProperty = 'set'.$name; |
|
113 | - if(in_array($setProperty, $this->properties)) |
|
112 | + $setProperty = 'set' . $name; |
|
113 | + if (in_array($setProperty, $this->properties)) |
|
114 | 114 | $this->$setProperty($value); |
115 | 115 | else |
116 | - throw new Exception('Property '.$name.' can not be set.'); |
|
116 | + throw new Exception('Property ' . $name . ' can not be set.'); |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | /** |
@@ -125,11 +125,11 @@ discard block |
||
125 | 125 | * @param array ICU data for date time formatting. |
126 | 126 | * @see getInstance() |
127 | 127 | */ |
128 | - function __construct($data=array()) |
|
128 | + function __construct($data = array()) |
|
129 | 129 | { |
130 | 130 | $this->properties = get_class_methods($this); |
131 | 131 | |
132 | - if(empty($data)) |
|
132 | + if (empty($data)) |
|
133 | 133 | throw new Exception('Please provide the ICU data to initialize.'); |
134 | 134 | |
135 | 135 | $this->data = $data; |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | static function getInvariantInfo() |
153 | 153 | { |
154 | 154 | static $invariant; |
155 | - if($invariant === null) |
|
155 | + if ($invariant === null) |
|
156 | 156 | { |
157 | 157 | $culture = CultureInfo::getInvariantCulture(); |
158 | 158 | $invariant = $culture->getDateTimeFormat(); |
@@ -166,12 +166,12 @@ discard block |
||
166 | 166 | * @return DateTimeFormatInfo DateTimeFormatInfo for the specified |
167 | 167 | * culture. |
168 | 168 | */ |
169 | - static function getInstance($culture=null) |
|
169 | + static function getInstance($culture = null) |
|
170 | 170 | { |
171 | 171 | |
172 | 172 | if ($culture instanceof CultureInfo) |
173 | 173 | return $culture->getDateTimeFormat(); |
174 | - else if(is_string($culture)) |
|
174 | + else if (is_string($culture)) |
|
175 | 175 | { |
176 | 176 | $cultureInfo = CultureInfo::getInstance($culture); |
177 | 177 | return $cultureInfo->getDateTimeFormat(); |
@@ -510,7 +510,7 @@ discard block |
||
510 | 510 | function formatDateTime($date, $time) |
511 | 511 | { |
512 | 512 | $pattern = $this->getDateTimeOrderPattern(); |
513 | - return str_replace(array('{0}','{1}'), array($time, $date), $pattern); |
|
513 | + return str_replace(array('{0}', '{1}'), array($time, $date), $pattern); |
|
514 | 514 | } |
515 | 515 | |
516 | 516 | } |
@@ -97,10 +97,11 @@ discard block |
||
97 | 97 | function __get($name) |
98 | 98 | { |
99 | 99 | $getProperty = 'get'.$name; |
100 | - if(in_array($getProperty, $this->properties)) |
|
101 | - return $this->$getProperty(); |
|
102 | - else |
|
103 | - throw new Exception('Property '.$name.' does not exists.'); |
|
100 | + if(in_array($getProperty, $this->properties)) { |
|
101 | + return $this->$getProperty(); |
|
102 | + } else { |
|
103 | + throw new Exception('Property '.$name.' does not exists.'); |
|
104 | + } |
|
104 | 105 | } |
105 | 106 | |
106 | 107 | /** |
@@ -110,10 +111,11 @@ discard block |
||
110 | 111 | function __set($name, $value) |
111 | 112 | { |
112 | 113 | $setProperty = 'set'.$name; |
113 | - if(in_array($setProperty, $this->properties)) |
|
114 | - $this->$setProperty($value); |
|
115 | - else |
|
116 | - throw new Exception('Property '.$name.' can not be set.'); |
|
114 | + if(in_array($setProperty, $this->properties)) { |
|
115 | + $this->$setProperty($value); |
|
116 | + } else { |
|
117 | + throw new Exception('Property '.$name.' can not be set.'); |
|
118 | + } |
|
117 | 119 | } |
118 | 120 | |
119 | 121 | /** |
@@ -129,8 +131,9 @@ discard block |
||
129 | 131 | { |
130 | 132 | $this->properties = get_class_methods($this); |
131 | 133 | |
132 | - if(empty($data)) |
|
133 | - throw new Exception('Please provide the ICU data to initialize.'); |
|
134 | + if(empty($data)) { |
|
135 | + throw new Exception('Please provide the ICU data to initialize.'); |
|
136 | + } |
|
134 | 137 | |
135 | 138 | $this->data = $data; |
136 | 139 | } |
@@ -169,14 +172,13 @@ discard block |
||
169 | 172 | static function getInstance($culture=null) |
170 | 173 | { |
171 | 174 | |
172 | - if ($culture instanceof CultureInfo) |
|
173 | - return $culture->getDateTimeFormat(); |
|
174 | - else if(is_string($culture)) |
|
175 | + if ($culture instanceof CultureInfo) { |
|
176 | + return $culture->getDateTimeFormat(); |
|
177 | + } else if(is_string($culture)) |
|
175 | 178 | { |
176 | 179 | $cultureInfo = CultureInfo::getInstance($culture); |
177 | 180 | return $cultureInfo->getDateTimeFormat(); |
178 | - } |
|
179 | - else |
|
181 | + } else |
|
180 | 182 | { |
181 | 183 | $cultureInfo = CultureInfo::getInvariantCulture(); |
182 | 184 | return $cultureInfo->getDateTimeFormat(); |
@@ -292,10 +294,11 @@ discard block |
||
292 | 294 | */ |
293 | 295 | function getAbbreviatedMonthNames() |
294 | 296 | { |
295 | - if (isset($this->data['monthNames']['format']['abbreviated'])) |
|
296 | - return $this->data['monthNames']['format']['abbreviated']; |
|
297 | - else |
|
298 | - return $this->data['monthNames']['format']['wide']; |
|
297 | + if (isset($this->data['monthNames']['format']['abbreviated'])) { |
|
298 | + return $this->data['monthNames']['format']['abbreviated']; |
|
299 | + } else { |
|
300 | + return $this->data['monthNames']['format']['wide']; |
|
301 | + } |
|
299 | 302 | } |
300 | 303 | |
301 | 304 | /** |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | * _read |
87 | 87 | * |
88 | 88 | * @access private |
89 | - * @return mixed |
|
89 | + * @return string|null |
|
90 | 90 | * @param int $bytes |
91 | 91 | */ |
92 | 92 | function _read($bytes = 1) |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | * Load MO file |
166 | 166 | * |
167 | 167 | * @access public |
168 | - * @return mixed Returns true on success or PEAR_Error on failure. |
|
168 | + * @return boolean Returns true on success or PEAR_Error on failure. |
|
169 | 169 | * @param string $file |
170 | 170 | */ |
171 | 171 | function load($file = null) |
@@ -261,7 +261,7 @@ discard block |
||
261 | 261 | * Save MO file |
262 | 262 | * |
263 | 263 | * @access public |
264 | - * @return mixed Returns true on success or PEAR_Error on failure. |
|
264 | + * @return boolean Returns true on success or PEAR_Error on failure. |
|
265 | 265 | * @param string $file |
266 | 266 | */ |
267 | 267 | function save($file = null) |
@@ -1,20 +1,20 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * TGettext_MO class file. |
|
4 | - * |
|
5 | - * This program is free software; you can redistribute it and/or modify |
|
6 | - * it under the terms of the BSD License. |
|
7 | - * |
|
8 | - * Copyright(c) 2004 by Qiang Xue. All rights reserved. |
|
9 | - * |
|
10 | - * To contact the author write to {@link mailto:[email protected] Qiang Xue} |
|
11 | - * The latest version of PRADO can be obtained from: |
|
12 | - * {@link http://prado.sourceforge.net/} |
|
13 | - * |
|
14 | - * @author Wei Zhuo <weizhuo[at]gmail[dot]com> |
|
15 | - * @version $Revision: 1.3 $ $Date: 2005/08/27 03:21:12 $ |
|
16 | - * @package System.I18N.core |
|
17 | - */ |
|
3 | + * TGettext_MO class file. |
|
4 | + * |
|
5 | + * This program is free software; you can redistribute it and/or modify |
|
6 | + * it under the terms of the BSD License. |
|
7 | + * |
|
8 | + * Copyright(c) 2004 by Qiang Xue. All rights reserved. |
|
9 | + * |
|
10 | + * To contact the author write to {@link mailto:[email protected] Qiang Xue} |
|
11 | + * The latest version of PRADO can be obtained from: |
|
12 | + * {@link http://prado.sourceforge.net/} |
|
13 | + * |
|
14 | + * @author Wei Zhuo <weizhuo[at]gmail[dot]com> |
|
15 | + * @version $Revision: 1.3 $ $Date: 2005/08/27 03:21:12 $ |
|
16 | + * @package System.I18N.core |
|
17 | + */ |
|
18 | 18 | |
19 | 19 | |
20 | 20 | // +----------------------------------------------------------------------+ |
@@ -52,304 +52,304 @@ discard block |
||
52 | 52 | */ |
53 | 53 | class TGettext_MO extends TGettext |
54 | 54 | { |
55 | - /** |
|
56 | - * file handle |
|
57 | - * |
|
58 | - * @access private |
|
59 | - * @var resource |
|
60 | - */ |
|
61 | - protected $_handle = null; |
|
62 | - |
|
63 | - /** |
|
64 | - * big endianess |
|
65 | - * |
|
66 | - * Whether to write with big endian byte order. |
|
67 | - * |
|
68 | - * @access public |
|
69 | - * @var bool |
|
70 | - */ |
|
71 | - protected $writeBigEndian = false; |
|
72 | - |
|
73 | - /** |
|
74 | - * Constructor |
|
75 | - * |
|
76 | - * @access public |
|
77 | - * @return object File_Gettext_MO |
|
78 | - * @param string $file path to GNU MO file |
|
79 | - */ |
|
80 | - function TGettext_MO($file = '') |
|
81 | - { |
|
82 | - $this->file = $file; |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * _read |
|
87 | - * |
|
88 | - * @access private |
|
89 | - * @return mixed |
|
90 | - * @param int $bytes |
|
91 | - */ |
|
92 | - function _read($bytes = 1) |
|
93 | - { |
|
94 | - if (0 < $bytes = abs($bytes)) { |
|
95 | - return fread($this->_handle, $bytes); |
|
96 | - } |
|
97 | - return null; |
|
98 | - } |
|
99 | - |
|
100 | - /** |
|
101 | - * _readInt |
|
102 | - * |
|
103 | - * @access private |
|
104 | - * @return int |
|
105 | - * @param bool $bigendian |
|
106 | - */ |
|
107 | - function _readInt($bigendian = false) |
|
108 | - { |
|
55 | + /** |
|
56 | + * file handle |
|
57 | + * |
|
58 | + * @access private |
|
59 | + * @var resource |
|
60 | + */ |
|
61 | + protected $_handle = null; |
|
62 | + |
|
63 | + /** |
|
64 | + * big endianess |
|
65 | + * |
|
66 | + * Whether to write with big endian byte order. |
|
67 | + * |
|
68 | + * @access public |
|
69 | + * @var bool |
|
70 | + */ |
|
71 | + protected $writeBigEndian = false; |
|
72 | + |
|
73 | + /** |
|
74 | + * Constructor |
|
75 | + * |
|
76 | + * @access public |
|
77 | + * @return object File_Gettext_MO |
|
78 | + * @param string $file path to GNU MO file |
|
79 | + */ |
|
80 | + function TGettext_MO($file = '') |
|
81 | + { |
|
82 | + $this->file = $file; |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * _read |
|
87 | + * |
|
88 | + * @access private |
|
89 | + * @return mixed |
|
90 | + * @param int $bytes |
|
91 | + */ |
|
92 | + function _read($bytes = 1) |
|
93 | + { |
|
94 | + if (0 < $bytes = abs($bytes)) { |
|
95 | + return fread($this->_handle, $bytes); |
|
96 | + } |
|
97 | + return null; |
|
98 | + } |
|
99 | + |
|
100 | + /** |
|
101 | + * _readInt |
|
102 | + * |
|
103 | + * @access private |
|
104 | + * @return int |
|
105 | + * @param bool $bigendian |
|
106 | + */ |
|
107 | + function _readInt($bigendian = false) |
|
108 | + { |
|
109 | 109 | //unpack returns a reference???? |
110 | 110 | $unpacked = unpack($bigendian ? 'N' : 'V', $this->_read(4)); |
111 | - return array_shift($unpacked); |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * _writeInt |
|
116 | - * |
|
117 | - * @access private |
|
118 | - * @return int |
|
119 | - * @param int $int |
|
120 | - */ |
|
121 | - function _writeInt($int) |
|
122 | - { |
|
123 | - return $this->_write(pack($this->writeBigEndian ? 'N' : 'V', (int) $int)); |
|
124 | - } |
|
125 | - |
|
126 | - /** |
|
127 | - * _write |
|
128 | - * |
|
129 | - * @access private |
|
130 | - * @return int |
|
131 | - * @param string $data |
|
132 | - */ |
|
133 | - function _write($data) |
|
134 | - { |
|
135 | - return fwrite($this->_handle, $data); |
|
136 | - } |
|
137 | - |
|
138 | - /** |
|
139 | - * _writeStr |
|
140 | - * |
|
141 | - * @access private |
|
142 | - * @return int |
|
143 | - * @param string $string |
|
144 | - */ |
|
145 | - function _writeStr($string) |
|
146 | - { |
|
147 | - return $this->_write($string . "\0"); |
|
148 | - } |
|
149 | - |
|
150 | - /** |
|
151 | - * _readStr |
|
152 | - * |
|
153 | - * @access private |
|
154 | - * @return string |
|
155 | - * @param array $params associative array with offset and length |
|
156 | - * of the string |
|
157 | - */ |
|
158 | - function _readStr($params) |
|
159 | - { |
|
160 | - fseek($this->_handle, $params['offset']); |
|
161 | - return $this->_read($params['length']); |
|
162 | - } |
|
163 | - |
|
164 | - /** |
|
165 | - * Load MO file |
|
166 | - * |
|
167 | - * @access public |
|
168 | - * @return mixed Returns true on success or PEAR_Error on failure. |
|
169 | - * @param string $file |
|
170 | - */ |
|
171 | - function load($file = null) |
|
172 | - { |
|
173 | - if (!isset($file)) { |
|
174 | - $file = $this->file; |
|
175 | - } |
|
176 | - |
|
177 | - // open MO file |
|
178 | - if (!is_resource($this->_handle = @fopen($file, 'rb'))) { |
|
179 | - return false; |
|
180 | - } |
|
181 | - // lock MO file shared |
|
182 | - if (!@flock($this->_handle, LOCK_SH)) { |
|
183 | - @fclose($this->_handle); |
|
184 | - return false; |
|
185 | - } |
|
186 | - |
|
187 | - // read (part of) magic number from MO file header and define endianess |
|
111 | + return array_shift($unpacked); |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * _writeInt |
|
116 | + * |
|
117 | + * @access private |
|
118 | + * @return int |
|
119 | + * @param int $int |
|
120 | + */ |
|
121 | + function _writeInt($int) |
|
122 | + { |
|
123 | + return $this->_write(pack($this->writeBigEndian ? 'N' : 'V', (int) $int)); |
|
124 | + } |
|
125 | + |
|
126 | + /** |
|
127 | + * _write |
|
128 | + * |
|
129 | + * @access private |
|
130 | + * @return int |
|
131 | + * @param string $data |
|
132 | + */ |
|
133 | + function _write($data) |
|
134 | + { |
|
135 | + return fwrite($this->_handle, $data); |
|
136 | + } |
|
137 | + |
|
138 | + /** |
|
139 | + * _writeStr |
|
140 | + * |
|
141 | + * @access private |
|
142 | + * @return int |
|
143 | + * @param string $string |
|
144 | + */ |
|
145 | + function _writeStr($string) |
|
146 | + { |
|
147 | + return $this->_write($string . "\0"); |
|
148 | + } |
|
149 | + |
|
150 | + /** |
|
151 | + * _readStr |
|
152 | + * |
|
153 | + * @access private |
|
154 | + * @return string |
|
155 | + * @param array $params associative array with offset and length |
|
156 | + * of the string |
|
157 | + */ |
|
158 | + function _readStr($params) |
|
159 | + { |
|
160 | + fseek($this->_handle, $params['offset']); |
|
161 | + return $this->_read($params['length']); |
|
162 | + } |
|
163 | + |
|
164 | + /** |
|
165 | + * Load MO file |
|
166 | + * |
|
167 | + * @access public |
|
168 | + * @return mixed Returns true on success or PEAR_Error on failure. |
|
169 | + * @param string $file |
|
170 | + */ |
|
171 | + function load($file = null) |
|
172 | + { |
|
173 | + if (!isset($file)) { |
|
174 | + $file = $this->file; |
|
175 | + } |
|
176 | + |
|
177 | + // open MO file |
|
178 | + if (!is_resource($this->_handle = @fopen($file, 'rb'))) { |
|
179 | + return false; |
|
180 | + } |
|
181 | + // lock MO file shared |
|
182 | + if (!@flock($this->_handle, LOCK_SH)) { |
|
183 | + @fclose($this->_handle); |
|
184 | + return false; |
|
185 | + } |
|
186 | + |
|
187 | + // read (part of) magic number from MO file header and define endianess |
|
188 | 188 | |
189 | 189 | //unpack returns a reference???? |
190 | 190 | $unpacked = unpack('c', $this->_read(4)); |
191 | - switch ($magic = array_shift($unpacked)) |
|
192 | - { |
|
193 | - case -34: |
|
194 | - $be = false; |
|
195 | - break; |
|
196 | - |
|
197 | - case -107: |
|
198 | - $be = true; |
|
199 | - break; |
|
200 | - |
|
201 | - default: |
|
202 | - return false; |
|
203 | - } |
|
204 | - |
|
205 | - // check file format revision - we currently only support 0 |
|
206 | - if (0 !== ($_rev = $this->_readInt($be))) { |
|
207 | - return false; |
|
208 | - } |
|
209 | - |
|
210 | - // count of strings in this file |
|
211 | - $count = $this->_readInt($be); |
|
212 | - |
|
213 | - // offset of hashing table of the msgids |
|
214 | - $offset_original = $this->_readInt($be); |
|
215 | - // offset of hashing table of the msgstrs |
|
216 | - $offset_translat = $this->_readInt($be); |
|
217 | - |
|
218 | - // move to msgid hash table |
|
219 | - fseek($this->_handle, $offset_original); |
|
220 | - // read lengths and offsets of msgids |
|
221 | - $original = array(); |
|
222 | - for ($i = 0; $i < $count; $i++) { |
|
223 | - $original[$i] = array( |
|
224 | - 'length' => $this->_readInt($be), |
|
225 | - 'offset' => $this->_readInt($be) |
|
226 | - ); |
|
227 | - } |
|
228 | - |
|
229 | - // move to msgstr hash table |
|
230 | - fseek($this->_handle, $offset_translat); |
|
231 | - // read lengths and offsets of msgstrs |
|
232 | - $translat = array(); |
|
233 | - for ($i = 0; $i < $count; $i++) { |
|
234 | - $translat[$i] = array( |
|
235 | - 'length' => $this->_readInt($be), |
|
236 | - 'offset' => $this->_readInt($be) |
|
237 | - ); |
|
238 | - } |
|
239 | - |
|
240 | - // read all |
|
241 | - for ($i = 0; $i < $count; $i++) { |
|
242 | - $this->strings[$this->_readStr($original[$i])] = |
|
243 | - $this->_readStr($translat[$i]); |
|
244 | - } |
|
245 | - |
|
246 | - // done |
|
247 | - @flock($this->_handle, LOCK_UN); |
|
248 | - @fclose($this->_handle); |
|
249 | - $this->_handle = null; |
|
250 | - |
|
251 | - // check for meta info |
|
252 | - if (isset($this->strings[''])) { |
|
253 | - $this->meta = parent::meta2array($this->strings['']); |
|
254 | - unset($this->strings['']); |
|
255 | - } |
|
256 | - |
|
257 | - return true; |
|
258 | - } |
|
259 | - |
|
260 | - /** |
|
261 | - * Save MO file |
|
262 | - * |
|
263 | - * @access public |
|
264 | - * @return mixed Returns true on success or PEAR_Error on failure. |
|
265 | - * @param string $file |
|
266 | - */ |
|
267 | - function save($file = null) |
|
268 | - { |
|
269 | - if (!isset($file)) { |
|
270 | - $file = $this->file; |
|
271 | - } |
|
272 | - |
|
273 | - // open MO file |
|
274 | - if (!is_resource($this->_handle = @fopen($file, 'wb'))) { |
|
275 | - return false; |
|
276 | - } |
|
277 | - // lock MO file exclusively |
|
278 | - if (!@flock($this->_handle, LOCK_EX)) { |
|
279 | - @fclose($this->_handle); |
|
280 | - return false; |
|
281 | - } |
|
282 | - |
|
283 | - // write magic number |
|
284 | - if ($this->writeBigEndian) { |
|
285 | - $this->_write(pack('c*', 0x95, 0x04, 0x12, 0xde)); |
|
286 | - } else { |
|
287 | - $this->_write(pack('c*', 0xde, 0x12, 0x04, 0x95)); |
|
288 | - } |
|
289 | - |
|
290 | - // write file format revision |
|
291 | - $this->_writeInt(0); |
|
292 | - |
|
293 | - $count = count($this->strings) + ($meta = (count($this->meta) ? 1 : 0)); |
|
294 | - // write count of strings |
|
295 | - $this->_writeInt($count); |
|
296 | - |
|
297 | - $offset = 28; |
|
298 | - // write offset of orig. strings hash table |
|
299 | - $this->_writeInt($offset); |
|
300 | - |
|
301 | - $offset += ($count * 8); |
|
302 | - // write offset transl. strings hash table |
|
303 | - $this->_writeInt($offset); |
|
304 | - |
|
305 | - // write size of hash table (we currently ommit the hash table) |
|
306 | - $this->_writeInt(0); |
|
307 | - |
|
308 | - $offset += ($count * 8); |
|
309 | - // write offset of hash table |
|
310 | - $this->_writeInt($offset); |
|
311 | - |
|
312 | - // unshift meta info |
|
313 | - if ($this->meta) { |
|
314 | - $meta = ''; |
|
315 | - foreach ($this->meta as $key => $val) { |
|
316 | - $meta .= $key . ': ' . $val . "\n"; |
|
317 | - } |
|
318 | - $strings = array('' => $meta) + $this->strings; |
|
319 | - } else { |
|
320 | - $strings = $this->strings; |
|
321 | - } |
|
322 | - |
|
323 | - // write offsets for original strings |
|
324 | - foreach (array_keys($strings) as $o) { |
|
325 | - $len = strlen($o); |
|
326 | - $this->_writeInt($len); |
|
327 | - $this->_writeInt($offset); |
|
328 | - $offset += $len + 1; |
|
329 | - } |
|
330 | - |
|
331 | - // write offsets for translated strings |
|
332 | - foreach ($strings as $t) { |
|
333 | - $len = strlen($t); |
|
334 | - $this->_writeInt($len); |
|
335 | - $this->_writeInt($offset); |
|
336 | - $offset += $len + 1; |
|
337 | - } |
|
338 | - |
|
339 | - // write original strings |
|
340 | - foreach (array_keys($strings) as $o) { |
|
341 | - $this->_writeStr($o); |
|
342 | - } |
|
343 | - |
|
344 | - // write translated strings |
|
345 | - foreach ($strings as $t) { |
|
346 | - $this->_writeStr($t); |
|
347 | - } |
|
348 | - |
|
349 | - // done |
|
350 | - @flock($this->_handle, LOCK_UN); |
|
351 | - @fclose($this->_handle); |
|
352 | - chmod($file,PRADO_CHMOD); |
|
353 | - return true; |
|
354 | - } |
|
191 | + switch ($magic = array_shift($unpacked)) |
|
192 | + { |
|
193 | + case -34: |
|
194 | + $be = false; |
|
195 | + break; |
|
196 | + |
|
197 | + case -107: |
|
198 | + $be = true; |
|
199 | + break; |
|
200 | + |
|
201 | + default: |
|
202 | + return false; |
|
203 | + } |
|
204 | + |
|
205 | + // check file format revision - we currently only support 0 |
|
206 | + if (0 !== ($_rev = $this->_readInt($be))) { |
|
207 | + return false; |
|
208 | + } |
|
209 | + |
|
210 | + // count of strings in this file |
|
211 | + $count = $this->_readInt($be); |
|
212 | + |
|
213 | + // offset of hashing table of the msgids |
|
214 | + $offset_original = $this->_readInt($be); |
|
215 | + // offset of hashing table of the msgstrs |
|
216 | + $offset_translat = $this->_readInt($be); |
|
217 | + |
|
218 | + // move to msgid hash table |
|
219 | + fseek($this->_handle, $offset_original); |
|
220 | + // read lengths and offsets of msgids |
|
221 | + $original = array(); |
|
222 | + for ($i = 0; $i < $count; $i++) { |
|
223 | + $original[$i] = array( |
|
224 | + 'length' => $this->_readInt($be), |
|
225 | + 'offset' => $this->_readInt($be) |
|
226 | + ); |
|
227 | + } |
|
228 | + |
|
229 | + // move to msgstr hash table |
|
230 | + fseek($this->_handle, $offset_translat); |
|
231 | + // read lengths and offsets of msgstrs |
|
232 | + $translat = array(); |
|
233 | + for ($i = 0; $i < $count; $i++) { |
|
234 | + $translat[$i] = array( |
|
235 | + 'length' => $this->_readInt($be), |
|
236 | + 'offset' => $this->_readInt($be) |
|
237 | + ); |
|
238 | + } |
|
239 | + |
|
240 | + // read all |
|
241 | + for ($i = 0; $i < $count; $i++) { |
|
242 | + $this->strings[$this->_readStr($original[$i])] = |
|
243 | + $this->_readStr($translat[$i]); |
|
244 | + } |
|
245 | + |
|
246 | + // done |
|
247 | + @flock($this->_handle, LOCK_UN); |
|
248 | + @fclose($this->_handle); |
|
249 | + $this->_handle = null; |
|
250 | + |
|
251 | + // check for meta info |
|
252 | + if (isset($this->strings[''])) { |
|
253 | + $this->meta = parent::meta2array($this->strings['']); |
|
254 | + unset($this->strings['']); |
|
255 | + } |
|
256 | + |
|
257 | + return true; |
|
258 | + } |
|
259 | + |
|
260 | + /** |
|
261 | + * Save MO file |
|
262 | + * |
|
263 | + * @access public |
|
264 | + * @return mixed Returns true on success or PEAR_Error on failure. |
|
265 | + * @param string $file |
|
266 | + */ |
|
267 | + function save($file = null) |
|
268 | + { |
|
269 | + if (!isset($file)) { |
|
270 | + $file = $this->file; |
|
271 | + } |
|
272 | + |
|
273 | + // open MO file |
|
274 | + if (!is_resource($this->_handle = @fopen($file, 'wb'))) { |
|
275 | + return false; |
|
276 | + } |
|
277 | + // lock MO file exclusively |
|
278 | + if (!@flock($this->_handle, LOCK_EX)) { |
|
279 | + @fclose($this->_handle); |
|
280 | + return false; |
|
281 | + } |
|
282 | + |
|
283 | + // write magic number |
|
284 | + if ($this->writeBigEndian) { |
|
285 | + $this->_write(pack('c*', 0x95, 0x04, 0x12, 0xde)); |
|
286 | + } else { |
|
287 | + $this->_write(pack('c*', 0xde, 0x12, 0x04, 0x95)); |
|
288 | + } |
|
289 | + |
|
290 | + // write file format revision |
|
291 | + $this->_writeInt(0); |
|
292 | + |
|
293 | + $count = count($this->strings) + ($meta = (count($this->meta) ? 1 : 0)); |
|
294 | + // write count of strings |
|
295 | + $this->_writeInt($count); |
|
296 | + |
|
297 | + $offset = 28; |
|
298 | + // write offset of orig. strings hash table |
|
299 | + $this->_writeInt($offset); |
|
300 | + |
|
301 | + $offset += ($count * 8); |
|
302 | + // write offset transl. strings hash table |
|
303 | + $this->_writeInt($offset); |
|
304 | + |
|
305 | + // write size of hash table (we currently ommit the hash table) |
|
306 | + $this->_writeInt(0); |
|
307 | + |
|
308 | + $offset += ($count * 8); |
|
309 | + // write offset of hash table |
|
310 | + $this->_writeInt($offset); |
|
311 | + |
|
312 | + // unshift meta info |
|
313 | + if ($this->meta) { |
|
314 | + $meta = ''; |
|
315 | + foreach ($this->meta as $key => $val) { |
|
316 | + $meta .= $key . ': ' . $val . "\n"; |
|
317 | + } |
|
318 | + $strings = array('' => $meta) + $this->strings; |
|
319 | + } else { |
|
320 | + $strings = $this->strings; |
|
321 | + } |
|
322 | + |
|
323 | + // write offsets for original strings |
|
324 | + foreach (array_keys($strings) as $o) { |
|
325 | + $len = strlen($o); |
|
326 | + $this->_writeInt($len); |
|
327 | + $this->_writeInt($offset); |
|
328 | + $offset += $len + 1; |
|
329 | + } |
|
330 | + |
|
331 | + // write offsets for translated strings |
|
332 | + foreach ($strings as $t) { |
|
333 | + $len = strlen($t); |
|
334 | + $this->_writeInt($len); |
|
335 | + $this->_writeInt($offset); |
|
336 | + $offset += $len + 1; |
|
337 | + } |
|
338 | + |
|
339 | + // write original strings |
|
340 | + foreach (array_keys($strings) as $o) { |
|
341 | + $this->_writeStr($o); |
|
342 | + } |
|
343 | + |
|
344 | + // write translated strings |
|
345 | + foreach ($strings as $t) { |
|
346 | + $this->_writeStr($t); |
|
347 | + } |
|
348 | + |
|
349 | + // done |
|
350 | + @flock($this->_handle, LOCK_UN); |
|
351 | + @fclose($this->_handle); |
|
352 | + chmod($file,PRADO_CHMOD); |
|
353 | + return true; |
|
354 | + } |
|
355 | 355 | } |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | * @license PHP License |
39 | 39 | */ |
40 | 40 | |
41 | -require_once dirname(__FILE__).'/TGettext.php'; |
|
41 | +require_once dirname(__FILE__) . '/TGettext.php'; |
|
42 | 42 | |
43 | 43 | /** |
44 | 44 | * File_Gettext_MO |
@@ -349,7 +349,7 @@ discard block |
||
349 | 349 | // done |
350 | 350 | @flock($this->_handle, LOCK_UN); |
351 | 351 | @fclose($this->_handle); |
352 | - chmod($file,PRADO_CHMOD); |
|
352 | + chmod($file, PRADO_CHMOD); |
|
353 | 353 | return true; |
354 | 354 | } |
355 | 355 | } |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | * Load PO file |
68 | 68 | * |
69 | 69 | * @access public |
70 | - * @return mixed Returns true on success or PEAR_Error on failure. |
|
70 | + * @return boolean Returns true on success or PEAR_Error on failure. |
|
71 | 71 | * @param string $file |
72 | 72 | */ |
73 | 73 | function load($file = null) |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | * Save PO file |
117 | 117 | * |
118 | 118 | * @access public |
119 | - * @return mixed Returns true on success or PEAR_Error on failure. |
|
119 | + * @return boolean Returns true on success or PEAR_Error on failure. |
|
120 | 120 | * @param string $file |
121 | 121 | */ |
122 | 122 | function save($file = null) |
@@ -1,20 +1,20 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * TGettext_PO class file. |
|
4 | - * |
|
5 | - * This program is free software; you can redistribute it and/or modify |
|
6 | - * it under the terms of the BSD License. |
|
7 | - * |
|
8 | - * Copyright(c) 2004 by Qiang Xue. All rights reserved. |
|
9 | - * |
|
10 | - * To contact the author write to {@link mailto:[email protected] Qiang Xue} |
|
11 | - * The latest version of PRADO can be obtained from: |
|
12 | - * {@link http://prado.sourceforge.net/} |
|
13 | - * |
|
14 | - * @author Wei Zhuo <weizhuo[at]gmail[dot]com> |
|
15 | - * @version $Revision: 1.2 $ $Date: 2005/01/05 03:15:14 $ |
|
16 | - * @package System.I18N.core |
|
17 | - */ |
|
3 | + * TGettext_PO class file. |
|
4 | + * |
|
5 | + * This program is free software; you can redistribute it and/or modify |
|
6 | + * it under the terms of the BSD License. |
|
7 | + * |
|
8 | + * Copyright(c) 2004 by Qiang Xue. All rights reserved. |
|
9 | + * |
|
10 | + * To contact the author write to {@link mailto:[email protected] Qiang Xue} |
|
11 | + * The latest version of PRADO can be obtained from: |
|
12 | + * {@link http://prado.sourceforge.net/} |
|
13 | + * |
|
14 | + * @author Wei Zhuo <weizhuo[at]gmail[dot]com> |
|
15 | + * @version $Revision: 1.2 $ $Date: 2005/01/05 03:15:14 $ |
|
16 | + * @package System.I18N.core |
|
17 | + */ |
|
18 | 18 | |
19 | 19 | // +----------------------------------------------------------------------+ |
20 | 20 | // | PEAR :: File :: Gettext :: PO | |
@@ -51,110 +51,110 @@ discard block |
||
51 | 51 | */ |
52 | 52 | class TGettext_PO extends TGettext |
53 | 53 | { |
54 | - /** |
|
55 | - * Constructor |
|
56 | - * |
|
57 | - * @access public |
|
58 | - * @return object File_Gettext_PO |
|
59 | - * @param string path to GNU PO file |
|
60 | - */ |
|
61 | - function TGettext_PO($file = '') |
|
62 | - { |
|
63 | - $this->file = $file; |
|
64 | - } |
|
54 | + /** |
|
55 | + * Constructor |
|
56 | + * |
|
57 | + * @access public |
|
58 | + * @return object File_Gettext_PO |
|
59 | + * @param string path to GNU PO file |
|
60 | + */ |
|
61 | + function TGettext_PO($file = '') |
|
62 | + { |
|
63 | + $this->file = $file; |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * Load PO file |
|
68 | - * |
|
69 | - * @access public |
|
70 | - * @return mixed Returns true on success or PEAR_Error on failure. |
|
71 | - * @param string $file |
|
72 | - */ |
|
73 | - function load($file = null) |
|
74 | - { |
|
75 | - if (!isset($file)) { |
|
76 | - $file = $this->file; |
|
77 | - } |
|
66 | + /** |
|
67 | + * Load PO file |
|
68 | + * |
|
69 | + * @access public |
|
70 | + * @return mixed Returns true on success or PEAR_Error on failure. |
|
71 | + * @param string $file |
|
72 | + */ |
|
73 | + function load($file = null) |
|
74 | + { |
|
75 | + if (!isset($file)) { |
|
76 | + $file = $this->file; |
|
77 | + } |
|
78 | 78 | |
79 | - // load file |
|
80 | - if (!$contents = @file($file)) { |
|
81 | - return false; |
|
82 | - } |
|
83 | - $contents = implode('', $contents); |
|
79 | + // load file |
|
80 | + if (!$contents = @file($file)) { |
|
81 | + return false; |
|
82 | + } |
|
83 | + $contents = implode('', $contents); |
|
84 | 84 | |
85 | - // match all msgid/msgstr entries |
|
86 | - $matched = preg_match_all( |
|
87 | - '/(msgid\s+("([^"]|\\\\")*?"\s*)+)\s+' . |
|
88 | - '(msgstr\s+("([^"]|\\\\")*?"\s*)+)/', |
|
89 | - $contents, $matches |
|
90 | - ); |
|
91 | - unset($contents); |
|
85 | + // match all msgid/msgstr entries |
|
86 | + $matched = preg_match_all( |
|
87 | + '/(msgid\s+("([^"]|\\\\")*?"\s*)+)\s+' . |
|
88 | + '(msgstr\s+("([^"]|\\\\")*?"\s*)+)/', |
|
89 | + $contents, $matches |
|
90 | + ); |
|
91 | + unset($contents); |
|
92 | 92 | |
93 | - if (!$matched) { |
|
94 | - return false; |
|
95 | - } |
|
93 | + if (!$matched) { |
|
94 | + return false; |
|
95 | + } |
|
96 | 96 | |
97 | - // get all msgids and msgtrs |
|
98 | - for ($i = 0; $i < $matched; $i++) { |
|
99 | - $msgid = preg_replace( |
|
100 | - '/\s*msgid\s*"(.*)"\s*/s', '\\1', $matches[1][$i]); |
|
101 | - $msgstr= preg_replace( |
|
102 | - '/\s*msgstr\s*"(.*)"\s*/s', '\\1', $matches[4][$i]); |
|
103 | - $this->strings[parent::prepare($msgid)] = parent::prepare($msgstr); |
|
104 | - } |
|
97 | + // get all msgids and msgtrs |
|
98 | + for ($i = 0; $i < $matched; $i++) { |
|
99 | + $msgid = preg_replace( |
|
100 | + '/\s*msgid\s*"(.*)"\s*/s', '\\1', $matches[1][$i]); |
|
101 | + $msgstr= preg_replace( |
|
102 | + '/\s*msgstr\s*"(.*)"\s*/s', '\\1', $matches[4][$i]); |
|
103 | + $this->strings[parent::prepare($msgid)] = parent::prepare($msgstr); |
|
104 | + } |
|
105 | 105 | |
106 | - // check for meta info |
|
107 | - if (isset($this->strings[''])) { |
|
108 | - $this->meta = parent::meta2array($this->strings['']); |
|
109 | - unset($this->strings['']); |
|
110 | - } |
|
106 | + // check for meta info |
|
107 | + if (isset($this->strings[''])) { |
|
108 | + $this->meta = parent::meta2array($this->strings['']); |
|
109 | + unset($this->strings['']); |
|
110 | + } |
|
111 | 111 | |
112 | - return true; |
|
113 | - } |
|
112 | + return true; |
|
113 | + } |
|
114 | 114 | |
115 | - /** |
|
116 | - * Save PO file |
|
117 | - * |
|
118 | - * @access public |
|
119 | - * @return mixed Returns true on success or PEAR_Error on failure. |
|
120 | - * @param string $file |
|
121 | - */ |
|
122 | - function save($file = null) |
|
123 | - { |
|
124 | - if (!isset($file)) { |
|
125 | - $file = $this->file; |
|
126 | - } |
|
115 | + /** |
|
116 | + * Save PO file |
|
117 | + * |
|
118 | + * @access public |
|
119 | + * @return mixed Returns true on success or PEAR_Error on failure. |
|
120 | + * @param string $file |
|
121 | + */ |
|
122 | + function save($file = null) |
|
123 | + { |
|
124 | + if (!isset($file)) { |
|
125 | + $file = $this->file; |
|
126 | + } |
|
127 | 127 | |
128 | - // open PO file |
|
129 | - if (!is_resource($fh = @fopen($file, 'w'))) { |
|
130 | - return false; |
|
131 | - } |
|
128 | + // open PO file |
|
129 | + if (!is_resource($fh = @fopen($file, 'w'))) { |
|
130 | + return false; |
|
131 | + } |
|
132 | 132 | |
133 | - // lock PO file exclusively |
|
134 | - if (!flock($fh, LOCK_EX)) { |
|
135 | - fclose($fh); |
|
136 | - return false; |
|
137 | - } |
|
138 | - // write meta info |
|
139 | - if (count($this->meta)) { |
|
140 | - $meta = 'msgid ""' . "\nmsgstr " . '""' . "\n"; |
|
141 | - foreach ($this->meta as $k => $v) { |
|
142 | - $meta .= '"' . $k . ': ' . $v . '\n"' . "\n"; |
|
143 | - } |
|
144 | - fwrite($fh, $meta . "\n"); |
|
145 | - } |
|
146 | - // write strings |
|
147 | - foreach ($this->strings as $o => $t) { |
|
148 | - fwrite($fh, |
|
149 | - 'msgid "' . parent::prepare($o, true) . '"' . "\n" . |
|
150 | - 'msgstr "' . parent::prepare($t, true) . '"' . "\n\n" |
|
151 | - ); |
|
152 | - } |
|
133 | + // lock PO file exclusively |
|
134 | + if (!flock($fh, LOCK_EX)) { |
|
135 | + fclose($fh); |
|
136 | + return false; |
|
137 | + } |
|
138 | + // write meta info |
|
139 | + if (count($this->meta)) { |
|
140 | + $meta = 'msgid ""' . "\nmsgstr " . '""' . "\n"; |
|
141 | + foreach ($this->meta as $k => $v) { |
|
142 | + $meta .= '"' . $k . ': ' . $v . '\n"' . "\n"; |
|
143 | + } |
|
144 | + fwrite($fh, $meta . "\n"); |
|
145 | + } |
|
146 | + // write strings |
|
147 | + foreach ($this->strings as $o => $t) { |
|
148 | + fwrite($fh, |
|
149 | + 'msgid "' . parent::prepare($o, true) . '"' . "\n" . |
|
150 | + 'msgstr "' . parent::prepare($t, true) . '"' . "\n\n" |
|
151 | + ); |
|
152 | + } |
|
153 | 153 | |
154 | - //done |
|
155 | - @flock($fh, LOCK_UN); |
|
156 | - @fclose($fh); |
|
157 | - chmod($file,PRADO_CHMOD); |
|
158 | - return true; |
|
159 | - } |
|
154 | + //done |
|
155 | + @flock($fh, LOCK_UN); |
|
156 | + @fclose($fh); |
|
157 | + chmod($file,PRADO_CHMOD); |
|
158 | + return true; |
|
159 | + } |
|
160 | 160 | } |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | * @license PHP License |
38 | 38 | */ |
39 | 39 | |
40 | -require_once dirname(__FILE__).'/TGettext.php'; |
|
40 | +require_once dirname(__FILE__) . '/TGettext.php'; |
|
41 | 41 | |
42 | 42 | /** |
43 | 43 | * File_Gettext_PO |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | for ($i = 0; $i < $matched; $i++) { |
99 | 99 | $msgid = preg_replace( |
100 | 100 | '/\s*msgid\s*"(.*)"\s*/s', '\\1', $matches[1][$i]); |
101 | - $msgstr= preg_replace( |
|
101 | + $msgstr = preg_replace( |
|
102 | 102 | '/\s*msgstr\s*"(.*)"\s*/s', '\\1', $matches[4][$i]); |
103 | 103 | $this->strings[parent::prepare($msgid)] = parent::prepare($msgstr); |
104 | 104 | } |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | // write strings |
147 | 147 | foreach ($this->strings as $o => $t) { |
148 | 148 | fwrite($fh, |
149 | - 'msgid "' . parent::prepare($o, true) . '"' . "\n" . |
|
149 | + 'msgid "' . parent::prepare($o, true) . '"' . "\n" . |
|
150 | 150 | 'msgstr "' . parent::prepare($t, true) . '"' . "\n\n" |
151 | 151 | ); |
152 | 152 | } |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | //done |
155 | 155 | @flock($fh, LOCK_UN); |
156 | 156 | @fclose($fh); |
157 | - chmod($file,PRADO_CHMOD); |
|
157 | + chmod($file, PRADO_CHMOD); |
|
158 | 158 | return true; |
159 | 159 | } |
160 | 160 | } |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | * |
119 | 119 | * @static |
120 | 120 | * @access public |
121 | - * @return mixed Returns true on success or PEAR_Error on failure. |
|
121 | + * @return boolean Returns true on success or PEAR_Error on failure. |
|
122 | 122 | * @param string $pofile path to GNU PO file |
123 | 123 | * @param string $mofile path to GNU MO file |
124 | 124 | */ |
@@ -260,7 +260,7 @@ discard block |
||
260 | 260 | * toMO |
261 | 261 | * |
262 | 262 | * @access protected |
263 | - * @return object File_Gettext_MO |
|
263 | + * @return TGettext_MO File_Gettext_MO |
|
264 | 264 | */ |
265 | 265 | function toMO() |
266 | 266 | { |
@@ -274,7 +274,7 @@ discard block |
||
274 | 274 | * toPO |
275 | 275 | * |
276 | 276 | * @access protected |
277 | - * @return object File_Gettext_PO |
|
277 | + * @return TGettext_PO File_Gettext_PO |
|
278 | 278 | */ |
279 | 279 | function toPO() |
280 | 280 | { |
@@ -58,229 +58,229 @@ |
||
58 | 58 | */ |
59 | 59 | class TGettext |
60 | 60 | { |
61 | - /** |
|
62 | - * strings |
|
63 | - * |
|
64 | - * associative array with all [msgid => msgstr] entries |
|
65 | - * |
|
66 | - * @access protected |
|
67 | - * @var array |
|
68 | - */ |
|
69 | - protected $strings = array(); |
|
61 | + /** |
|
62 | + * strings |
|
63 | + * |
|
64 | + * associative array with all [msgid => msgstr] entries |
|
65 | + * |
|
66 | + * @access protected |
|
67 | + * @var array |
|
68 | + */ |
|
69 | + protected $strings = array(); |
|
70 | 70 | |
71 | - /** |
|
72 | - * meta |
|
73 | - * |
|
74 | - * associative array containing meta |
|
75 | - * information like project name or content type |
|
76 | - * |
|
77 | - * @access protected |
|
78 | - * @var array |
|
79 | - */ |
|
80 | - protected $meta = array(); |
|
71 | + /** |
|
72 | + * meta |
|
73 | + * |
|
74 | + * associative array containing meta |
|
75 | + * information like project name or content type |
|
76 | + * |
|
77 | + * @access protected |
|
78 | + * @var array |
|
79 | + */ |
|
80 | + protected $meta = array(); |
|
81 | 81 | |
82 | - /** |
|
83 | - * file path |
|
84 | - * |
|
85 | - * @access protected |
|
86 | - * @var string |
|
87 | - */ |
|
88 | - protected $file = ''; |
|
82 | + /** |
|
83 | + * file path |
|
84 | + * |
|
85 | + * @access protected |
|
86 | + * @var string |
|
87 | + */ |
|
88 | + protected $file = ''; |
|
89 | 89 | |
90 | - /** |
|
91 | - * Factory |
|
92 | - * |
|
93 | - * @static |
|
94 | - * @access public |
|
95 | - * @return object Returns File_Gettext_PO or File_Gettext_MO on success |
|
96 | - * or PEAR_Error on failure. |
|
97 | - * @param string $format MO or PO |
|
98 | - * @param string $file path to GNU gettext file |
|
99 | - */ |
|
100 | - static function factory($format, $file = '') |
|
101 | - { |
|
102 | - $format = strToUpper($format); |
|
103 | - $filename = dirname(__FILE__).'/'.$format.'.php'; |
|
104 | - if(is_file($filename) == false) |
|
105 | - throw new Exception ("Class file $file not found"); |
|
90 | + /** |
|
91 | + * Factory |
|
92 | + * |
|
93 | + * @static |
|
94 | + * @access public |
|
95 | + * @return object Returns File_Gettext_PO or File_Gettext_MO on success |
|
96 | + * or PEAR_Error on failure. |
|
97 | + * @param string $format MO or PO |
|
98 | + * @param string $file path to GNU gettext file |
|
99 | + */ |
|
100 | + static function factory($format, $file = '') |
|
101 | + { |
|
102 | + $format = strToUpper($format); |
|
103 | + $filename = dirname(__FILE__).'/'.$format.'.php'; |
|
104 | + if(is_file($filename) == false) |
|
105 | + throw new Exception ("Class file $file not found"); |
|
106 | 106 | |
107 | - include_once $filename; |
|
108 | - $class = 'TGettext_' . $format; |
|
107 | + include_once $filename; |
|
108 | + $class = 'TGettext_' . $format; |
|
109 | 109 | |
110 | - return new $class($file); |
|
111 | - } |
|
110 | + return new $class($file); |
|
111 | + } |
|
112 | 112 | |
113 | - /** |
|
114 | - * poFile2moFile |
|
115 | - * |
|
116 | - * That's a simple fake of the 'msgfmt' console command. It reads the |
|
117 | - * contents of a GNU PO file and saves them to a GNU MO file. |
|
118 | - * |
|
119 | - * @static |
|
120 | - * @access public |
|
121 | - * @return mixed Returns true on success or PEAR_Error on failure. |
|
122 | - * @param string $pofile path to GNU PO file |
|
123 | - * @param string $mofile path to GNU MO file |
|
124 | - */ |
|
125 | - static function poFile2moFile($pofile, $mofile) |
|
126 | - { |
|
127 | - if (!is_file($pofile)) { |
|
128 | - throw new Exception("File $pofile doesn't exist."); |
|
129 | - } |
|
113 | + /** |
|
114 | + * poFile2moFile |
|
115 | + * |
|
116 | + * That's a simple fake of the 'msgfmt' console command. It reads the |
|
117 | + * contents of a GNU PO file and saves them to a GNU MO file. |
|
118 | + * |
|
119 | + * @static |
|
120 | + * @access public |
|
121 | + * @return mixed Returns true on success or PEAR_Error on failure. |
|
122 | + * @param string $pofile path to GNU PO file |
|
123 | + * @param string $mofile path to GNU MO file |
|
124 | + */ |
|
125 | + static function poFile2moFile($pofile, $mofile) |
|
126 | + { |
|
127 | + if (!is_file($pofile)) { |
|
128 | + throw new Exception("File $pofile doesn't exist."); |
|
129 | + } |
|
130 | 130 | |
131 | - include_once dirname(__FILE__).'/PO.php'; |
|
131 | + include_once dirname(__FILE__).'/PO.php'; |
|
132 | 132 | |
133 | - $PO = new TGettext_PO($pofile); |
|
134 | - if (true !== ($e = $PO->load())) { |
|
135 | - return $e; |
|
136 | - } |
|
133 | + $PO = new TGettext_PO($pofile); |
|
134 | + if (true !== ($e = $PO->load())) { |
|
135 | + return $e; |
|
136 | + } |
|
137 | 137 | |
138 | - $MO = $PO->toMO(); |
|
139 | - if (true !== ($e = $MO->save($mofile))) { |
|
140 | - return $e; |
|
141 | - } |
|
142 | - unset($PO, $MO); |
|
138 | + $MO = $PO->toMO(); |
|
139 | + if (true !== ($e = $MO->save($mofile))) { |
|
140 | + return $e; |
|
141 | + } |
|
142 | + unset($PO, $MO); |
|
143 | 143 | |
144 | - return true; |
|
145 | - } |
|
144 | + return true; |
|
145 | + } |
|
146 | 146 | |
147 | - /** |
|
148 | - * prepare |
|
149 | - * |
|
150 | - * @static |
|
151 | - * @access protected |
|
152 | - * @return string |
|
153 | - * @param string $string |
|
154 | - * @param bool $reverse |
|
155 | - */ |
|
156 | - static function prepare($string, $reverse = false) |
|
157 | - { |
|
158 | - if ($reverse) { |
|
159 | - $smap = array('"', "\n", "\t", "\r"); |
|
160 | - $rmap = array('\"', '\\n"' . "\n" . '"', '\\t', '\\r'); |
|
161 | - return (string) str_replace($smap, $rmap, $string); |
|
162 | - } else { |
|
163 | - $string = preg_replace('/"\s+"/', '', $string); |
|
164 | - $smap = array('\\n', '\\r', '\\t', '\"'); |
|
165 | - $rmap = array("\n", "\r", "\t", '"'); |
|
166 | - return (string) str_replace($smap, $rmap, $string); |
|
167 | - } |
|
168 | - } |
|
147 | + /** |
|
148 | + * prepare |
|
149 | + * |
|
150 | + * @static |
|
151 | + * @access protected |
|
152 | + * @return string |
|
153 | + * @param string $string |
|
154 | + * @param bool $reverse |
|
155 | + */ |
|
156 | + static function prepare($string, $reverse = false) |
|
157 | + { |
|
158 | + if ($reverse) { |
|
159 | + $smap = array('"', "\n", "\t", "\r"); |
|
160 | + $rmap = array('\"', '\\n"' . "\n" . '"', '\\t', '\\r'); |
|
161 | + return (string) str_replace($smap, $rmap, $string); |
|
162 | + } else { |
|
163 | + $string = preg_replace('/"\s+"/', '', $string); |
|
164 | + $smap = array('\\n', '\\r', '\\t', '\"'); |
|
165 | + $rmap = array("\n", "\r", "\t", '"'); |
|
166 | + return (string) str_replace($smap, $rmap, $string); |
|
167 | + } |
|
168 | + } |
|
169 | 169 | |
170 | - /** |
|
171 | - * meta2array |
|
172 | - * |
|
173 | - * @static |
|
174 | - * @access public |
|
175 | - * @return array |
|
176 | - * @param string $meta |
|
177 | - */ |
|
178 | - static function meta2array($meta) |
|
179 | - { |
|
180 | - $array = array(); |
|
181 | - foreach (explode("\n", $meta) as $info) { |
|
182 | - if ($info = trim($info)) { |
|
183 | - list($key, $value) = explode(':', $info, 2); |
|
184 | - $array[trim($key)] = trim($value); |
|
185 | - } |
|
186 | - } |
|
187 | - return $array; |
|
188 | - } |
|
170 | + /** |
|
171 | + * meta2array |
|
172 | + * |
|
173 | + * @static |
|
174 | + * @access public |
|
175 | + * @return array |
|
176 | + * @param string $meta |
|
177 | + */ |
|
178 | + static function meta2array($meta) |
|
179 | + { |
|
180 | + $array = array(); |
|
181 | + foreach (explode("\n", $meta) as $info) { |
|
182 | + if ($info = trim($info)) { |
|
183 | + list($key, $value) = explode(':', $info, 2); |
|
184 | + $array[trim($key)] = trim($value); |
|
185 | + } |
|
186 | + } |
|
187 | + return $array; |
|
188 | + } |
|
189 | 189 | |
190 | - /** |
|
191 | - * toArray |
|
192 | - * |
|
193 | - * Returns meta info and strings as an array of a structure like that: |
|
194 | - * <code> |
|
195 | - * array( |
|
196 | - * 'meta' => array( |
|
197 | - * 'Content-Type' => 'text/plain; charset=iso-8859-1', |
|
198 | - * 'Last-Translator' => 'Michael Wallner <[email protected]>', |
|
199 | - * 'PO-Revision-Date' => '2004-07-21 17:03+0200', |
|
200 | - * 'Language-Team' => 'German <[email protected]>', |
|
201 | - * ), |
|
202 | - * 'strings' => array( |
|
203 | - * 'All rights reserved' => 'Alle Rechte vorbehalten', |
|
204 | - * 'Welcome' => 'Willkommen', |
|
205 | - * // ... |
|
206 | - * ) |
|
207 | - * ) |
|
208 | - * </code> |
|
209 | - * |
|
210 | - * @see fromArray() |
|
211 | - * @access protected |
|
212 | - * @return array |
|
213 | - */ |
|
214 | - function toArray() |
|
215 | - { |
|
216 | - return array('meta' => $this->meta, 'strings' => $this->strings); |
|
217 | - } |
|
190 | + /** |
|
191 | + * toArray |
|
192 | + * |
|
193 | + * Returns meta info and strings as an array of a structure like that: |
|
194 | + * <code> |
|
195 | + * array( |
|
196 | + * 'meta' => array( |
|
197 | + * 'Content-Type' => 'text/plain; charset=iso-8859-1', |
|
198 | + * 'Last-Translator' => 'Michael Wallner <[email protected]>', |
|
199 | + * 'PO-Revision-Date' => '2004-07-21 17:03+0200', |
|
200 | + * 'Language-Team' => 'German <[email protected]>', |
|
201 | + * ), |
|
202 | + * 'strings' => array( |
|
203 | + * 'All rights reserved' => 'Alle Rechte vorbehalten', |
|
204 | + * 'Welcome' => 'Willkommen', |
|
205 | + * // ... |
|
206 | + * ) |
|
207 | + * ) |
|
208 | + * </code> |
|
209 | + * |
|
210 | + * @see fromArray() |
|
211 | + * @access protected |
|
212 | + * @return array |
|
213 | + */ |
|
214 | + function toArray() |
|
215 | + { |
|
216 | + return array('meta' => $this->meta, 'strings' => $this->strings); |
|
217 | + } |
|
218 | 218 | |
219 | - /** |
|
220 | - * fromArray |
|
221 | - * |
|
222 | - * Assigns meta info and strings from an array of a structure like that: |
|
223 | - * <code> |
|
224 | - * array( |
|
225 | - * 'meta' => array( |
|
226 | - * 'Content-Type' => 'text/plain; charset=iso-8859-1', |
|
227 | - * 'Last-Translator' => 'Michael Wallner <[email protected]>', |
|
228 | - * 'PO-Revision-Date' => date('Y-m-d H:iO'), |
|
229 | - * 'Language-Team' => 'German <[email protected]>', |
|
230 | - * ), |
|
231 | - * 'strings' => array( |
|
232 | - * 'All rights reserved' => 'Alle Rechte vorbehalten', |
|
233 | - * 'Welcome' => 'Willkommen', |
|
234 | - * // ... |
|
235 | - * ) |
|
236 | - * ) |
|
237 | - * </code> |
|
238 | - * |
|
239 | - * @see toArray() |
|
240 | - * @access protected |
|
241 | - * @return bool |
|
242 | - * @param array $array |
|
243 | - */ |
|
244 | - function fromArray($array) |
|
245 | - { |
|
246 | - if (!array_key_exists('strings', $array)) { |
|
247 | - if (count($array) != 2) { |
|
248 | - return false; |
|
249 | - } else { |
|
250 | - list($this->meta, $this->strings) = $array; |
|
251 | - } |
|
252 | - } else { |
|
253 | - $this->meta = @$array['meta']; |
|
254 | - $this->strings = @$array['strings']; |
|
255 | - } |
|
256 | - return true; |
|
257 | - } |
|
219 | + /** |
|
220 | + * fromArray |
|
221 | + * |
|
222 | + * Assigns meta info and strings from an array of a structure like that: |
|
223 | + * <code> |
|
224 | + * array( |
|
225 | + * 'meta' => array( |
|
226 | + * 'Content-Type' => 'text/plain; charset=iso-8859-1', |
|
227 | + * 'Last-Translator' => 'Michael Wallner <[email protected]>', |
|
228 | + * 'PO-Revision-Date' => date('Y-m-d H:iO'), |
|
229 | + * 'Language-Team' => 'German <[email protected]>', |
|
230 | + * ), |
|
231 | + * 'strings' => array( |
|
232 | + * 'All rights reserved' => 'Alle Rechte vorbehalten', |
|
233 | + * 'Welcome' => 'Willkommen', |
|
234 | + * // ... |
|
235 | + * ) |
|
236 | + * ) |
|
237 | + * </code> |
|
238 | + * |
|
239 | + * @see toArray() |
|
240 | + * @access protected |
|
241 | + * @return bool |
|
242 | + * @param array $array |
|
243 | + */ |
|
244 | + function fromArray($array) |
|
245 | + { |
|
246 | + if (!array_key_exists('strings', $array)) { |
|
247 | + if (count($array) != 2) { |
|
248 | + return false; |
|
249 | + } else { |
|
250 | + list($this->meta, $this->strings) = $array; |
|
251 | + } |
|
252 | + } else { |
|
253 | + $this->meta = @$array['meta']; |
|
254 | + $this->strings = @$array['strings']; |
|
255 | + } |
|
256 | + return true; |
|
257 | + } |
|
258 | 258 | |
259 | - /** |
|
260 | - * toMO |
|
261 | - * |
|
262 | - * @access protected |
|
263 | - * @return object File_Gettext_MO |
|
264 | - */ |
|
265 | - function toMO() |
|
266 | - { |
|
267 | - include_once dirname(__FILE__).'/MO.php'; |
|
268 | - $MO = new TGettext_MO; |
|
269 | - $MO->fromArray($this->toArray()); |
|
270 | - return $MO; |
|
271 | - } |
|
259 | + /** |
|
260 | + * toMO |
|
261 | + * |
|
262 | + * @access protected |
|
263 | + * @return object File_Gettext_MO |
|
264 | + */ |
|
265 | + function toMO() |
|
266 | + { |
|
267 | + include_once dirname(__FILE__).'/MO.php'; |
|
268 | + $MO = new TGettext_MO; |
|
269 | + $MO->fromArray($this->toArray()); |
|
270 | + return $MO; |
|
271 | + } |
|
272 | 272 | |
273 | - /** |
|
274 | - * toPO |
|
275 | - * |
|
276 | - * @access protected |
|
277 | - * @return object File_Gettext_PO |
|
278 | - */ |
|
279 | - function toPO() |
|
280 | - { |
|
281 | - include_once dirname(__FILE__).'/PO.php'; |
|
282 | - $PO = new TGettext_PO; |
|
283 | - $PO->fromArray($this->toArray()); |
|
284 | - return $PO; |
|
285 | - } |
|
273 | + /** |
|
274 | + * toPO |
|
275 | + * |
|
276 | + * @access protected |
|
277 | + * @return object File_Gettext_PO |
|
278 | + */ |
|
279 | + function toPO() |
|
280 | + { |
|
281 | + include_once dirname(__FILE__).'/PO.php'; |
|
282 | + $PO = new TGettext_PO; |
|
283 | + $PO->fromArray($this->toArray()); |
|
284 | + return $PO; |
|
285 | + } |
|
286 | 286 | } |
@@ -100,9 +100,9 @@ discard block |
||
100 | 100 | static function factory($format, $file = '') |
101 | 101 | { |
102 | 102 | $format = strToUpper($format); |
103 | - $filename = dirname(__FILE__).'/'.$format.'.php'; |
|
104 | - if(is_file($filename) == false) |
|
105 | - throw new Exception ("Class file $file not found"); |
|
103 | + $filename = dirname(__FILE__) . '/' . $format . '.php'; |
|
104 | + if (is_file($filename) == false) |
|
105 | + throw new Exception("Class file $file not found"); |
|
106 | 106 | |
107 | 107 | include_once $filename; |
108 | 108 | $class = 'TGettext_' . $format; |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | throw new Exception("File $pofile doesn't exist."); |
129 | 129 | } |
130 | 130 | |
131 | - include_once dirname(__FILE__).'/PO.php'; |
|
131 | + include_once dirname(__FILE__) . '/PO.php'; |
|
132 | 132 | |
133 | 133 | $PO = new TGettext_PO($pofile); |
134 | 134 | if (true !== ($e = $PO->load())) { |
@@ -264,7 +264,7 @@ discard block |
||
264 | 264 | */ |
265 | 265 | function toMO() |
266 | 266 | { |
267 | - include_once dirname(__FILE__).'/MO.php'; |
|
267 | + include_once dirname(__FILE__) . '/MO.php'; |
|
268 | 268 | $MO = new TGettext_MO; |
269 | 269 | $MO->fromArray($this->toArray()); |
270 | 270 | return $MO; |
@@ -278,7 +278,7 @@ discard block |
||
278 | 278 | */ |
279 | 279 | function toPO() |
280 | 280 | { |
281 | - include_once dirname(__FILE__).'/PO.php'; |
|
281 | + include_once dirname(__FILE__) . '/PO.php'; |
|
282 | 282 | $PO = new TGettext_PO; |
283 | 283 | $PO->fromArray($this->toArray()); |
284 | 284 | return $PO; |
@@ -101,8 +101,9 @@ |
||
101 | 101 | { |
102 | 102 | $format = strToUpper($format); |
103 | 103 | $filename = dirname(__FILE__).'/'.$format.'.php'; |
104 | - if(is_file($filename) == false) |
|
105 | - throw new Exception ("Class file $file not found"); |
|
104 | + if(is_file($filename) == false) { |
|
105 | + throw new Exception ("Class file $file not found"); |
|
106 | + } |
|
106 | 107 | |
107 | 108 | include_once $filename; |
108 | 109 | $class = 'TGettext_' . $format; |
@@ -109,6 +109,7 @@ |
||
109 | 109 | /** |
110 | 110 | * Set the culture for this particular message source. |
111 | 111 | * @param string the Culture name. |
112 | + * @return void |
|
112 | 113 | */ |
113 | 114 | function setCulture($culture); |
114 | 115 |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | * @param string the catalogue to add to |
73 | 73 | * @return boolean true if saved successfuly, false otherwise. |
74 | 74 | */ |
75 | - function save($catalogue='messages'); |
|
75 | + function save($catalogue = 'messages'); |
|
76 | 76 | |
77 | 77 | /** |
78 | 78 | * Add a untranslated message to the source. Need to call save() |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | * @param string the catalogue to delete from. |
89 | 89 | * @return boolean true if deleted, false otherwise. |
90 | 90 | */ |
91 | - function delete($message, $catalogue='messages'); |
|
91 | + function delete($message, $catalogue = 'messages'); |
|
92 | 92 | |
93 | 93 | /** |
94 | 94 | * Update the translation. |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | * @param string the catalogue of the translation. |
99 | 99 | * @return boolean true if translation was updated, false otherwise. |
100 | 100 | */ |
101 | - function update($text, $target, $comments, $catalogue='messages'); |
|
101 | + function update($text, $target, $comments, $catalogue = 'messages'); |
|
102 | 102 | |
103 | 103 | /** |
104 | 104 | * Returns a list of catalogue as key and all it variants as value. |
@@ -99,9 +99,7 @@ |
||
99 | 99 | * Get the data from the cache. |
100 | 100 | * @param string $catalogue The translation section. |
101 | 101 | * @param string $culture The translation locale, e.g. "en_AU". |
102 | - * @param string $filename If the source is a file, this file's modified |
|
103 | - * time is newer than the cache's modified time, no cache hit. |
|
104 | - * @return mixed Boolean FALSE if no cache hit. Otherwise, translation |
|
102 | + * @return false|string Boolean FALSE if no cache hit. Otherwise, translation |
|
105 | 103 | * table data for the specified section and locale. |
106 | 104 | */ |
107 | 105 | public function get($catalogue, $culture, $lastmodified=0) |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | /** |
9 | 9 | * Load the cache lite library. |
10 | 10 | */ |
11 | -require_once(dirname(__FILE__).'/TCache_Lite.php'); |
|
11 | +require_once(dirname(__FILE__) . '/TCache_Lite.php'); |
|
12 | 12 | |
13 | 13 | /** |
14 | 14 | * Cache the translation table into the file system. |
@@ -37,15 +37,15 @@ discard block |
||
37 | 37 | */ |
38 | 38 | public function __construct($cacheDir) |
39 | 39 | { |
40 | - $cacheDir = $cacheDir.'/'; |
|
40 | + $cacheDir = $cacheDir . '/'; |
|
41 | 41 | |
42 | - if(!is_dir($cacheDir)) |
|
42 | + if (!is_dir($cacheDir)) |
|
43 | 43 | throw new Exception( |
44 | - 'The cache directory '.$cacheDir.' does not exists.'. |
|
44 | + 'The cache directory ' . $cacheDir . ' does not exists.' . |
|
45 | 45 | 'The cache directory must be writable by the server.'); |
46 | - if(!is_writable($cacheDir)) |
|
46 | + if (!is_writable($cacheDir)) |
|
47 | 47 | throw new Exception( |
48 | - 'The cache directory '.$cacheDir.' must be writable '. |
|
48 | + 'The cache directory ' . $cacheDir . ' must be writable ' . |
|
49 | 49 | 'by the server.'); |
50 | 50 | |
51 | 51 | $options = array( |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | */ |
73 | 73 | public function setLifeTime($time) |
74 | 74 | { |
75 | - $this->lifetime = (int)$time; |
|
75 | + $this->lifetime = (int) $time; |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | */ |
83 | 83 | protected function getID($catalogue, $culture) |
84 | 84 | { |
85 | - return $catalogue.':'.$culture; |
|
85 | + return $catalogue . ':' . $culture; |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | /** |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | */ |
93 | 93 | protected function getGroup($catalogue, $culture) |
94 | 94 | { |
95 | - return $catalogue.':'.get_class($this); |
|
95 | + return $catalogue . ':' . get_class($this); |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | /** |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | * @return mixed Boolean FALSE if no cache hit. Otherwise, translation |
105 | 105 | * table data for the specified section and locale. |
106 | 106 | */ |
107 | - public function get($catalogue, $culture, $lastmodified=0) |
|
107 | + public function get($catalogue, $culture, $lastmodified = 0) |
|
108 | 108 | { |
109 | 109 | $ID = $this->getID($catalogue, $culture); |
110 | 110 | $group = $this->getGroup($catalogue, $culture); |
@@ -113,13 +113,13 @@ discard block |
||
113 | 113 | |
114 | 114 | $cache = $this->cache->getCacheFile(); |
115 | 115 | |
116 | - if(is_file($cache) == false) |
|
116 | + if (is_file($cache) == false) |
|
117 | 117 | return false; |
118 | 118 | |
119 | 119 | |
120 | - $lastmodified = (int)$lastmodified; |
|
120 | + $lastmodified = (int) $lastmodified; |
|
121 | 121 | |
122 | - if($lastmodified <= 0 || $lastmodified > filemtime($cache)) |
|
122 | + if ($lastmodified <= 0 || $lastmodified > filemtime($cache)) |
|
123 | 123 | return false; |
124 | 124 | |
125 | 125 | //echo '@@ Cache hit: "'.$ID.'" : "'.$group.'"'; |
@@ -39,14 +39,16 @@ discard block |
||
39 | 39 | { |
40 | 40 | $cacheDir = $cacheDir.'/'; |
41 | 41 | |
42 | - if(!is_dir($cacheDir)) |
|
43 | - throw new Exception( |
|
42 | + if(!is_dir($cacheDir)) { |
|
43 | + throw new Exception( |
|
44 | 44 | 'The cache directory '.$cacheDir.' does not exists.'. |
45 | 45 | 'The cache directory must be writable by the server.'); |
46 | - if(!is_writable($cacheDir)) |
|
47 | - throw new Exception( |
|
46 | + } |
|
47 | + if(!is_writable($cacheDir)) { |
|
48 | + throw new Exception( |
|
48 | 49 | 'The cache directory '.$cacheDir.' must be writable '. |
49 | 50 | 'by the server.'); |
51 | + } |
|
50 | 52 | |
51 | 53 | $options = array( |
52 | 54 | 'cacheDir' => $cacheDir, |
@@ -113,14 +115,16 @@ discard block |
||
113 | 115 | |
114 | 116 | $cache = $this->cache->getCacheFile(); |
115 | 117 | |
116 | - if(is_file($cache) == false) |
|
117 | - return false; |
|
118 | + if(is_file($cache) == false) { |
|
119 | + return false; |
|
120 | + } |
|
118 | 121 | |
119 | 122 | |
120 | 123 | $lastmodified = (int)$lastmodified; |
121 | 124 | |
122 | - if($lastmodified <= 0 || $lastmodified > filemtime($cache)) |
|
123 | - return false; |
|
125 | + if($lastmodified <= 0 || $lastmodified > filemtime($cache)) { |
|
126 | + return false; |
|
127 | + } |
|
124 | 128 | |
125 | 129 | //echo '@@ Cache hit: "'.$ID.'" : "'.$group.'"'; |
126 | 130 | //echo "<br>\n"; |