承接 blobfolio/blob-domain 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

blobfolio/blob-domain

最新稳定版本:8.0.0

Composer 安装命令:

composer require blobfolio/blob-domain

包简介

Parse and validate domain names.

README 文档

README

blob-domain is a simple PHP library for parsing and validating domain names. It supports the full Public Suffix ruleset, translates Unicode to ASCII or vice versa (if the PHP extension INTL is present), and can break down a host into its constituent parts: subdomain, domain, and suffix.

Build Status

 

Table of Contents

  1. Requirements
  2. Installation
  3. Reference
  1. License

 

Requirements

blob-domain and its dependencies require PHP 7.0+ with the following modules:

  • BCMath
  • DOM
  • Fileinfo
  • Filter
  • JSON
  • MBString
  • INTL

 

Installation

Use Composer:

composer require "blobfolio/blob-domain:dev-master"

 

Reference

First up, the basics.

Basic Usage:

// Initialize the object by passing a host-like string.
$domain = new blobfolio\domain\domain('www.Google.com');

// Access the sanitized host by typecasting as a string.
echo (string) $domain; //www.google.com

// Get it all. If a part is not applicable, its value will be NULL.
$data = $domain->get_data();
/*
array(
    host => www.google.com
    subdomain => www
    domain => google
    suffix => com
)
*/

// Or each part using `get_KEY()`.
echo $domain->get_host(); //www.google.com
echo $domain->get_subdomain(); //www
echo $domain->get_domain(); //google
echo $domain->get_suffix(); //com

// By default, Unicode domains are converted to ASCII.
$domain = new blobfolio\domain\domain('http://☺.com');
echo $domain->get_host(); //xn--74h.com

// Convert them back by passing `TRUE` to the getters.
echo $domain->get_host(true); //☺.com

 

The following static methods exist if you don't want to initialize an object.

::parse_host()

Parse the hostname part of an arbitrary string, which might be a hostname, IP address, URL, etc.

Note: this will convert Unicode to ASCII.

Arguments

  • (string) Host

Returns

Returns the processed hostname or FALSE on failure.

Example

$foo = blobfolio\domain\domain::parse_host('http://☺.com'); //xn--74h.com
$foo = blobfolio\domain\domain::parse_host('co.uk'); //FALSE

::parse_host_parts()

Pull out the different parts of a host name, i.e. what you'd get running get_data() on a domain object.

Note: this will convert Unicode to ASCII.

Arguments

  • (string) Host

Returns

Returns an array containing the processed parts or FALSE on failure.

Example

$foo = blobfolio\domain\domain::parse_host_parts('www.Google.com');
/*
array(
    host => www.google.com
    subdomain => www
    domain => google
    suffix => com
)
*/

 

The object also comes with public methods. Aside from the various get_*() functions already demonstrated, you've got the following.

is_valid()

Is the host valid? This will be TRUE unless:

  • The host string is malformed;
  • The host string contains Unicode and the INTL extension is missing;
  • The host contains no domain portion;
  • The $dns option is passed but the host is not a FQDN or is missing an A record;

Arguments

  • (bool) (optional) Reachable DNS. If TRUE, the host must either be a public IP address or have an A record in its DNS table. Default: FALSE

Returns

Returns TRUE or FALSE.

is_ascii()

Whether or not a host is ASCII, like google.com. Unicode domains are still a bit unknown in many parts of the Western world and can cause problems with native PHP functions or databases, so good to know what you've got.

Note: IP addresses are considered ASCII for the purposes of this function.

Note: The various get_*() functions will always return the host in ASCII format by default. Passing TRUE to those functions will return Unicode hosts in their original Unicode, e.g. ☺.com.

Arguments

N/A

Returns

Returns TRUE or FALSE.

Example

// ☺.com
$domain->is_ascii(); //FALSE

// xn--74h.com
$domain->is_ascii(); //FALSE

// google.com
$domain->is_ascii(); //TRUE

is_fdqn()

Checks to see whether the host is a Fully-Qualified Domain Name (or at least a public IP address). In other words, can it be seen by the outside world?

Note: this does not imply the host actually exists.

Arguments

N/A

Returns

Returns TRUE or FALSE.

is_ip()

Is the host an IP address?

Arguments

  • (bool) (optional) Allow restricted/private. Default: TRUE

Returns

Returns TRUE or FALSE.

is_unicode()

Whether or not a host is Unicode, like ☺.com. Unicode hosts can cause problems with native PHP functions and databases, so might be a good thing to know.

Note: The various get_*() functions will return an ASCIIfied version of a Unicode domain by default, like xn--74h.com. Passing TRUE will de-convert them back to the original Unicode.

Arguments

N/A

Returns

Returns TRUE or FALSE.

Example

// ☺.com
$domain->is_unicode(); //TRUE

// xn--74h.com
$domain->is_unicode(); //TRUE

// google.com
$domain->is_unicode(); //FALSE

has_dns()

Does this host have an A record in its DNS table or is it a public IP address?

Note: the A record cannot point to a restricted/reserved IP like 127.0.0.1 or the function will return FALSE.

Arguments

N/A

Returns

Returns TRUE or FALSE.

strip_www()

This removes the leading www. subdomain, if any, from the parsed result. You can also have this run automatically at initialization by passing a second argument to the constructor, TRUE.

Arguments

N/A

Returns

Returns TRUE or FALSE, indicating whether or not a change was made.

Example

// As separate actions.
$foo = new blobfolio\domain\domain('www.Google.com');
/*
array(
    host => www.google.com
    subdomain => www
    domain => google
    suffix => com
)
*/
$foo->strip_www();
/*
array(
    host => google.com
    subdomain => NULL
    domain => google
    suffix => com
)
*/

// Or you can do this at initializing by passing TRUE as a second argument.
$foo = new blobfolio\domain\domain('www.Google.com', true);

 

License

Copyright © 2018 Blobfolio, LLC <hello@blobfolio.com>

This work is free. You can redistribute it and/or modify it under the terms of the Do What The Fuck You Want To Public License, Version 2.

DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004

Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>

Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.

DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

0. You just DO WHAT THE FUCK YOU WANT TO.

Donations

Bitcoin QR If you have found this work useful and would like to contribute financially, Bitcoin tips are always welcome!

1Af56Nxauv8M1ChyQxtBe1yvdp2jtaB1GF

blobfolio/blob-domain 适用场景与选型建议

blobfolio/blob-domain 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5.93k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2017 年 03 月 25 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 5.93k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 28
  • 依赖项目数: 3
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: WTFPL
  • 更新时间: 2017-03-25