Ejemplo n.º 1
0
 /**
  * Write the content domDocument to the stream
  * Read the answer
  * Load the answer in a response domDocument
  * return the reponse
  *
  * @param eppRequest $content
  * @return eppResponse
  * @throws eppException
  */
 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;
 }