Merhaba,
Static bir SoapClient oluşturup bunu diğer metotlarda erişmek istiyorum. İşin içinden çıkamadım.
class BaseCall
{
/**
*
* @description SOAP Servis sınıfının örneği
*
*/
protected $service = null;
/**
*
* @description SOAP İstek Sınıfının örneği
*
*/
protected $request = null;
protected $clientStatus = false;
/**
*
* @description SOAP Api servislerinin ilk çağırma için hazırlanması
* @param $serviceName
* @param $apiKey
* @param $apiPassword
* @throws ServerException
*/
public function __construct($serviceName, $apiKey, $apiPassword)
{
$soapServiceName = "App\Classes\ServerService\Services\\" . $serviceName;
$this->service = new $soapServiceName();
$this->request = new Request("SERVİS URL" , $apiKey, $apiPassword);
}
/**
*
* @description Gelen Tüm fonksiyon isteklerini ilgili servislere iletme
* @param string
* @param array
* @return string
*
* @throws ServerException
*/
public function __call($methodName, $arguments)
{
if(!$this->clientStatus) {
$this->clientStatus = $this->request->connectSoap();
}
if (!method_exists($this->service, $methodName)) {
throw new ServerException("Method Bulunamadı");
}
return call_user_func_array(array($this->service, $methodName), array_merge(array($this->request), $arguments));
}
}
Class Request
{
/**
*
* @description Api Key
*
*/
protected $apiKey;
/**
*
* @description Api Şifre
*
*/
protected $apiPassword;
/**
*
* @description SOAP Service Url
*
*/
protected $serviceUrl;
/**
*
* @description SOAP Oturumu
*
*/
protected $client = false;
/**
*
* @description Service Url Depolama için.
* @param $serviceUrl
* @param $apiKey
* @param $apiPassword
*/
public function __construct($serviceUrl, $apiKey, $apiPassword)
{
$this->apiKey = $apiKey;
$this->apiPassword = $apiPassword;
$this->serviceUrl = $serviceUrl;
}
/**
*
* @description SOAP Oturumunu Başlatma
* @param string
* @return bool
*
* @throws ServerException
*/
public function connectSoap()
{
try {
$this->client = new \SoapClient($this->serviceUrl, array("trace" => 1, "exception" => false, 'cache_wsdl' => WSDL_CACHE_NONE));
return true;
} catch (\Exception $e) {
throw new ServerException("SOAP Oturumu Başarısız");
}
}
/**
*
* @description SOAP İstek Gönderme
* @param string
* @param array $data
* @return SoapClient
*
* @throws ServerException
*/
public function sendRequest($method, $data = array())
{
if (isset($data['auth'])) {
unset($data['auth']);
}
try {
return $this->client->$method(array_merge(array('auth' => array('appKey' => $this->apiKey, 'appSecret' => $this->apiPassword)), $data));
} catch (\Exception $e) {
throw new ServerException($e->getMessage());
}
}
}
class CityService
{
public function getCities($client)
{
return $client->sendRequest('getCities');
}
}
Amacım BaseCall içerisinde Request sınıfında oluşan client'i CityService ve CategoryService gibi classlara dağıtmak ve tek client üzerinden çalışmak istiyorum.
Request sınıfındaki clienti BaseCall sınıfına çekiyorum , CityService class'ına da __construct olarak hatta aktarıyorum. Ama bu sefer de sendRequest'i çalıştıramıyorum.