项目作者: AfriCC

项目描述 :
A High Level EPP TCP/SSL Client for PHP
高级语言: PHP
项目地址: git://github.com/AfriCC/php-epp2.git
创建时间: 2014-06-07T20:55:05Z
项目社区:https://github.com/AfriCC/php-epp2

开源协议:GNU General Public License v3.0

下载


build and publish
Scrutinizer Code Quality
Coverage Status
Latest Stable Version
Packagist
Latest Unstable Version
License

php-epp2

php-epp2 is a High Level Extensible Provisioning Protocol (EPP) TCP/SSL client written in modern PHP.

Released under the GPLv3 License, feel free to contribute (fork, create
meaningful branchname, issue pull request with thus branchname)!

Table of Contents generated with DocToc

Requirements

  • PHP 5.5+
  • php-ext-intl
  • php-ext-openssl

Features

  • modern PHP standards
    • PSR-1, PSR-2 & PSR-4
    • notice and warning free (find them, and I’ll fix it!)
  • high-level usage (Plug & Play)
  • simplified client for socket and http(s) connections (auto login/logout, auto inject clTRID)
  • SSL (+local-cert)
  • XPath like setter to simplify the creation of complex XML structures
  • XML based responses for direct traversal via XPath
  • RFC 5730, RFC 5731, RFC 5732, RFC 5733, RFC 5734 & RFC 3915
  • DNSSEC support RFC 5910

Install

Via Composer

  1. $ composer require africc/php-epp2

Usage

See the examples
folder for a more or less complete usage reference. Additionally have a look at
whmcs-registrars-coza
which is a WHMCS Registrar Module for the
co.za zone using this library.

Basic Client Connection

this will automatically login on connect() and logout on close()

  1. <?php
  2. require 'vendor/autoload.php';
  3. use AfriCC\EPP\Client as EPPClient;
  4. $epp_client = new EPPClient([
  5. 'host' => 'epptest.org',
  6. 'username' => 'foo',
  7. 'password' => 'bar',
  8. 'services' => [
  9. 'urn:ietf:params:xml:ns:domain-1.0',
  10. 'urn:ietf:params:xml:ns:contact-1.0'
  11. ],
  12. 'debug' => true,
  13. ]);
  14. try {
  15. $greeting = $epp_client->connect();
  16. } catch(Exception $e) {
  17. echo $e->getMessage() . PHP_EOL;
  18. unset($epp_client);
  19. exit(1);
  20. }
  21. $epp_client->close();

Create Frame Objects

setXXX() indicates that value can only be set once, re-calling the method will
overwrite the previous value.

addXXX() indicates that multiple values can exist, re-calling the method will
add values.

  1. <?php
  2. require 'vendor/autoload.php';
  3. use AfriCC\EPP\Frame\Command\Create\Host as CreateHost;
  4. $frame = new CreateHost();
  5. $frame->setHost('ns1.example.com');
  6. $frame->setHost('ns2.example.com');
  7. $frame->addAddr('8.8.8.8');
  8. $frame->addAddr('8.8.4.4');
  9. $frame->addAddr('2a00:1450:4009:809::1001');
  10. echo $frame;
  11. // or send frame to previously established connection
  12. $epp_client->sendFrame($frame);

Parse Response

You can either access nodes directly by passing through a xpath or use the data()
Method which will return an assoc array.

  1. use AfriCC\EPP\Frame\Command\Check\Domain as DomainCheck;
  2. use AfriCC\EPP\Frame\Response;
  3. $frame = new DomainCheck();
  4. $frame->addDomain('example.org');
  5. $frame->addDomain('example.net');
  6. $frame->addDomain('example.com');
  7. $response = $epp_client->request($frame);
  8. if (!($response instanceof Response)) {
  9. echo 'response error' . PHP_EOL;
  10. unset($epp_client);
  11. exit(1);
  12. }
  13. $result = $response->results()[0];
  14. echo $result->code() . PHP_EOL;
  15. echo $result->message() . PHP_EOL;
  16. echo $response->clientTransactionId() . PHP_EOL;
  17. echo $response->serverTransactionId() . PHP_EOL;
  18. $data = $response->data();
  19. if (empty($data) || !is_array($data)) {
  20. echo 'empty response data' . PHP_EOL;
  21. unset($epp_client);
  22. exit(1);
  23. }
  24. foreach ($data['chkData']['cd'] as $cd) {
  25. printf('Domain: %s, available: %d' . PHP_EOL, $cd['name'], $cd['@name']['avail']);
  26. }

