Esempio n. 1
0
 /**
  * Gets the singleton SoapClient which is used to connect to the TransIP Api.
  *
  * @param  mixed       $parameters  Parameters.
  * @return SoapClient               The SoapClient object to which we can connect to the TransIP API
  */
 public static function _getSoapClient($parameters = array())
 {
     $endpoint = Transip_ApiSettings::$endpoint;
     if (self::$_soapClient === null) {
         $extensions = get_loaded_extensions();
         $errors = array();
         if (!class_exists('SoapClient') || !in_array('soap', $extensions)) {
             $errors[] = 'The PHP SOAP extension doesn\'t seem to be installed. You need to install the PHP SOAP extension. (See: http://www.php.net/manual/en/book.soap.php)';
         }
         if (!in_array('openssl', $extensions)) {
             $errors[] = 'The PHP OpenSSL extension doesn\'t seem to be installed. You need to install PHP with the OpenSSL extension. (See: http://www.php.net/manual/en/book.openssl.php)';
         }
         if (!empty($errors)) {
             die('<p>' . implode("</p>\n<p>", $errors) . '</p>');
         }
         $classMap = array('Product' => 'Transip_Product', 'PrivateNetwork' => 'Transip_PrivateNetwork', 'Vps' => 'Transip_Vps', 'Snapshot' => 'Transip_Snapshot', 'OperatingSystem' => 'Transip_OperatingSystem');
         $options = array('classmap' => $classMap, 'encoding' => 'utf-8', 'features' => SOAP_SINGLE_ELEMENT_ARRAYS, 'trace' => false);
         $wsdlUri = "https://{$endpoint}/wsdl/?service=" . self::SERVICE;
         try {
             self::$_soapClient = new SoapClient($wsdlUri, $options);
         } catch (SoapFault $sf) {
             throw new Exception("Unable to connect to endpoint '{$endpoint}'");
         }
         self::$_soapClient->__setCookie('login', Transip_ApiSettings::$login);
         self::$_soapClient->__setCookie('mode', Transip_ApiSettings::$mode);
     }
     $timestamp = time();
     $nonce = uniqid('', true);
     self::$_soapClient->__setCookie('timestamp', $timestamp);
     self::$_soapClient->__setCookie('nonce', $nonce);
     self::$_soapClient->__setCookie('clientVersion', self::API_VERSION);
     self::$_soapClient->__setCookie('signature', self::_urlencode(self::_sign(array_merge($parameters, array('__service' => self::SERVICE, '__hostname' => $endpoint, '__timestamp' => $timestamp, '__nonce' => $nonce)))));
     return self::$_soapClient;
 }