/**
 * @param eppConnection $conn
 * @param string $domainname
 * @return array|null
 * @throws eppException
 * @throws tmchException
 */
function checkdomainclaim($conn, $domainname)
{
    $check = new eppLaunchCheckRequest(array($domainname));
    $check->setLaunchPhase(eppLaunchCheckRequest::PHASE_CLAIMS, null, eppLaunchCheckRequest::TYPE_CLAIMS);
    if ($response = $conn->request($check)) {
        //$phase = $response->getLaunchPhase();
        /* @var Metaregistrar\EPP\eppLaunchCheckResponse $response */
        $checks = $response->getDomainClaims();
        foreach ($checks as $check) {
            echo $check['domainname'] . " has " . ($check['claimed'] ? 'a claim' : 'no claim') . "\n";
            if ($check['claimed']) {
                if ($check['claim']) {
                    if ($check['claim'] instanceof eppDomainClaim) {
                        echo "Claim validator: " . $check['claim']->getValidator() . ", claim key: " . $check['claim']->getClaimKey() . "\n";
                        $tmch = new cnisTmchConnection(true, 'settingslive.ini');
                        $claim = array();
                        $output = $tmch->getCnis($check['claim']->getClaimKey());
                        /* @var $output Metaregistrar\TMCH\tmchClaimData */
                        $claim['noticeid'] = $output->getNoticeId();
                        $claim['notafter'] = $output->getNotAfter();
                        $claim['confirmed'] = gmdate("Y-m-d\\TH:i:s\\Z");
                        return $claim;
                    } else {
                        throw new eppException("Domain name " . $check['domainname'] . " is claimed, but no valid claim key is present");
                    }
                } else {
                    throw new eppException("Domain name " . $check['domainname'] . " is claimed, but no claim key is present");
                }
            }
        }
    } else {
        echo "ERROR2\n";
    }
    return null;
}
/**
 * @param $conn eppConnection
 * @param $domains array
 */
function checkdomains($conn, $domains)
{
    try {
        $check = new eppLaunchCheckRequest($domains);
        $check->setLaunchPhase('claims');
        if ($response = $conn->request($check)) {
            /* @var $response Metaregistrar\EPP\eppLaunchCheckResponse */
            $checks = $response->getCheckedDomains();
            foreach ($checks as $check) {
                echo $check['domainname'] . " is " . ($check['available'] ? 'free' : 'taken') . " (" . $check['reason'] . ")\n";
            }
        } else {
            echo "ERROR\n";
        }
    } catch (eppException $e) {
        echo $e->getMessage() . "\n";
    }
}
/**
 * @param $conn eppConnection
 * @param $domains array
 */
function checkdomains($conn, $domains)
{
    try {
        $check = new eppLaunchCheckRequest($domains);
        $check->setLaunchPhase(eppLaunchCheckRequest::PHASE_CLAIMS, 'test', eppLaunchCheckRequest::TYPE_CLAIMS);
        if ($response = $conn->request($check)) {
            /* @var $response Metaregistrar\EPP\eppLaunchCheckResponse */
            //$phase = $response->getLaunchPhase();
            $checks = $response->getDomainClaims();
            foreach ($checks as $check) {
                echo $check['domainname'] . " has " . ($check['claimed'] ? 'a claim' : 'no claim') . "\n";
                if ($check['claimed']) {
                    if ($check['claim']) {
                        if ($check['claim'] instanceof eppDomainClaim) {
                            echo "Claim validator: " . $check['claim']->getValidator() . ", claim key: " . $check['claim']->getClaimKey() . "\n";
                            // Do not forget to fill in the CNIS login details!
                            $tmch = new cnisTmchConnection('');
                            $output = $tmch->getCnis($check['claim']->getClaimKey());
                            echo "Notice ID: " . $output->getNoticeId() . " Not after: " . $output->getNotAfter() . "\n";
                        } else {
                            throw new Metaregistrar\EPP\eppException("Domain name " . $check['domainname'] . " is claimed, but no valid claim key is present");
                        }
                    } else {
                        throw new Metaregistrar\EPP\eppException("Domain name " . $check['domainname'] . " is claimed, but no claim key is present");
                    }
                }
            }
        } else {
            echo "ERROR2\n";
        }
    } catch (eppException $e) {
        echo 'ERROR1: ' . $e->getMessage() . "\n";
    } catch (tmchException $t) {
        echo 'ERROR TMCH: ' . $t->getMessage() . "\n";
    }
}