geekwright / regdom

Florian Sager的regdom库的面向对象版,用于查询Mozilla公共后缀列表

v1.0.9 2023-05-01 00:09 UTC

This package is auto-updated.

Last update: 2024-09-08 20:57:29 UTC


README

面向对象的Florian Sager的regdom库,用于查询Mozilla公共后缀列表,并附带单元测试。

有关公共后缀的更多信息,以及为什么您可能想要查询该列表,请参阅publicsuffix.org

安装

composer require xoops/regdom

使用

类 Xoops\RegDom\PublicSuffixList

此类处理与公共后缀列表(PSL)的所有直接交互。这包括,从源URL获取列表,在本地上缓存该列表,将该列表转换为树形结构以方便快速查找,并在序列化形式中缓存该树。

$psl = new PublicSuffixList($url)

创建一个新的PublicSuffixList对象,该对象将使用指定的URL作为PSL的源。如果没有指定$url,则默认为https://publicsuffix.org/list/public_suffix_list.dat

$psl->setURL($url)

重置当前的PSL,并使用指定的URL作为源。

$psl->getTree()

返回当前PSL的树。Xoops\RegDom\RegisteredDomain使用此树形结构进行所有查找。

$psl->clearDataDirectory($cacheOnly)

默认情况下,这将清除所有缓存的PSL数据,包括远程访问的PSL数据的本地副本。通过传递true$cacheOnly仅清除序列化的树形数据。

类 Xoops\RegDom\RegisteredDomain

此类可用于确定URL的注册域部分,同时遵守公共后缀列表约定。

$regdom = new RegisteredDomain(PublicSuffixList $psl)

创建一个新的RegisteredDomain对象,该对象将使用$psl访问PSL。如果没有指定$psl,则将使用默认行为实例化一个新的PublicSuffixList对象。

$regdom->getRegisteredDomain($host)

返回提供的$host的最短可注册域部分,如果主机无法有效注册,则返回null

示例:echo $regdom->getRegisteredDomain('https://www.google.com/'); 输出

google.com

echo $regdom->getRegisteredDomain('theregister.co.uk'); 输出

theregister.co.uk

echo null === $regdom->getRegisteredDomain('co.uk'); 输出

1

脚本 bin\reloadpsl

此脚本可以用于加载PSL的新副本。在cron作业或其他脚本更新中可能很有用。

致谢

Reg-dom由Florian Sager编写,2009-02-05,sager@agitos.de

原始代码发布于http://www.dkim-reputation.org/regdom-lib-downloads/

Marcus Bointon的修改版代码在此http://github.com/Synchro

原始许可证

# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to you under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at:
#
#     https://apache.ac.cn/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.