rincler / domain
3.0.2
2020-02-02 13:17 UTC
Requires
- php: >=7.3.0
- ext-intl: *
- ext-mbstring: *
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.16
- phpstan/phpstan: ^0.12.8
- phpunit/phpunit: ^8.5
README
域名值对象
使用
<?php use \Rincler\Domain\Domain; $domain = new Domain('sub.domain.com'); echo $domain; // sub.domain.com echo $domain->asIdn(); // sub.domain.com echo $domain->asPunycode(); // sub.domain.com echo $domain->getZone(); // domain.com echo $domain->getWithoutZone(); // sub echo $domain->getTld(); // com echo $domain->getWithoutTld(); // sub.domain echo $domain->getLevel(); // 3 $domain = new Domain('домен.рф'); echo $domain->asIdn(); // домен.рф echo $domain->asPunycode(); // xn--d1acufc.xn--p1ai $domain = new Domain('xn--d1acufc.xn--p1ai'); echo $domain->asIdn(); // домен.рф echo $domain->asPunycode(); // xn--d1acufc.xnn
安装
composer require rincler/domain
文档
- static
isValid(): bool
- 如果域名有效则返回true
,否则返回false
__constructor(string $domain)
- 验证域名(如果域名无效则抛出InvalidDomainException
)并创建域名对象asIdn(): string
- 返回IDN格式的域名字符串asPunycode(): string
- 返回Punycode格式的域名字符串getLevel(): int
- 返回域名层级数量getZone(): Domain
- 返回域名的区域getWithoutZone(): Domain
- 返回不包含区域的域名getTld(): Domain
- 返回顶级域名getWithoutTld(): Domain
- 返回不包含顶级域名的域名equals(Domain $domain): bool
- 如果当前域名等于检查的域名则返回true
,否则返回false
__toString(): string
- 与asIdn
类似
为什么需要PHP >= 7.3?
在7.3.0版本中修复了intl扩展中域名验证的问题。请参阅http://bugs.php.net/76829
许可证
此库根据MIT许可证发布。