Custom ObjectSpec

If registrar you’re working with uses custom namespace names (eg NASK) you can
use custom ObjectSpec. Clients always use specified ObjectSpec when decoding
responses from EPP server.

You can use this feature as follows:

  1. use AfriCC\EPP\HTTPClient as EPPClient;
  2. use \AfriCC\EPP\Extension\NASK\ObjectSpec as NASKObjectSpec;
  3. use AfriCC\EPP\Frame\Command\Poll;
  4. $objectSpec = new NASKObjectSpec();
  5. $config = [
  6. 'host' => 'https://app.registrar.tld',
  7. 'username' => 'user',
  8. 'password' => 'pass',
  9. 'services' => $objectSpec->services,
  10. 'serviceExtensions' => $objectSpec->serviceExtensions,
  11. ];
  12. $epp_client = new EPPClient($config, $objectSpec);
  13. $frame = new Poll($epp_client->getObjectSpec());

or you can create frames with custom ObjectSpec:

  1. use AfriCC\EPP\Extension\NASK\Update\Future as UpdateFuture;
  2. use AfriCC\EPP\Extension\NASK\ObjectSpec as NASKObjectSpec;
  3. $frame = new UpdateFuture(new NASKObjectSpec());
  4. $frame->setFuture('example7.pl');
  5. $frame->changeRegistrant('mak21');
  6. $frame->changeAuthInfo('2fooBAR');
  7. echo $frame;

You can also create different clients with different ObjectSpec and then you can
use getObjectSpec method when creating any request frame:

  1. use AfriCC\EPP\ObjectSpec as DefaultObjectSpec;
  2. use AfriCC\EPP\Extension\NASK\ObjectSpec as NASKObjectSpec;
  3. use AfriCC\EPP\Client as EPPClient;
  4. use AfriCC\EPP\HTTPClient as HTTPEPPClient;
  5. use AfriCC\EPP\Frame\Command\Poll;
  6. //...
  7. $nask_objectspec = new NASKObjectSpec();
  8. $default_objectspec = new DefaultObjectSpec();
  9. $nask_client = new HTTPEPPClient($nask_config, $nask_objectspec);
  10. $http_client = new HTTPEPPClient($http_config, $default_objectspec);
  11. $socket_client = new EPPClient($socket_config, $default_objectspec);
  12. $nask_socket_client = new EPPClient($nask_socket_config, $nask_objectspec);
  13. $nask_poll = new Poll($nask_client->getObjectSpec());
  14. $default_poll = new Poll($socket_client->getObjectSpec());

You can also change Client’s objectSpec on the fly via setObjectSpec method:

  1. use AfriCC\EPP\ObjectSpec as DefaultObjectSpec;
  2. use AfriCC\EPP\Extension\NASK\ObjectSpec as NASKObjectSpec;
  3. use AfriCC\EPP\Client as EPPClient;
  4. //...
  5. $nask_objectspec = new NASKObjectSpec();
  6. $default_objectspec = new DefaultObjectSpec();
  7. $variable_client = new EPPClient($socket_config, $default_objectspec);
  8. //calls to getObjectSpec will return default objectSpec and responses
  9. //will be parsed using default ObjectSpec
  10. $variable_client->setObjectSpec($nask_objectspec);
  11. //calls to getObjectSpec will return NASK objectSpec and responses
  12. //will be parsed using NASK ObjectSpec

Future

  • stricter response parsing
  • stricter request validation
  • make it server capable (in conjunction with apache mod_epp)

Credits

Acknowledgments

License

php-epp2 is released under the GPLv3 License. See the bundled
LICENSE file for
details.