-
Notifications
You must be signed in to change notification settings - Fork 673
/
Locale.php
49 lines (43 loc) · 973 Bytes
/
Locale.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
namespace Elgg\I18n;
/**
* WARNING: API IN FLUX. DO NOT USE DIRECTLY.
*
* Language class to ensure only valid languages are used.
*
* @since 1.11
*
* @access private
*/
final class Locale {
/** @var string */
private $locale;
/**
* Use Locale::parse to construct
*
* @param string $locale A string representation of the locale
*/
private function __construct($locale) {
$this->locale = $locale;
}
/** @inheritDoc */
public function __toString() {
return $this->locale;
}
/**
* Create a language, asserting that the language code is valid.
*
* @param string $locale Language code
*
* @return Locale
*
* @throws InvalidLocaleException
*/
public static function parse($locale) {
// TODO(evan): Better sanitizing of locales using \Locale perhaps
if (strlen($locale) < 2 || strlen($locale) > 5) {
throw new InvalidLocaleException("Unrecognized locale: $locale");
}
return new Locale($locale);
}
}