Metaregistrar\EPP\eppConnection::writeandread PHP Method

writeandread() public method

Write the content domDocument to the stream Read the answer Load the answer in a response domDocument return the reponse
public writeandread ( eppRequest $content ) : eppResponse
$content eppRequest
return eppResponse
    public function writeandread($content)
    {
        $requestsessionid = $content->getSessionId();
        $namespaces = $this->getDefaultNamespaces();
        if (is_array($namespaces)) {
            foreach ($namespaces as $id => $namespace) {
                $content->addExtension($id, $namespace);
            }
        }
        /*
         * $content->login is only set if this is an instance or a sub-instance of an eppLoginRequest
         */
        if ($content->login) {
            /* @var $content eppLoginRequest */
            // Set username for login request
            $content->addUsername($this->getUsername());
            // Set password for login request
            $content->addPassword($this->getPassword());
            // Set 'new password' for login request
            if ($this->getNewPassword()) {
                $content->addNewPassword($this->getNewPassword());
            }
            // Add version to this object
            $content->addVersion($this->getVersion());
            // Add language to this object
            $content->addLanguage($this->getLanguage());
            // Add services and extensions to this content
            $content->addServices($this->getServices(), $this->getExtensions());
        }
        /*
         * $content->hello is only set if this is an instance or a sub-instance of an eppHelloRequest
         */
        if (!$content->hello) {
            /**
             * Add used namespaces to the correct places in the XML
             */
            $content->addNamespaces($this->getServices());
            $content->addNamespaces($this->getExtensions());
        }
        $response = $this->createResponse($content);
        /* @var $response eppResponse */
        if (!$response) {
            throw new eppException("No valid response from server", 0, null, null, $content);
        }
        $content->formatOutput = true;
        $this->writeLog($content->saveXML(null, LIBXML_NOEMPTYTAG), "WRITE");
        $content->formatOutput = false;
        if ($this->write($content->saveXML(null, LIBXML_NOEMPTYTAG))) {
            $readcounter = 0;
            $xml = $this->read();
            // When no data is present on the stream, retry reading several times
            while (strlen($xml) == 0 && $readcounter < $this->retry) {
                $xml = $this->read();
                $readcounter++;
            }
            if (strlen($xml)) {
                set_error_handler(array($this, 'HandleXmlError'));
                if ($response->loadXML($xml)) {
                    restore_error_handler();
                    $this->writeLog($response->saveXML(null, LIBXML_NOEMPTYTAG), "READ");
                    /*
                    ob_flush();
                    */
                    $clienttransid = $response->getClientTransactionId();
                    if ($this->checktransactionids && $clienttransid && $clienttransid != $requestsessionid) {
                        throw new eppException("Client transaction id {$requestsessionid} does not match returned {$clienttransid}", 0, null, null, $xml);
                    }
                    $response->setXpath($this->getServices());
                    $response->setXpath($this->getExtensions());
                    $response->setXpath($this->getXpathExtensions());
                    if ($response instanceof eppHelloResponse) {
                        /* @var $response eppHelloResponse */
                        $response->validateServices($this->getLanguage(), $this->getVersion());
                    }
                    return $response;
                } else {
                    restore_error_handler();
                }
            } else {
                throw new eppException('Empty XML document when receiving data!');
            }
        } else {
            throw new eppException('Error writing content', 0, null, null, $content);
        }
        return null;
    }

Usage Example

示例#1
0
/**
 * @param \Metaregistrar\EPP\eppConnection $conn
 * @param string $contactid
 */
function infocontact($conn, $contactid)
{
    try {
        $contact = new Metaregistrar\EPP\eppContactHandle($contactid);
        $info = new Metaregistrar\EPP\eppInfoContactRequest($contact);
        if (($response = $conn->writeandread($info)) instanceof Metaregistrar\EPP\eppInfoContactResponse && $response->Success()) {
            echo $response->saveXML();
        }
    } catch (Metaregistrar\EPP\eppException $e) {
        echo $e->getMessage() . "\n";
    }
}