komakino / identity
此包的最新版本(v1.3.0)没有可用的许可证信息。
身份号码的验证和属性解析
v1.3.0
2016-01-26 19:49 UTC
Requires
- komakino/luhn: ^1.0
- komakino/modulus11: ^1.0
Requires (Dev)
- phpunit/phpunit: 4.*
This package is not auto-updated.
Last update: 2024-09-14 19:09:21 UTC
README
Identity 是一个 Composer 包,用于验证、解析、格式化并从国家身份号码中提取各种信息。
当前实现:
- 瑞典个人号码/组织号码
- 丹麦个人号码/CPR号码
- 芬兰个人识别码/个人标识
- 挪威出生登记号
安装
要将此包作为依赖项添加到项目中,只需在项目的 composer.json
文件中添加对 komakino/identity
的依赖。
{ "require": { "komakino/identity": "*" } }
用法
use Komakino\Identity\National\SwedishIdentity; use Komakino\Identity\National\DanishIdentity; $swedishIdentity = new SwedishIdentity('011017-2721'); $danishIdentity = new DanishIdentity('170583-7315');
常用方法
构造时,将解析并验证号码。
如果号码不符合实现允许的输入格式,则将抛出 IdentityInvalidFormatException。
公共属性
-
bool $valid
- 身份号码的有效性
-
mixed **getters**
- 所有数字属性都可以作为实例上的属性访问
公共方法
-
array listProperties()
- 返回所有数字属性
-
bool hasProperty(string $property)
- 检查身份的实现是否具有属性
-
string __toString()
- 输出格式化的身份号码
静态方法
-
static array parse(string $number)
- 创建一个实例并返回所有数字属性
-
static bool validate(string $number)
- 创建一个实例并返回号码的有效性
-
static string format(string $number)
- 输出格式化的身份号码
瑞典个人号码/组织号码
允许的输入格式
0110172721
011017-2721
011017+2721
200110172721
20011017-2721
20011017+2721
格式化输出
011017-2721
数字属性
- type
- organization 或 person
- century
- 世纪的来源
- 以 OOxxxxxx-xxxx 的形式提供在号码中
- 分隔符是 +,表示此人已超过 100 岁
- 通过逻辑猜测。伪代码:
year > current_year ? 19 : 20
- 世纪的来源
- year
- OOxxxx-xxxx
- month
- xxOOxx-xxxx
- day
- xxxxOO-xxxx
- centuryHint
- xxxxx**-**xxxx
- 默认为 -
- locality
- xxxxxx-OOxx
- county
- 仅适用于 1990 年以前出生的人
- number
- xxxxxx-xxOx
- gender
- male 或 female
- checkdigit
- xxxxxx-xxxO
- birthday
- A DateTime 对象
- temporary
- 如果号码是临时的
丹麦个人号码/CPR号码
允许的输入格式
1705837315
170583-7315
格式化输出
170583-7315
数字属性
- century
- 从 year 和 centuryHint 计算得出
- day
- OOxxxx-xxxx
- month
- xxOOxx-xxxx
- year
- xxxxOO-xxxx
- centuryHint
- xxxxxx-Oxxx
- sequence
- xxxxxx-OOO0
- gender
- male 或 female
- birthday
- A DateTime 对象
芬兰个人号码/CPR号码
允许的输入格式
311280-888Y
格式化输出
311280-888Y
数字属性
- century
- 由 centuryHint 定义
- day
- OOxxxx-xxxx
- month
- xxOOxx-xxxx
- year
- xxxxOO-xxxx
- centuryHint
- xxxxx**-**xxxx
- -/+/A
- number
- xxxxxx-OOOx
- checkdigit
- xxxxxx-xxxO
- gender
- male 或 female
- birthday
- A DateTime 对象
挪威出生登记号
允许的输入格式
17058332143
格式化输出
17058332143
数字属性
- century
- 从 year 和 number 计算得出
- day
- OOxxxxxxxxx
- month
- xxOOxxxxxxx
- year
- xxxxOOxxxxx
- number
- xxxxxxOOOxx
- checkdigits
- xxxxxxxxxOO
- gender
- male 或 female
- birthday
- A DateTime 对象
- D-number
- bool 是否是 D-number。提供给移民等人的临时号码
- H-number
- bool 是否是 H-number。用于医疗保健等部门的临时号码
更新日志
v1.3.0
- 如果号码不符合实现允许的输入格式,现在将抛出异常。
v1.2.1
- 修复了解析零的问题。
v1.2.0
- 添加了挪威出生登记号的实现
版本 v1.1.0
- 添加了芬兰个人识别码/个人标识符的实现
版本 v1.0.0
- 首次公开发布
- 添加了瑞典个人号码/组织号码的实现
- 添加了丹麦个人号码/CPR号码的实现