nidzho / php-epp2

A High Level EPP TCP/SSL Client for PHP5

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Build Status Scrutinizer Code Quality 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.4 or higher
  • libicu 4.8 or higher
  • php-intl 3 or higher
  • php-mcrypt

Features

  • modern PHP standards
    • autoloader (e.g. lazy loading, we don't want to load XXX php files, if we only need few operations)
    • PSR-1 and PSR-2 compliant
    • notice and warning free (find them, and I'll fix it!)
  • high-level usage (Plug & Play)
  • simplified client (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

Install

Via Composer

$ 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()

<?php
require 'src/AfriCC/autoload.php';

use AfriCC\EPP\Client as EPPClient;

$epp_client = new EPPClient([
    'host' => 'epptest.org',
    'username' => 'foo',
    'password' => 'bar',
    'services' => [
        'urn:ietf:params:xml:ns:domain-1.0',
        'urn:ietf:params:xml:ns:contact-1.0'
    ],
    'debug' => true,
]);

try {
    $greeting = $epp_client->connect();
} catch(Exception $e) {
    echo $e->getMessage() . PHP_EOL;
    unset($epp_client);
    exit(1);
}

$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.

<?php
require 'src/AfriCC/autoload.php';

use AfriCC\EPP\Frame\Command\Create\Host as CreateHost;

$frame = new CreateHost;
$frame->setHost('ns1.example.com');
$frame->setHost('ns2.example.com');
$frame->addAddr('8.8.8.8');
$frame->addAddr('8.8.4.4');
$frame->addAddr('2a00:1450:4009:809::1001');
echo $frame;

// or send frame to previously established connection
$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.

use AfriCC\EPP\Frame\Command\Check\Domain as DomainCheck;
use AfriCC\EPP\Frame\Response;

$frame = new DomainCheck;
$frame->addDomain('example.org');
$frame->addDomain('example.net');
$frame->addDomain('example.com');

$response = $epp_client->request($frame);
if (!($response instanceof Response)) {
    echo 'response error' . PHP_EOL;
    unset($epp_client);
    exit(1);
}

echo $response->code() . PHP_EOL;
echo $response->message() . PHP_EOL;
echo $response->clientTransactionId() . PHP_EOL;
echo $response->serverTransactionId() . PHP_EOL;
$data = $response->data();
if (empty($data) || !is_array($data)) {
    echo 'empty response data' . PHP_EOL;
    unset($epp_client);
    exit(1);
}

foreach ($data['chkData']['cd'] as $cd) {
    printf('Domain: %s, available: %d' . PHP_EOL, $cd['name'], $cd['@name']['avail']);
}

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.

About

A High Level EPP TCP/SSL Client for PHP5

License:GNU General Public License v3.0


Languages

Language:PHP 100.0%