| 1 |
<?php |
| 2 |
/** |
| 3 |
* |
| 4 |
*/ |
| 5 |
|
| 6 |
/** |
| 7 |
* |
| 8 |
*/ |
| 9 |
abstract class CJTServicesClientModule { |
| 10 |
|
| 11 |
/** |
| 12 |
* put your comment there... |
| 13 |
* |
| 14 |
* @var mixed |
| 15 |
*/ |
| 16 |
protected $moduleName; |
| 17 |
|
| 18 |
/** |
| 19 |
* put your comment there... |
| 20 |
* |
| 21 |
* @var WP_Error |
| 22 |
*/ |
| 23 |
private $response; |
| 24 |
|
| 25 |
/** |
| 26 |
* put your comment there... |
| 27 |
* |
| 28 |
* @var mixed |
| 29 |
*/ |
| 30 |
private $responseData; |
| 31 |
|
| 32 |
/** |
| 33 |
* put your comment there... |
| 34 |
* |
| 35 |
* @var mixed |
| 36 |
*/ |
| 37 |
private $servicesAPI; |
| 38 |
|
| 39 |
/** |
| 40 |
* put your comment there... |
| 41 |
* |
| 42 |
* @param CJTServicesClient $servicesClient |
| 43 |
* @return CJTServicesClientModule |
| 44 |
*/ |
| 45 |
public function __construct(CJTServicesClient & $servicesClient) |
| 46 |
{ |
| 47 |
# Get Services API instance |
| 48 |
$this->servicesAPI =& $servicesClient; |
| 49 |
|
| 50 |
# Allow module name to be coded from derided class |
| 51 |
if (!$this->moduleName) |
| 52 |
{ |
| 53 |
# Obtain module name from $this class name with CJT prefix removed |
| 54 |
$this->moduleName = strtolower(substr(get_class($this), 3)); |
| 55 |
} |
| 56 |
} |
| 57 |
|
| 58 |
/** |
| 59 |
* put your comment there... |
| 60 |
* |
| 61 |
* @param mixed $name |
| 62 |
*/ |
| 63 |
protected function get($name) |
| 64 |
{ |
| 65 |
return isset($this->responseData[$name]) ? $this->responseData[$name] : null; |
| 66 |
} |
| 67 |
|
| 68 |
/** |
| 69 |
* put your comment there... |
| 70 |
* |
| 71 |
*/ |
| 72 |
public function getModuleName() |
| 73 |
{ |
| 74 |
return $this->moduleName; |
| 75 |
} |
| 76 |
|
| 77 |
/** |
| 78 |
* put your comment there... |
| 79 |
* |
| 80 |
*/ |
| 81 |
public function getResponseData() |
| 82 |
{ |
| 83 |
return $this->responseData; |
| 84 |
} |
| 85 |
|
| 86 |
/** |
| 87 |
* put your comment there... |
| 88 |
* |
| 89 |
*/ |
| 90 |
public function & getServicesAPI() |
| 91 |
{ |
| 92 |
return $this->servicesAPI; |
| 93 |
} |
| 94 |
|
| 95 |
/** |
| 96 |
* put your comment there... |
| 97 |
* |
| 98 |
* @param mixed $json |
| 99 |
*/ |
| 100 |
protected function jsonDecode( $json ) |
| 101 |
{ |
| 102 |
return json_decode( $json, true ); |
| 103 |
} |
| 104 |
|
| 105 |
/** |
| 106 |
* put your comment there... |
| 107 |
* |
| 108 |
* @param mixed $method |
| 109 |
* @param mixed $params |
| 110 |
* @param mixed $postData |
| 111 |
* @param mixed $bodyEncoding |
| 112 |
* @return CJTServicesClientModule |
| 113 |
*/ |
| 114 |
public function makeCall( $method, |
| 115 |
$params = null, |
| 116 |
$postData = null, |
| 117 |
$bodyEncoding = CJTServicesClient::BODY_ENCODING_JSON) |
| 118 |
{ |
| 119 |
# Reset response object |
| 120 |
$this->response = null; |
| 121 |
$this->responseData = null; |
| 122 |
|
| 123 |
# Dispatch and store response |
| 124 |
$this->response = $this->getServicesAPI()->makeCall( |
| 125 |
|
| 126 |
$this->getModuleName(), |
| 127 |
$method, |
| 128 |
$params, |
| 129 |
$postData, |
| 130 |
$bodyEncoding |
| 131 |
); |
| 132 |
|
| 133 |
# Read response data |
| 134 |
$this->responseData = wp_remote_retrieve_body( $this->response ); |
| 135 |
|
| 136 |
# Chain |
| 137 |
return $this; |
| 138 |
} |
| 139 |
|
| 140 |
} |
| 141 |
|