/**
* Retrieves API Client
*
* @return ClientInterface
* @throws AwsException
*/
public function getApiClient()
{
$apiClientType = $this->getApiClientType();
if (!isset($this->apiClients[$apiClientType])) {
$class = get_class($this);
$serviceName = preg_replace('/^.+\\\\([^\\\\]+)$/', '\\1', $class);
$clientClass = __NAMESPACE__ . '\\Client\\' . $apiClientType . 'Client';
//Some services, like Simple Storage Service, may use different query client.
if (file_exists(__DIR__ . '/Client/' . $apiClientType . 'Client/' . $serviceName . $apiClientType . 'Client.php')) {
$clientClass = $clientClass . '\\' . $serviceName . $apiClientType . 'Client';
}
if ($apiClientType == \Scalr\Service\Aws::CLIENT_SOAP) {
$wsdlPath = __DIR__ . '/' . $serviceName . '/V' . $this->getApiVersion() . '/' . $serviceName . '.wsdl';
if (!file_exists($wsdlPath)) {
throw new AwsException(sprintf('Could not find wsdl "%s" for the service "%s"', $wsdlPath, $serviceName));
}
$client = new $clientClass($this->aws->getAccessKeyId(), $this->aws->getSecretAccessKey(), $this->getApiVersion(), $this->getUrl(), $wsdlPath);
$client->setCertificate($this->aws->getCertificate());
$client->setPrivateKey($this->aws->getPrivateKey());
} else {
$client = new $clientClass($this->aws->getAccessKeyId(), $this->aws->getSecretAccessKey(), $this->getApiVersion(), $this->getUrl());
}
$client->setAws($this->getAws());
$this->apiClients[$apiClientType] = $client;
}
return $this->apiClients[$apiClientType];
}