layershifter / tld-database
公共后缀列表的数据库抽象
1.0.69
2019-08-04 10:03 UTC
Requires
- php: ^5.5.0 || ^7.0
- ext-curl: *
- layershifter/tld-support: ^1.0.0
Requires (Dev)
- codeclimate/php-test-reporter: dev-master
- mikey179/vfsstream: ^1.6
- phpmd/phpmd: @stable
- phpunit/phpunit: ^4.8 || ^5.0
- squizlabs/php_codesniffer: ~2.0
- 1.0.69
- 1.0.68
- 1.0.67
- 1.0.66
- 1.0.65
- 1.0.64
- 1.0.63
- 1.0.62
- 1.0.61
- 1.0.60
- 1.0.59
- 1.0.58
- 1.0.57
- 1.0.56
- 1.0.55
- 1.0.54
- 1.0.53
- 1.0.52
- 1.0.51
- 1.0.50
- 1.0.49
- 1.0.48
- 1.0.47
- 1.0.46
- 1.0.45
- 1.0.44
- 1.0.43
- 1.0.42
- 1.0.41
- 1.0.40
- 1.0.39
- 1.0.38
- 1.0.37
- 1.0.36
- 1.0.35
- 1.0.34
- 1.0.33
- 1.0.32
- 1.0.31
- 1.0.30
- 1.0.29
- 1.0.28
- 1.0.27
- 1.0.26
- 1.0.25
- 1.0.24
- 1.0.23
- 1.0.22
- 1.0.21
- 1.0.20
- 1.0.19
- 1.0.18
- 1.0.17
- 1.0.16
- 1.0.15
- 1.0.14
- 1.0.13
- 1.0.12
- 1.0.11
- 1.0.10
- 1.0.9
- 1.0.8
- 1.0.7
- 1.0.6
- 1.0.5
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
This package is auto-updated.
Last update: 2024-09-20 03:20:31 UTC
README
请使用 https://github.com/jeremykendall/php-domain-parser.
TLDDatabase
PHP中公共后缀列表的抽象层。由TLDExtract使用。
库的主要思想是提供对公共后缀列表实际数据库的简单快速访问。库始终附带实际数据库。
此软件包符合PSR-1、PSR-2、PSR-4规范。如果您注意到符合规范的疏漏,请通过拉取请求发送补丁。
需求
以下版本的PHP得到支持
- PHP 5.5
- PHP 5.6
- PHP 7.0
- PHP 7.1
- HHVM
基本用法
首先需要加载Store类。
$store = new \LayerShifter\TLDDatabase\Store();
为了检查数据库中是否存在条目,需要使用isExists
方法
$store->isExists(string $suffix) : bool; $store->isExists('com'); // true $store->isExists('comcom'); // false
注意:后缀必须不带前导点。
为了获取后缀的类型,需要使用getType
方法
为了检查数据库中是否存在条目,需要使用isExists
方法
$store->isExists(string $suffix): int; $store->getType('com'); // \LayerShifter\TLDDatabase\Store::TYPE_ICANN = 1 $store->getType('s3.amazonaws.com'); // \LayerShifter\TLDDatabase\Store::TYPE_PRIVATE = 2
如果条目不存在,方法将抛出异常,否则它将返回一个整型常量之一
\LayerShifter\TLDDatabase\Store::TYPE_ICANN
;\LayerShifter\TLDDatabase\Store::TYPE_PRIVATE
;
为了直接检查类型,可以使用isICANN
或isPrivate
方法。
$store->isICANN(string $suffix) : bool; $store->isICANN'com'); // true $store->isICANN('s3.amazonaws.com'); // false $store->isPrivate(string $suffix) : bool; $store->isPrivate('com'); // false $store->isPrivate('s3.amazonaws.com'); // true
高级用法
为开发者提供了一些酷炫的功能。
自定义数据库
如果您需要操作自定义(非打包)数据库,只需将参数添加到Store
构造函数即可。
$store = new \LayerShifter\TLDDatabase\Store(string $filename); $store = new \LayerShifter\TLDDatabase\Store(__DIR__ . '/cache/datatabase.php');
更新
如果您使用自定义数据库,则需要更新它。因此,您可以使用Update
类。
$update = new \LayerShifter\TLDDatabase\Update(string $filename); $update = new \LayerShifter\TLDDatabase\Update(__DIR__ . '/cache/datatabase.php'); $update->run();
HTTP适配器
基本上,库使用cURL适配器进行更新,但您也可以使用自定义适配器。
class customHttp implements \LayerShifter\TLDDatabase\Http\AdapterInterface { public function get() {} } $update = new \LayerShifter\TLDDatabase\Update(__DIR__ . '/cache/datatabase.php', 'customHttp'); $update->run();
安装
通过Composer
$ composer require layershifter/tld-database
测试
$ composer test
版本控制
库使用SemVer版本控制。其中
- 主要版本进行不兼容的API更改;
- 次要版本增加功能,完全向后兼容;
- 补丁是公共后缀列表的数据库更新。
数据库每周更新一次。
贡献
请参阅CONTRIBUTING和CONDUCT以获取详细信息。
许可证
此库在Apache 2.0许可证下发布。请参阅许可证文件以获取更多信息。