Person.php
7.0 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
<?php
namespace Faker\Provider\kk_KZ;
use Faker\Provider\DateTime;
class Person extends \Faker\Provider\Person
{
public const GENDER_MALE = 0;
public const GENDER_FEMALE = 1;
public const CENTURY_19TH = 0;
public const CENTURY_20TH = 1;
public const CENTURY_21ST = 2;
public const MALE_CENTURY_19TH = 1;
public const MALE_CENTURY_20TH = 3;
public const MALE_CENTURY_21ST = 5;
public const FEMALE_CENTURY_19TH = 2;
public const FEMALE_CENTURY_20TH = 4;
public const FEMALE_CENTURY_21ST = 6;
/**
* @var array
*/
public static $firstSequenceBitWeights = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];
/**
* @var array
*/
public static $secondSequenceBitWeights = [3, 4, 5, 6, 7, 8, 9, 10, 11, 1, 2];
/**
* @var array
*/
public static $genderCenturyMap = [
self::GENDER_MALE => [
self::CENTURY_19TH => self::MALE_CENTURY_19TH,
self::CENTURY_20TH => self::MALE_CENTURY_20TH,
self::CENTURY_21ST => self::MALE_CENTURY_21ST,
],
self::GENDER_FEMALE => [
self::CENTURY_19TH => self::FEMALE_CENTURY_19TH,
self::CENTURY_20TH => self::FEMALE_CENTURY_20TH,
self::CENTURY_21ST => self::FEMALE_CENTURY_21ST,
],
];
/**
* @see https://ru.wikipedia.org/wiki/%D0%9A%D0%B0%D0%B7%D0%B0%D1%85%D1%81%D0%BA%D0%B0%D1%8F_%D1%84%D0%B0%D0%BC%D0%B8%D0%BB%D0%B8%D1%8F
*
* @var array
*/
protected static $maleNameFormats = [
'{{lastName}}ұлы {{firstNameMale}}',
];
/**
* @see https://ru.wikipedia.org/wiki/%D0%9A%D0%B0%D0%B7%D0%B0%D1%85%D1%81%D0%BA%D0%B0%D1%8F_%D1%84%D0%B0%D0%BC%D0%B8%D0%BB%D0%B8%D1%8F
*
* @var array
*/
protected static $femaleNameFormats = [
'{{lastName}}қызы {{firstNameFemale}}',
];
/**
* @see http://koshpendi.kz/index.php/nomad/imena/
*
* @var array
*/
protected static $firstNameMale = [
'Аылғазы',
'Әбдіқадыр',
'Бабағожа',
'Ғайса',
'Дәмен',
'Егізбек',
'Жазылбек',
'Зұлпықар',
'Игісін',
'Кәдіржан',
'Қадырқан',
'Латиф',
'Мағаз',
'Нармағамбет',
'Оңалбай',
'Өндіріс',
'Пердебек',
'Рақат',
'Сағындық',
'Танабай',
'Уайыс',
'Ұйықбай',
'Үрімбай',
'Файзрахман',
'Хангелді',
'Шаттық',
'Ыстамбақы',
'Ібни',
];
/**
* @see http://koshpendi.kz/index.php/nomad/imena/
*
* @var array
*/
protected static $firstNameFemale = [
'Асылтас',
'Әужа',
'Бүлдіршін',
'Гүлшаш',
'Ғафура',
'Ділдә',
'Еркежан',
'Жібек',
'Зылиқа',
'Ирада',
'Күнсұлу',
'Қырмызы',
'Ләтипа',
'Мүштәри',
'Нұршара',
'Орынша',
'Өрзия',
'Перизат',
'Рухия',
'Сындыбала',
'Тұрсынай',
'Уәсима',
'Ұрқия',
'Үрия',
'Фируза',
'Хафиза',
'Шырынгүл',
'Ырысты',
'Іңкәр',
];
/**
* @see http://koshpendi.kz/index.php/nomad/imena/
* @see https://ru.wikipedia.org/wiki/%D0%9A%D0%B0%D0%B7%D0%B0%D1%85%D1%81%D0%BA%D0%B0%D1%8F_%D1%84%D0%B0%D0%BC%D0%B8%D0%BB%D0%B8%D1%8F
*
* @var array
*/
protected static $lastName = [
'Адырбай',
'Әжібай',
'Байбөрі',
'Ғизат',
'Ділдабек',
'Ешмұхамбет',
'Жігер',
'Зікірия',
'Иса',
'Кунту',
'Қыдыр',
'Лұқпан',
'Мышырбай',
'Нысынбай',
'Ошақбай',
'Өтетілеу',
'Пірәлі',
'Рүстем',
'Сырмұхамбет',
'Тілеміс',
'Уәлі',
'Ұлықбек',
'Үстем',
'Фахир',
'Хұсайын',
'Шілдебай',
'Ыстамбақы',
'Ісмет',
];
/**
* Note! When calculating individual identification number
* 2000-01-01 - 2000-12-31 counts as 21th century
* 1900-01-01 - 1900-12-31 counts as 20th century
*
* @param int $year
*
* @return int
*/
private static function getCenturyByYear($year)
{
if (($year >= 2100) || ($year < 1800)) {
throw new \InvalidArgumentException('Unexpected century');
}
if ($year >= 2000) {
return self::CENTURY_21ST;
}
if ($year >= 1900) {
return self::CENTURY_20TH;
}
return self::CENTURY_19TH;
}
/**
* National Individual Identification Numbers
*
* @see http://egov.kz/wps/portal/Content?contentPath=%2Fegovcontent%2Fcitizen_migration%2Fpassport_id_card%2Farticle%2Fiin_info&lang=en
* @see https://ru.wikipedia.org/wiki/%D0%98%D0%BD%D0%B4%D0%B8%D0%B2%D0%B8%D0%B4%D1%83%D0%B0%D0%BB%D1%8C%D0%BD%D1%8B%D0%B9_%D0%B8%D0%B4%D0%B5%D0%BD%D1%82%D0%B8%D1%84%D0%B8%D0%BA%D0%B0%D1%86%D0%B8%D0%BE%D0%BD%D0%BD%D1%8B%D0%B9_%D0%BD%D0%BE%D0%BC%D0%B5%D1%80
*
* @param int $gender
*
* @return string 12 digits, like 780322300455
*/
public static function individualIdentificationNumber(\DateTime $birthDate = null, $gender = self::GENDER_MALE)
{
if (!$birthDate) {
$birthDate = DateTime::dateTimeBetween();
}
do {
$population = self::numberBetween(1000, 2000);
$century = self::getCenturyByYear((int) $birthDate->format('Y'));
$iin = $birthDate->format('ymd');
$iin .= (string) self::$genderCenturyMap[$gender][$century];
$iin .= (string) $population;
$checksum = self::checkSum($iin);
} while ($checksum === 10);
return $iin . (string) $checksum;
}
/**
* @param string $iinValue
*
* @return int
*/
public static function checkSum($iinValue)
{
$controlDigit = self::getControlDigit($iinValue, self::$firstSequenceBitWeights);
if ($controlDigit === 10) {
return self::getControlDigit($iinValue, self::$secondSequenceBitWeights);
}
return $controlDigit;
}
/**
* @param string $iinValue
* @param array $sequence
*
* @return int
*/
protected static function getControlDigit($iinValue, $sequence)
{
$sum = 0;
for ($i = 0; $i <= 10; ++$i) {
$sum += (int) $iinValue[$i] * $sequence[$i];
}
return $sum % 11;
}
}