utopia-php / domains
Utopia Domains 库是一个简单的轻量级库,用于解析网页域名。这个库的目标是尽可能简单、易于学习和使用。
0.6.0
2024-09-05 16:21 UTC
Requires
- php: >=8.0
- utopia-php/framework: 1.0.*
Requires (Dev)
- laravel/pint: 1.2.*
- phpstan/phpstan: 1.9.x-dev
- phpunit/phpunit: ^9.3
- dev-master
- 0.6.0
- 0.6.0-RC1
- 0.5.0
- 0.4.1
- 0.4.0
- 0.3.2
- 0.3.1
- 0.3.0
- 0.2.5
- 0.2.4
- 0.2.3
- 0.2.2
- 0.2.1
- 0.2.0
- 0.1.0
- 0.0.1
- dev-feat-framework-v2
- dev-feat-github-action
- dev-feat-add-is-external
- dev-fix-domains-constructor
- dev-feat-allow-certain-domains
- dev-fix-public-validator
- dev-feat-add-new-validator
- dev-feat-registrar
- dev-fix-failing-jobs
- dev-feat-updated-public-suffix
- dev-meldiron/getregisterable-doesn-1
This package is auto-updated.
Last update: 2024-09-05 16:22:10 UTC
README
Utopia Domains 库是一个简单的轻量级库,用于解析域名名称结构。这个库的目标是尽可能简单、易于学习和使用。这个库由 Appwrite 团队 维护。
尽管这个库是 Utopia 框架 项目的组成部分,但它完全 无依赖,可以与其他任何 PHP 项目或框架独立使用。
入门指南
使用 composer 安装
composer require utopia-php/domains
<?php require_once '../vendor/autoload.php'; use Utopia\Domains\Domain; // demo.example.co.uk $domain = new Domain('demo.example.co.uk'); $domain->get(); // demo.example.co.uk $domain->getTLD(); // uk $domain->getSuffix(); // co.uk $domain->getRegisterable(); // example.co.uk $domain->getName(); // example $domain->getSub(); // demo $domain->isKnown(); // true $domain->isICANN(); // true $domain->isPrivate(); // false $domain->isTest(); // false // demo.localhost $domain = new Domain('demo.localhost'); $domain->get(); // demo.localhost $domain->getTLD(); // localhost $domain->getSuffix(); // '' $domain->getRegisterable(); // '' $domain->getName(); // demo $domain->getSub(); // '' $domain->isKnown(); // false $domain->isICANN(); // false $domain->isPrivate(); // false $domain->isTest(); // true
Utopia Domains 解析器使用从 publicsuffix.org 自动生成的公共后缀 PHP 数据集。数据集会定期更新,但您也可以通过克隆此库并运行带有导入命令的导入脚本来手动更新它。
php ./data/import.php
库 API
- get() - 返回完整的域名。
- getTLD() - 仅返回顶级域名。
- getSuffix() - 仅返回域名的公共后缀,例如:co.uk、ac.be、org.il、com、org。
- getRegisterable() - 返回可注册的域名,即公共后缀加上一个额外的标签。
- getName() - 仅返回可注册的域名。例如,blog.example.com 将返回 'example',而 demo.co.uk 将返回 'demo'。
- getSub() - 返回您域名的完整子域名路径。例如,blog.example.com 将返回 'blog',而 subdomain.demo.co.uk 将返回 'subdomain.demo'。
- isKnown() - 如果公共后缀已知则返回 true,否则返回 false。
- isICANN() - 如果公共后缀在公共后缀列表的 ICANN 域名部分中找到,则返回 true。
- isPrivate() - 如果公共后缀在公共后缀列表的 PRIVATE 域名部分中找到,则返回 true。
- isTest() - 如果域名的 TLD 是 'localhost' 或 'test',则返回 true,否则返回 false。
如果您想解析普通网页 URL,则使用
$host = parse_url($return, PHP_URL_HOST); $domain = new Utopia\Domains\Domain($host);
获取域名对象。
使用注册商 API
<?php use Utopia\Domains\Registrar; use Utopia\Domains\Contact; use Utopia\Domains\Registrar\OpenSRS; $opensrs = new OpenSRS( 'apikey', 'apisecret', 'username', 'password', [ 'ns1.nameserver.com', 'ns2.nameserver.com', ] ); $reg = new Registrar($opensrs); $contact = new Contact( 'firstname', 'lastname', 'phone', 'email', 'address1', 'address2', 'address3', 'city', 'state', 'country', 'postalcode', 'org', 'owner', ); $domain = 'yourname.com'; $available = $reg->available($domain); $purchase = $reg->purchase($domain, $contact); $suggest = $reg->suggest(['yourname', 'yourname1.com'], ['com', 'net', 'org']); $domainDetails = $reg->getDomain($domain); $renew = $reg->renew($domain, 1); $transfer = $reg->transfer($domain, [$contact]);
库注册商 API
- available(string $domain): bool - 检查域名是否可注册。
- purchase(string $domain, array $contacts, array $nameservers = []): array - 购买域名。
- suggest(array $query, array $tlds = [], $minLength = 1, $maxLength = 100): array - 建议或搜索域名。
- getDomain(string $domain): array - 获取域名详细信息。
- renew(string $domain, int $years): array - 续订域名。
- transfer(string $domain, array $contacts, array $nameservers = []): array - 转移域名。
系统要求
Utopia 框架需要 PHP 8.0 或更高版本。我们建议尽可能使用最新的 PHP 版本。
作者
Eldad Fux
版权和许可
MIT 许可证 (MIT) http://www.opensource.org/licenses/mit-license.php