Address.php
5 years ago
Color.php
5 years ago
Company.php
5 years ago
DateTime.php
5 years ago
Internet.php
5 years ago
Payment.php
5 years ago
Person.php
5 years ago
PhoneNumber.php
5 years ago
Text.php
5 years ago
Person.php
229 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Faker\Provider\zh_TW; |
| 4 | |
| 5 | class Person extends \Faker\Provider\Person |
| 6 | { |
| 7 | /** |
| 8 | * @see https://zh.wikipedia.org/wiki/%E4%B8%AD%E8%8F%AF%E6%B0%91%E5%9C%8B%E5%9C%8B%E6%B0%91%E8%BA%AB%E5%88%86%E8%AD%89 |
| 9 | */ |
| 10 | public static $idBirthplaceCode = array( |
| 11 | 'A' => 10, |
| 12 | 'B' => 11, |
| 13 | 'C' => 12, |
| 14 | 'D' => 13, |
| 15 | 'E' => 14, |
| 16 | 'F' => 15, |
| 17 | 'G' => 16, |
| 18 | 'H' => 17, |
| 19 | 'I' => 34, |
| 20 | 'J' => 18, |
| 21 | 'K' => 19, |
| 22 | 'M' => 21, |
| 23 | 'N' => 22, |
| 24 | 'O' => 35, |
| 25 | 'P' => 23, |
| 26 | 'Q' => 24, |
| 27 | 'T' => 27, |
| 28 | 'U' => 28, |
| 29 | 'V' => 29, |
| 30 | 'W' => 32, |
| 31 | 'X' => 30, |
| 32 | 'Z' => 33 |
| 33 | ); |
| 34 | |
| 35 | /** |
| 36 | * @see https://zh.wikipedia.org/wiki/%E4%B8%AD%E8%8F%AF%E6%B0%91%E5%9C%8B%E5%9C%8B%E6%B0%91%E8%BA%AB%E5%88%86%E8%AD%89 |
| 37 | */ |
| 38 | public static $idDigitValidator = array(1, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1); |
| 39 | |
| 40 | protected static $maleNameFormats = array( |
| 41 | '{{lastName}}{{firstNameMale}}', |
| 42 | ); |
| 43 | |
| 44 | protected static $femaleNameFormats = array( |
| 45 | '{{lastName}}{{firstNameFemale}}', |
| 46 | ); |
| 47 | |
| 48 | protected static $titleMale = array('� |
| 49 | �生', '博士', '教授'); |
| 50 | protected static $titleFemale = array('小姐', '太太', '博士', '教授'); |
| 51 | |
| 52 | /** |
| 53 | * @link http://zh.wikipedia.org/wiki/%E7%99%BE%E5%AE%B6%E5%A7%93 |
| 54 | */ |
| 55 | protected static $lastName = array( |
| 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 | * @link http://technology.chtsai.org/namefreq/ |
| 149 | */ |
| 150 | protected static $characterMale = array( |
| 151 | '佳', '俊', '信', '偉', '傑', '冠', '君', '哲', |
| 152 | '嘉', '威', '宇', '安', '宏', '宗', '宜', '家', |
| 153 | '庭', '廷', '建', '彥', '心', '志', '思', '承', |
| 154 | '文', '柏', '樺', '瑋', '穎', '美', '翰', '華', |
| 155 | '詩', '豪', '賢', '軒', '銘', '霖', |
| 156 | ); |
| 157 | |
| 158 | protected static $characterFemale = array( |
| 159 | '伶', '佩', '佳', '依', '儀', '冠', '君', '嘉', |
| 160 | '如', '娟', '婉', '婷', '安', '宜', '家', '庭', |
| 161 | '心', '思', '怡', '惠', '� |
| 162 | �', '文', '欣', '涵', |
| 163 | '淑', '玲', '珊', '琪', '琬', '瑜', '穎', '筑', |
| 164 | '筱', '美', '芬', '芳', '華', '萍', '萱', '蓉', |
| 165 | '詩', '貞', '郁', '鈺', '� |
| 166 | ', '雯', '靜', '馨', |
| 167 | ); |
| 168 | |
| 169 | public static function randomName($pool, $n) |
| 170 | { |
| 171 | $name = ''; |
| 172 | for ($i = 0; $i < $n; ++$i) { |
| 173 | $name .= static::randomElement($pool); |
| 174 | } |
| 175 | return $name; |
| 176 | } |
| 177 | |
| 178 | public static function firstNameMale() |
| 179 | { |
| 180 | return static::randomName(static::$characterMale, mt_rand(1, 2)); |
| 181 | } |
| 182 | |
| 183 | public static function firstNameFemale() |
| 184 | { |
| 185 | return static::randomName(static::$characterFemale, mt_rand(1, 2)); |
| 186 | } |
| 187 | |
| 188 | public static function suffix() |
| 189 | { |
| 190 | return ''; |
| 191 | } |
| 192 | |
| 193 | /** |
| 194 | * @param string $gender Person::GENDER_MALE || Person::GENDER_FEMALE |
| 195 | * |
| 196 | * @see https://en.wikipedia.org/wiki/National_Identification_Card_(Republic_of_China) |
| 197 | * |
| 198 | * @return string Length 10 alphanumeric characters, begins with 1 latin character (birthplace), |
| 199 | * 1 number (gender) and then 8 numbers (the last one is check digit). |
| 200 | */ |
| 201 | public function personalIdentityNumber($gender = null) |
| 202 | { |
| 203 | $birthPlace = self::randomKey(self::$idBirthplaceCode); |
| 204 | $birthPlaceCode = self::$idBirthplaceCode[$birthPlace]; |
| 205 | |
| 206 | $gender = ($gender != null) ? $gender : self::randomElement(array(self::GENDER_FEMALE, self::GENDER_MALE)); |
| 207 | $genderCode = ($gender === self::GENDER_MALE) ? 1 : 2; |
| 208 | |
| 209 | $randomNumberCode = self::randomNumber(7, true); |
| 210 | |
| 211 | $codes = str_split($birthPlaceCode . $genderCode . $randomNumberCode); |
| 212 | $total = 0; |
| 213 | |
| 214 | foreach ($codes as $key => $code) { |
| 215 | $total += $code * self::$idDigitValidator[$key]; |
| 216 | } |
| 217 | |
| 218 | $checkSumDigit = 10 - ($total % 10); |
| 219 | |
| 220 | if ($checkSumDigit == 10) { |
| 221 | $checkSumDigit = 0; |
| 222 | } |
| 223 | |
| 224 | $id = $birthPlace . $genderCode . $randomNumberCode . $checkSumDigit; |
| 225 | |
| 226 | return $id; |
| 227 | } |
| 228 | } |
| 229 |