EkomiServiceService

Class Service.

Defined (1)

The class is defined in the following location(s).

/includes/libraries/Ekomi/Service/Service.php  
  1. abstract class Service implements ServiceInterface{ 
  2. public $url; 
  3. public $auth; 
  4.  
  5. /** 
  6. * @param string $serviceName 
  7. * @return ServiceInterface 
  8. */ 
  9. public static function getInstance($serviceName='SOAP') { 
  10. if(!class_exists(__NAMESPACE__.'\\'.$serviceName.'Service') || !self::checkExtension($serviceName)) { 
  11. $serviceName = 'GET'; 
  12. $className = __NAMESPACE__.'\\'.$serviceName.'Service'; 
  13.  
  14. return new $className(); 
  15.  
  16. /** 
  17. * @param $serviceName 
  18. * @return bool 
  19. */ 
  20. public static function checkExtension($serviceName) { 
  21. if ($serviceName==='SOAP' && !extension_loaded(strtolower($serviceName))) { 
  22. return false; 
  23. else if ($serviceName==='CURL' && !extension_loaded(strtolower($serviceName))) { 
  24. return false; 
  25.  
  26. return true; 
  27.  
  28. /** 
  29. * @return string 
  30. */ 
  31. public function getUrl() 
  32. return $this->url; 
  33.  
  34. /** 
  35. * @return mixed 
  36. */ 
  37. public function getAuth() 
  38. return $this->auth; 
  39.  
  40. /** 
  41. * Set API Auth 
  42. * @param $apiId 
  43. * @param $apiKey 
  44. */ 
  45. final public function setAuth($apiId, $apiKey) 
  46. $this->auth = $apiId.'|'.$apiKey; 
  47.  
  48. /** 
  49. * Check and encode JSON 
  50. * @param $result 
  51. * @return string 
  52. */ 
  53. public function checkEncodeJson($result) { 
  54. if(is_array($result)) { 
  55. return json_encode($result); 
  56. else if(isset($result[0]) && $result[0]!=='{' && $result[0]!=='[') { 
  57. $result = json_encode(array('response'=>$result)); 
  58. return $result;