1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Mbright\Validation\Rule\Validate; |
4
|
|
|
|
5
|
|
|
class Locale implements ValidateRuleInterface |
6
|
|
|
{ |
7
|
|
|
/** |
8
|
|
|
* Valid locale codes; generated via `locale -a` on Mac OS X 10.7.5. |
9
|
|
|
* |
10
|
|
|
* @var array |
11
|
|
|
*/ |
12
|
|
|
protected $codes = [ |
13
|
|
|
'af_ZA', 'am_ET', 'be_BY', 'bg_BG', 'ca_ES', 'cs_CZ', 'da_DK', |
14
|
|
|
'de_AT', 'de_CH', 'de_DE', 'el_GR', 'en_AU', 'en_CA', 'en_GB', |
15
|
|
|
'en_IE', 'en_NZ', 'en_US', 'es_ES', 'et_EE', 'eu_ES', 'fi_FI', |
16
|
|
|
'fr_BE', 'fr_CA', 'fr_CH', 'fr_FR', 'he_IL', 'hi_IN', 'hr_HR', |
17
|
|
|
'hu_HU', 'hy_AM', 'is_IS', 'it_CH', 'it_IT', 'ja_JP', 'kk_KZ', |
18
|
|
|
'ko_KR', 'lt_LT', 'nl_BE', 'nl_NL', 'no_NO', 'pl_PL', 'pt_BR', |
19
|
|
|
'pt_PT', 'ro_RO', 'ru_RU', 'sk_SK', 'sl_SI', 'sr_YU', 'sv_SE', |
20
|
|
|
'tr_TR', 'uk_UA', 'zh_CN', 'zh_HK', 'zh_TW', |
21
|
|
|
]; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Validates that the value is in the list of allowed locale codes. |
25
|
|
|
* |
26
|
|
|
* @param object $subject The subject to be filtered. |
27
|
|
|
* @param string $field The subject field name. |
28
|
|
|
* |
29
|
|
|
* @return bool True if valid, false if not. |
30
|
|
|
*/ |
31
|
27 |
|
public function __invoke($subject, string $field): bool |
32
|
|
|
{ |
33
|
27 |
|
$value = $subject->$field; |
34
|
|
|
|
35
|
27 |
|
return in_array($value, $this->codes); |
36
|
|
|
} |
37
|
|
|
} |
38
|
|
|
|