オープンソース PHP
Registrar API
NameSilo、GoDaddy、Namecheap、Dynadot をまたいでドメインを管理する単一の PHP ライブラリ。さらにゾーン・DNS・キャッシュ用の Cloudflare アダプターも。空き状況チェック、登録、更新、移管、DNS レコード、ネームサーバーを、すべて一貫したインターフェースで。
composer require josuamarcelc/registrar-api
アダプター
対応レジストラ
ブランド名の文字列でアダプターを選択します。すべてのアダプターは同じメソッドシグネチャを共有するため、コードを書き直さずにレジストラを切り替えられます。
ライブデモ
ドメインの空き状況を確認
サーバー側で NameSilo アダプターを通じて実際の checkAvailability() 呼び出しを実行します。ドメインは最大 10 件、カンマ・スペース・改行で区切って入力してください。5 分あたり 10 回までに制限されています。
クイックスタート
3 行で動く呼び出し
<?php
require __DIR__ . '/vendor/autoload.php';
use RegistrarAPI\RegistrarAPI;
$api = RegistrarAPI::make('namesilo', [
'api_key' => 'YOUR_NAMESILO_API_KEY'
]);
$result = $api->checkAvailability(['example.com', 'mybrand.io']);
print_r($result);
認証情報
アダプターごとの設定
各アダプターは設定配列を受け取ります。以下は通常必要となる最小限の設定です。
NameSilo
RegistrarAPI::make('namesilo', [
'api_key' => 'YOUR_KEY',
]); GoDaddy
RegistrarAPI::make('godaddy', [
'api_key' => 'KEY',
'api_secret' => 'SECRET',
// optional: 'base' => 'https://api.godaddy.com/v1'
]); Namecheap
RegistrarAPI::make('namecheap', [
'api_user' => 'USERNAME',
'api_key' => 'KEY',
'client_ip' => 'SERVER_PUBLIC_IP',
// optional: 'base' => 'https://api.namecheap.com/xml.response'
]); Dynadot
RegistrarAPI::make('dynadot', [
'api_key' => 'KEY',
]); メソッド
よく使う操作
すべてのアダプターは同じメソッドシグネチャを実装します。戻り値は正規化された連想配列です。
// Availability
$api->checkAvailability(['example.com']);
// Lifecycle
$api->registerDomain('example.com', [
'years' => 1,
'privacy' => true,
'auto_renew' => true,
'registrant' => [ /* contact fields */ ],
]);
$api->renewDomain('example.com', 1);
$api->transferDomain('example.com', ['auth_code' => 'EPP']);
$api->getDomain('example.com');
// DNS records
$api->getDNS('example.com');
$api->setDNS('example.com', [
['type'=>'A', 'host'=>'@', 'value'=>'203.0.113.10', 'ttl'=>600],
['type'=>'CNAME','host'=>'www', 'value'=>'@', 'ttl'=>600],
]);
$api->addDNS('example.com', ['type'=>'TXT','host'=>'@','value'=>'v=spf1 -all','ttl'=>300]);
$api->delDNS('example.com', ['type'=>'TXT','host'=>'@']);
// Nameservers
$api->setNameServers('example.com', ['ns1.host.com','ns2.host.com']);
// Escape hatch — call any raw endpoint the adapter doesn't wrap
$api->raw('domains/suggestions?query=mybrand&limit=5');
レスポンスの形
得られるもの
bool — 成否をすばやく確認checkAvailability() によって埋められるバケットgetDNS() が返す {type,host,value,ttl,prio?} の配列ボーナス
Cloudflare アダプター
同じライブラリ、同じ形ですが、ゾーン、DNS レコード、キャッシュ削除、無料トグル(Always HTTPS、Auto HTTPS Rewrites、Brotli、Minify、Rocket Loader、Dev Mode)に対応します。
$cf = RegistrarAPI::make('cloudflare', ['api_token' => 'CF_TOKEN']);
$cf->createZone('example.com');
$cf->setDNS('example.com', [
['type'=>'A','host'=>'@','value'=>'198.51.100.10','ttl'=>300,'proxied'=>true],
]);
$cf->purgeEverything('example.com'); コントリビュート
1 ファイルで新しいレジストラを追加
src/adapters/ に BaseAdapter を継承するクラスを作成し、抽象メソッドを実装してください。Composer が自動的に読み込みます。
namespace RegistrarAPI\Adapters;
use RegistrarAPI\Core\BaseAdapter;
class MyRegistrar extends BaseAdapter {
protected string $brand = 'myregistrar';
public function checkAvailability(array $domains): array { /* ... */ }
public function registerDomain(string $domain, array $opts): array { /* ... */ }
public function renewDomain(string $domain, int $years=1, array $opts=[]): array { /* ... */ }
public function transferDomain(string $domain, array $opts): array { /* ... */ }
public function getDomain(string $domain): array { /* ... */ }
public function getDNS(string $domain): array { /* ... */ }
public function setDNS(string $domain, array $records): array { /* ... */ }
public function addDNS(string $domain, array $record): array { /* ... */ }
public function delDNS(string $domain, array $selector): array { /* ... */ }
public function setNameServers(string $domain, array $nameservers): array { /* ... */ }
public function raw(string $op, array $params=[]): array { /* ... */ }
}