/** * Create a SoftLayer API SOAP Client * * Retrieve a new SoftLayer_SoapClient object for a specific SoftLayer API * service using either the class' constants API_USER and API_KEY or a * custom username and API key for authentication. Provide an optional id * value if you wish to instantiate a particular SoftLayer API object. * * @param string $serviceName The name of the SoftLayer API service you wish to query * @param int $id An optional object id if you're instantiating a particular SoftLayer API object. Setting an id defines this client's initialization parameter header. * @param string $username An optional API username if you wish to bypass SoftLayer_SoapClient's built-in username. * @param string $username An optional API key if you wish to bypass SoftLayer_SoapClient's built-in API key. * @return SoftLayer_SoapClient */ public static function getClient($serviceName, $id = null, $username = null, $apiKey = null) { $serviceName = trim($serviceName); if ($serviceName == null) { throw new Exception('Please provide a SoftLayer API service name.'); } $soapClient = new SoftLayer_SoapClient(self::API_BASE_URL . $serviceName . '?wsdl'); if ($username != null && $apiKey != null) { $soapClient->setAuthentication($username, $apiKey); } elseif (Softlayer_SoapClient::$apiUser != null && Softlayer_SoapClient::$apiKey != null) { $soapClient->setAuthentication(Softlayer_SoapClient::$apiUser, Softlayer_SoapClient::$apiKey); } $soapClient->_serviceName = $serviceName; if ($id != null) { $soapClient->setInitParameter($id); } return $soapClient; }
/** * Create a SoftLayer API SOAP Client * * Retrieve a new SoftLayer_SoapClient object for a specific SoftLayer API * service using either the class' constants API_USER and API_KEY or a * custom username and API key for authentication. Provide an optional id * value if you wish to instantiate a particular SoftLayer API object. * * @param string $serviceName The name of the SoftLayer API service you wish to query * @param int $id An optional object id if you're instantiating a particular SoftLayer API object. Setting an id defines this client's initialization parameter header. * @param string $username An optional API username if you wish to bypass SoftLayer_SoapClient's built-in username. * @param string $username An optional API key if you wish to bypass SoftLayer_SoapClient's built-in API key. * @param string $endpointUrl The API endpoint base URL you wish to connect to. Set this to SoftLayer_SoapClient::API_PRIVATE_ENDPOINT to connect via SoftLayer's private network. * @return SoftLayer_SoapClient */ public static function getClient($serviceName, $id = null, $username = null, $apiKey = null, $endpointUrl = null) { $serviceName = trim($serviceName); if ($serviceName == null) { throw new Exception('Please provide a SoftLayer API service name.'); } /* * Default to use the public network API endpoint, otherwise use the * endpoint defined in API_PUBLIC_ENDPOINT, otherwise use the one * provided by the user. */ if (isset($endpointUrl)) { $endpointUrl = trim($endpointUrl); if ($endpointUrl == null) { throw new Exception('Please provide a valid API endpoint.'); } } elseif (self::API_BASE_URL != null) { $endpointUrl = self::API_BASE_URL; } else { $endpointUrl = SoftLayer_SoapClient::API_PUBLIC_ENDPOINT; } if (is_null(self::SOAP_TIMEOUT)) { $soapClient = new SoftLayer_SoapClient($endpointUrl . $serviceName . '?wsdl'); } else { $soapClient = new SoftLayer_SoapClient($endpointUrl . $serviceName . '?wsdl', array('connection_timeout' => self::SOAP_TIMEOUT)); } $soapClient->_serviceName = $serviceName; $soapClient->_endpointUrl = $endpointUrl; if ($username != null && $apiKey != null) { $soapClient->setAuthentication($username, $apiKey); } else { $soapClient->setAuthentication(self::API_USER, self::API_KEY); } if ($id !== null) { $soapClient->setInitParameter($id); } return $soapClient; }