定制 rincler/domain 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

rincler/domain

Composer 安装命令:

composer require rincler/domain

包简介

A domain name value object that supports IDN and Punycode, FQDN, validates input, and provides easy access to the domain level, labels, zone, TLD, eTLD and eTLD+1.

README 文档

README

Packagist Version PHP Version GitHub Workflow Status

A domain name value object that supports IDN and Punycode, FQDN, validates input, and provides easy access to the domain level, labels, zone, TLD, eTLD and eTLD+1.

Usage

<?php

use \Rincler\Domain\Domain;

$domain = new Domain('sub.example.com');
echo $domain; // sub.example.com
echo $domain->asIDN(); // sub.example.com
echo $domain->asPunycode(); // sub.example.com
echo $domain->zone(); // example.com
echo $domain->without($domain->zone()); // sub
echo $domain->TLD(); // com
echo $domain->without($domain->TLD()); // sub.example
echo $domain->level(); // 3
echo $domain->labels(); // [new Domain('com'), new Domain('example'), new Domain('sub')]
echo $domain->label(2); // example
echo $domain->sliceToLevel(2); // example.com
echo $domain->absolute(); // sub.example.com.

$domain = new Domain('пример.рф');
echo $domain->asIDN(); // пример.рф
echo $domain->asPunycode(); // xn--e1afmkfd.xn--p1ai

$domain = new Domain('xn--e1afmkfd.xn--p1ai');
echo $domain->asIDN(); // пример.рф
echo $domain->asPunycode(); // xn--e1afmkfd.xn--p1ai

var_dump($domain->equals(new Domain('xn--e1afmkfd.xn--p1ai'))) // true
var_dump($domain->equals(new Domain('пример.рф'))) // true
var_dump($domain->equals(new Domain('суб.пример.рф'))) // false

var_dump(Domain::isValid('example.com')) // true
var_dump(Domain::isValid('пример.рф')) // true
var_dump(Domain::isValid('exam_ple.com')) // false
var_dump(Domain::isValid('.example.com')) // false

$domain = new Domain('sub.example.com.');
var_dump($domain->isFQDN()) // true
echo $domain // sub.example.com.
echo $domain->zone() // example.com.
echo $domain->relative(); // sub.example.com

Installation

composer require rincler/domain

Documentation

  • static isValid(): bool - Returns true if the domain is valid, false otherwise.
  • __constructor(string $domain) - The constructor validates the domain and throws InvalidDomainException if it is not valid, then creates the value object.
  • asIDN(): string - Returns the domain in IDN format.
  • asPunycode(): string - Returns the domain in Punycode format.
  • equals(Domain $domain): bool - Returns true if the current domain equals the specified domain, false otherwise.
  • level(): int - Returns the number of levels in the domain.
  • zone(): Domain - Returns the domain zone.
  • TLD(): Domain - Returns the domain’s top-level domain (TLD).
  • eTLD(): ?Domain - Returns the domain’s effective top-level domain (eTLD).
  • eTLDPlusOne(): ?Domain - Returns the domain’s effective top-level domain plus the next label (eTLD+1).
  • without(Domain $suffix): ?Domain - Returns the domain without the specified suffix.
  • labels(): Domain[] - Returns an array containing all labels of the domain.
  • label(int $level): Domain - Returns the label corresponding to the given domain level.
  • sliceToLevel(int $level): Domain - Returns the domain up to the specified level.
  • absolute(): Domain - Returns the absolute form of the domain (FQDN) with a trailing dot.
  • isAbsolute(): bool - Returns true if the domain is absolute (FQDN), false otherwise.
  • FQDN(): Domain - Alias for absolute().
  • isFQDN(): bool - Alias for isAbsolute().
  • relative(): Domain - Returns the relative form of the domain.
  • isRoot(): bool - Returns true if the domain is root, false otherwise.
  • clone(): Domain - Returns a copy of the domain.
  • __toString(): string - Magic method returning the domain equivalent to asIDN().

URL Domain

Domains used in URLs cannot be absolute (with a dot at the end) and do not have a root zone. In such cases, you can use the UrlDomain class instead of Domain.

eTLD

See eTLD and Public Suffix List.

To use eTLDs, you must specify an eTLD provider via the eTLDSetProvider method:

<?php

use \Rincler\Domain\Domain;

Domain::eTLDSetProvider(static function () {
    return ['net.ru', 'org.ru'];
});

$domain = new Domain('sub.example.net.ru');

echo $domain->eTLD(); // net.ru
echo $domain->eTLDPlusOne(); // example.net.ru

Why PHP >= 7.3?

Domain validation in the intl extension was fixed in 7.3.0. See http://bugs.php.net/76829

Development

Running tests in Docker:

  1. Build the Docker image:
docker build -t php:8.4-cli-intl .
  1. Run the tests:
docker run --rm -v $(pwd):/app/ php:8.4-cli-intl php vendor/bin/phpunit

License

This library is released under the MIT license.

rincler/domain 适用场景与选型建议

rincler/domain 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6 次下载、GitHub Stars 达 2, 最近一次更新时间为 2020 年 01 月 04 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「domain」 「tld」 「idn」 「punycode」 「fqdn」 「etld」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 rincler/domain 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 rincler/domain 我们能提供哪些服务?
定制开发 / 二次开发

基于 rincler/domain 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 6
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-01-04