Ejemplo n.º 1
0
 /**
  * Soap __doRequest() Method with CURL Implementation
  * @param string $request
  * @param string $location
  * @param string $action
  * @param int    $version
  * @param int    $one_way
  *
  * @return string
  * @throws SoapFault
  */
 public function __doRequest($request, $location, $action, $version, $one_way = 0)
 {
     $action = static::$action;
     /** return the xml response as its coming from normal soap call */
     if ($action == static::GET_RESULT && static::$xmlResponse) {
         return static::$xmlResponse;
     }
     $soapResponses =& static::$soapResponses;
     $soapRequests =& static::$soapRequests;
     /** @var $id string represent hashId of each request based on the request body to avoid multiple calls for the same request if exists */
     $id = sha1($location . $request);
     /** if curl is not enabled use parent::__doRequest */
     if (!in_array('curl', get_loaded_extensions())) {
         if (isset($soapResponses[$id])) {
             unset($soapResponses[$id]);
             return parent::__doRequest($request, $location, $action, $version, $one_way = 0);
         }
         $soapRequests[$id] = true;
         return "";
     }
     /** return response if soap method called for second time with same parameters */
     if (isset($soapResponses[$id])) {
         $data = $soapResponses[$id];
         unset($soapResponses[$id]);
         if ($data instanceof SoapFault) {
             throw $data;
         }
         return $data;
     }
     /** @var $headers array of headers to be sent with request */
     $headers = array('Content-type: text/xml; charset=utf-8', 'SOAPAction: "' . $action . '"');
     $ch = curl_init();
     /** CURL_OPTIONS  */
     curl_setopt($ch, CURLOPT_URL, $location);
     curl_setopt($ch, CURLOPT_POST, true);
     curl_setopt($ch, CURLOPT_ENCODING, "");
     curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
     curl_setopt($ch, CURLOPT_TIMEOUT, 50);
     curl_setopt($ch, CURLOPT_TIMECONDITION, 50);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_VERBOSE, static::$debug);
     curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
     $soapRequests[$id] = $ch;
     static::$requestIds[$id] = $id;
     static::$actions[$id] = $action;
     static::$lastRequestId = $id;
     return "";
 }
Ejemplo n.º 2
0
 /**
  * Soap __doRequest() Method with CURL Implementation
  *
  * @param string $request
  * @param string $location
  * @param string $action
  * @param int    $version
  * @param int    $one_way
  *
  * @return string
  * @throws SoapFault
  */
 public function __doRequest($request, $location, $action, $version, $one_way = 0)
 {
     $action = static::$action;
     $actionCommand = static::$action;
     $actionMethod = $action;
     // print xml for debugging testing
     if ($actionCommand != static::GET_RESULT && self::$printSoapRequest) {
         // debug the request here
         echo $this->prettyXml($request);
         if (self::$exitAfterPrint) {
             exit;
         }
         self::$printSoapRequest = false;
         self::$exitAfterPrint = false;
     }
     // some .NET Servers only accept action method with ns url!! uncomment it if you get error wrong command
     // $actionMethod  = str_ireplace(['http://tempuri.org/IFlightAPI/', 'https://tempuri.org/IFlightAPI/'], '', $action);
     /** return the xml response as its coming from normal soap call */
     if ($actionCommand == static::GET_RESULT && static::$xmlResponse) {
         return static::$xmlResponse;
     } else {
     }
     /** return the xml response as its coming from normal soap call */
     if ($action == static::GET_RESULT && static::$xmlResponse) {
         return static::$xmlResponse;
     }
     $soapResponses =& static::$soapResponses;
     $soapRequests =& static::$soapRequests;
     /** @var $id string represent hashId of each request based on the request body to avoid multiple calls for the same request if exists */
     $id = sha1($location . $request);
     /** if curl is not enabled use parent::__doRequest */
     if (!in_array('curl', get_loaded_extensions())) {
         if (isset($soapResponses[$id])) {
             unset($soapResponses[$id]);
             return parent::__doRequest($request, $location, $action, $version, $one_way = 0);
         }
         $soapRequests[$id] = true;
         return "";
     }
     /** return response if soap method called for second time with same parameters */
     if (isset($soapResponses[$id])) {
         $data = $soapResponses[$id];
         unset($soapResponses[$id]);
         if ($data instanceof SoapFault) {
             throw $data;
         }
         return $data;
     }
     /** @var $headers array of headers to be sent with request */
     $headers = ['Content-type: text/xml', 'charset=utf-8', "Accept: text/xml", 'SOAPAction: "' . $action . '"', "Content-length: " . strlen($request)];
     // ssl connection sharing
     if (empty(static::$sharedCurlData[$location])) {
         $shOpt = curl_share_init();
         curl_share_setopt($shOpt, CURLSHOPT_SHARE, CURL_LOCK_DATA_SSL_SESSION);
         curl_share_setopt($shOpt, CURLSHOPT_SHARE, CURL_LOCK_DATA_DNS);
         curl_share_setopt($shOpt, CURLSHOPT_SHARE, CURL_LOCK_DATA_COOKIE);
         static::$sharedCurlData[$location] = $shOpt;
     }
     $sh = static::$sharedCurlData[$location];
     $ch = curl_init();
     /** CURL_OPTIONS  */
     curl_setopt($ch, CURLOPT_URL, $location);
     curl_setopt($ch, CURLOPT_POST, true);
     curl_setopt($ch, CURLOPT_ENCODING, "");
     curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
     curl_setopt($ch, CURLOPT_TIMEOUT, 50);
     curl_setopt($ch, CURLOPT_TIMECONDITION, 50);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_VERBOSE, static::$debug);
     curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
     curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
     curl_setopt($ch, CURLOPT_SHARE, $sh);
     $soapRequests[$id] = $ch;
     static::$requestIds[$id] = $id;
     static::$actions[$id] = $actionMethod;
     static::$requestXml[$id] = $request;
     static::$lastRequestId = $id;
     return "";
 }