コード例 #1
0
 /**
  * Execute a call to the Namecheap API
  * @return bool success or failure
  */
 public function dispatch()
 {
     $this->_beforeDispatch();
     // Verify config options
     $this->_config->check();
     $this->_prepareParameters();
     // Set the API url
     $this->_url = $this->_config->url . '?' . $this->getEncodedParams();
     // Perform any pre-connect code if the extending command class has defined it
     $this->_preConnect();
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_URL, $this->_config->url);
     curl_setopt($ch, CURLOPT_POST, 1);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $this->getEncodedParams());
     $this->_result = curl_exec($ch);
     curl_close($ch);
     // Perform any post-connect code if the extending command class has defined it
     $this->_postConnect();
     if (false === $this->_result) {
         $this->errorMessage = 'Communication error with Namecheap.';
         throw new Exception((string) $this->_xml->Errors->Error);
         return false;
     }
     // Parse xml result
     $this->_xml = new \SimpleXMLElement($this->_result);
     // Save status
     $this->_status = strtolower($this->_xml['Status']);
     if ($this->_status == 'error') {
         $this->errorMessage = (string) $this->_xml->Errors->Error;
         throw new Exception((string) $this->_xml->Errors->Error);
         return false;
     } else {
         if ($this->_status == 'ok') {
             $this->_response = $this->_xml->CommandResponse;
         }
     }
     $this->_postDispatch();
     return true;
 }