juanparati/rdap-lib 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

juanparati/rdap-lib

最新稳定版本:2.1

Composer 安装命令:

composer require juanparati/rdap-lib

包简介

A PHP RDAP client library

README 文档

README

RDAPLib

About

RDAPLib is a Registration Data Access Protocol (RDAP) client library that query and resolve results into models, arrays or standard objects (stdObject).

This library uses Guzzle as default http client, however is possible to inject any custom HTTP client that is compliant with PSR-18.

Installation

composer require juanparati/rdap-lib "^2.0"

You may also require Guzzle 7 in case that you don't want to inject PSR-18 compliant client:

composer require guzzlehttp/guzzle "^7.0.1"

Usage

Basic example

$rdap = new \Juanparati\RDAPLib\RDAPClient();

$ip        = $rdap->ipLookup('94.234.38.5');    
$domain    = $rdap->domainLookup('google.com');
$tld       = $rdap->tldLookup('io');
$entity    = $rdap->entityLookup('APL7-ARIN')
$as        = $rdap->asLookup(1);
$registrar = $rdap->registrarLookup(1);

Output formats

RDAPClient map the result into models, however is possible to return the results using the following types:

  • RAW_OUTPUT (JSON string)
  • ARRAY_OUTPUT (Nested array)
  • OBJECT_OUTPUT (stdClass)
  • MODEL_OUTPUT

The "lookups" method accept a secondary parameter where to specify the format.

Example:

 $rdap = new \Juanparati\RDAPLib\RDAPClient();
    
 $ip     = $rdap->ipLookup('94.234.38.5', \Juanparati\RDAPLib\RDAPClient\RAW_OUTPUT);    
 $domain = $rdap->domainLookup('google.com', \Juanparati\RDAPLib\RDAPClient\ARRAY_OUTPUT);
 $tld    = $rdap->tldLookup('io', \Juanparati\RDAPLib\RDAPClient\OBJECT_OUTPUT);
 $entity = $rdap->entityLookup('APL7-ARIN')   // Default output is MODEL_OUTPUT

Model format

The model format is suitable when data accessors or extra parameters are required. RDAPClient provides defaults models that are possible to replace. The models are based on RFC-7483.

For example the default method for "vcardArray" provides a method that can parse jCard format.

Example:

$rdap = new \Juanparati\RDAPLib\RDAPClient();

$domain = $rdap->domainLookup('google.com');
$contact = $rdap->entities[0]->vcardArray->parseCard();

The link model has another method that can generate HTML links:

$rdap = new \Juanparati\RDAPLib\RDAPClient();

$domain = $rdap->domainLookup('google.com');
echo $rdap->links[0]->asLink();

It's possible to replace the current models with your own custom models. In order achieve that a custom ModelMapper is required.

Example:

// 1. Define our custom model that extends the default one.
class MyIpAddressModel extends \Juanparati\RDAPLib\Models\IpAddressModel {
    
    /**
     * Our new method
     */
    public function getFirstIpV4Ip() : ?string {
        return $this->v4[0] ?? null;
    }
}

// 2. Instantiate a custom mapper with the model replacement.   
$mapper = new \Juanparati\RDAPLib\ModelMapper([         
    'ipAddresses'  => \Juanparati\RDAPLib\Models\IpAddressModel::class,            
]);

// 3. Instantiate the client injecting our custom mapper
$rdap = new \Juanparati\RDAPLib\RDAPClient([], null, null, $mapper);

Use different endpoints

By default RDAPLib uses the following endpoints according to the lookup type:

'ip'        => 'https://rdap.db.ripe.net/ip/',
'domain'    => 'https://rdap.org/domain/',
'tld'       => 'https://root.rdap.org/domain/',
'autnum'    => 'https://rdap.db.ripe.net/autnum/',
'entity'    => 'https://rdap.arin.net/registry/entity/',
'registrar' => 'https://registrars.rdap.org/entity/',

It's possible to replace the endpoints passing a new ones into the first parameter of the RDAPClient constructor.

Example:

$rdap = new \Juanparati\RDAPLib\RDAPClient(['ip' => 'https://rdap.org/ip/']);

Use a custom HTTP Client

RDAPLib allows to inject a custom PSR-18 HTTP Client. The client will also require a message interface PSR-7.

Example:

 $rdap = new \Juanparati\RDAPLib\RDAPClient(
    [],
    $myCompatiblePSR18HTTPClient,       // Psr\Http\Client\ClientInterface
    $myCompatiblePSR7MessageInterface   // Psr\Http\Message\RequestFactoryInterface
 );

Supporters

统计信息

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

GitHub 信息

  • Stars: 6
  • Watchers: 1
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-10-18