/**
  * @ignore
  *
  * @param string $faultcode
  * @param string $message
  * @param boolean $json
  * @param string $logpath
  */
 public function __construct($faultcode, $message, $logpath = null)
 {
     $this->setFaultCode($faultcode);
     //$this->faultcode = $faultcode;
     $this->setMessage($message);
     $this->setOutputTitle('Turnitin SDK Exception');
     $logger = new TurnitinLogger($logpath);
     if ($logger) {
         $logger->logError($this->getOutputTitle() . ': ' . $this->getFaultCode() . ' - ' . $this->getMessage());
     }
 }
 /**
  * @ignore
  * @param Soap $soap
  * @throws TurnitinSDKException
  */
 public function __construct($soap)
 {
     $this->domobject = new DomDocument();
     $this->requestdomobject = new DomDocument();
     $logger = new TurnitinLogger($soap->getLogPath());
     if ($logger) {
         $logger->logInfo($soap->getHttpHeaders() . PHP_EOL . $soap->__getLastRequest());
     }
     if ($soap->getDebug()) {
         $this->outputDebug($soap->__getLastRequest(), 'Request Message', $soap->getHttpHeaders());
     }
     @$this->requestdomobject->loadXML($soap->__getLastRequest());
     if ($logger) {
         $logger->logInfo($soap->__getLastResponse());
     }
     if ($soap->getDebug()) {
         $this->outputDebug($soap->__getLastResponse(), 'Response Message');
     }
     if (($load = @$this->domobject->loadXML($soap->__getLastResponse())) === false) {
         throw new TurnitinSDKException('responsexmlerror', 'XML Response could not be parsed', $soap->getLogPath());
     }
     $this->setMessageId(@$this->domobject->getElementsByTagName('imsx_messageIdentifier')->item(0)->nodeValue);
     $this->setStatus(@$this->domobject->getElementsByTagName('imsx_severity')->item(0)->nodeValue);
     if (is_null($this->getStatus())) {
         $this->setStatus($this->domobject->getElementsByTagName('status')->item(0)->nodeValue);
     }
     if (isset($this->domobject->getElementsByTagName('imsx_codeMinorFieldValue')->item(0)->nodeValue)) {
         $this->setStatusCode(@$this->domobject->getElementsByTagName('imsx_codeMinorFieldValue')->item(0)->nodeValue);
     } else {
         $this->setStatus('status');
         $this->setStatusCode($this->domobject->getElementsByTagName('status')->item(0)->nodeValue);
     }
     $this->setDescription(@$this->domobject->getElementsByTagName('imsx_description')->item(0)->nodeValue);
     if (is_null($this->getDescription())) {
         $this->setDescription($this->domobject->getElementsByTagName('message')->item(0)->nodeValue);
     }
     $this->setMessageRefId(@$this->domobject->getElementsByTagName('imsx_messageRefIdentifier')->item(0)->nodeValue);
 }
 public function __doRequest($request, $location, $action, $version, $one_way = null)
 {
     $http_headers = array('Content-type: text/xml;charset="utf-8"', 'Accept: text/xml', 'Cache-Control: no-cache', 'Pragma: no-cache', 'SOAPAction: "' . $action . '"', 'Content-length: ' . strlen($request), 'X-Integration-Version: ' . $this->getIntegrationVersion(), 'X-Plugin-Version: ' . $this->getPluginVersion());
     $location .= !is_null($this->language) ? '?lang=' . $this->language : '';
     $auth_headers[] = 'Source: ' . $this->getIntegrationId();
     $auth_headers[] = 'Authorization: ' . $this->getOAuthHeader($location, $request);
     $curl_headers = array_merge($http_headers, $auth_headers);
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $location);
     if (defined('CLI_SCRIPT') && CLI_SCRIPT) {
         curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
         curl_setopt($ch, CURLOPT_TIMEOUT, 240);
     } else {
         curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);
         curl_setopt($ch, CURLOPT_TIMEOUT, 30);
     }
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
     curl_setopt($ch, CURLOPT_POST, true);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
     curl_setopt($ch, CURLOPT_HTTPHEADER, $curl_headers);
     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
     if (isset($this->sslcertificate) and !empty($this->sslcertificate)) {
         curl_setopt($ch, CURLOPT_CAINFO, $this->sslcertificate);
     }
     if (isset($this->proxyhost) and !empty($this->proxyhost)) {
         curl_setopt($ch, CURLOPT_PROXY, $this->proxyhost . ':' . $this->proxyport);
     }
     if (isset($this->proxyuser) and !empty($this->proxyuser)) {
         curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
         curl_setopt($ch, CURLOPT_PROXYUSERPWD, sprintf('%s:%s', $this->proxyuser, $this->proxypassword));
     }
     $this->setHttpHeaders(join(PHP_EOL, $curl_headers));
     if ($this->perflog !== null) {
         $this->perflog->start_timer();
     }
     $result = curl_exec($ch);
     if ($this->perflog !== null) {
         $this->perflog->stop_timer($ch);
     }
     if ($result === false) {
         $logger = new TurnitinLogger($this->logpath);
         if ($logger) {
             $logger->logError('Curl Error: ' . curl_error($ch));
         }
         throw new TurnitinSDKException('Curl Error', curl_error($ch), $this->logpath);
     } else {
         $response = $result;
     }
     $this->setHeaders();
     curl_close($ch);
     return $response;
 }