@@ -96,9 +96,9 @@ |
||
| 96 | 96 | * @method sxmlAddChildrenRecursive |
| 97 | 97 | * @author PA |
| 98 | 98 | * @date 2017-01-12 |
| 99 | - * @param SimpleXMLElement $root Root XML Node |
|
| 99 | + * @param \SimpleXMLElement $root Root XML Node |
|
| 100 | 100 | * @param array $arguments Array of Arguments to be added to XML Node |
| 101 | - * @return SimpleXMLElement Resulting XML Tree |
|
| 101 | + * @return \SimpleXMLElement Resulting XML Tree |
|
| 102 | 102 | */ |
| 103 | 103 | private function sxmlAddChildrenRecursive(\SimpleXMLElement $root, array $arguments) : \SimpleXMLElement |
| 104 | 104 | { |
@@ -8,51 +8,51 @@ discard block |
||
| 8 | 8 | class Request |
| 9 | 9 | { |
| 10 | 10 | |
| 11 | - /** |
|
| 12 | - * Base URL |
|
| 13 | - * @var string |
|
| 14 | - */ |
|
| 15 | - const BASE_URL = 'https://api.yourmembership.com'; |
|
| 16 | - const API_VERSION = '2.25'; |
|
| 17 | - |
|
| 18 | - /** |
|
| 19 | - * Session ID use for YourMembership API |
|
| 20 | - * @var string |
|
| 21 | - */ |
|
| 22 | - private static $sessionId = null; |
|
| 23 | - /** |
|
| 24 | - * Call Counter for Your Membership for a given session |
|
| 25 | - * @var integer |
|
| 26 | - */ |
|
| 27 | - public static $callId = 0; |
|
| 28 | - /** |
|
| 29 | - * API Key Used for YourMembership API |
|
| 30 | - * @var string |
|
| 31 | - */ |
|
| 32 | - private $apiKey; |
|
| 33 | - /** |
|
| 34 | - * Sa Passcode is a supplementary API key used for YourMembership API |
|
| 35 | - * @var string |
|
| 36 | - */ |
|
| 37 | - private $saPasscode; |
|
| 38 | - |
|
| 39 | - |
|
| 40 | - public function __construct(string $apiKey, string $saPasscode) |
|
| 41 | - { |
|
| 42 | - $this->apiKey = $apiKey; |
|
| 43 | - $this->saPasscode = $saPasscode; |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * Create the Base Envelope for an API call to YourMembership |
|
| 48 | - * @method buildBasePayload |
|
| 49 | - * @author PA |
|
| 50 | - * @date 2017-01-09 |
|
| 51 | - * @return \SimpleXMLElement XML Envelope with necessary credential parameters |
|
| 52 | - */ |
|
| 53 | - public function buildBasePayload() : \SimpleXMLElement |
|
| 54 | - { |
|
| 55 | - /* |
|
| 11 | + /** |
|
| 12 | + * Base URL |
|
| 13 | + * @var string |
|
| 14 | + */ |
|
| 15 | + const BASE_URL = 'https://api.yourmembership.com'; |
|
| 16 | + const API_VERSION = '2.25'; |
|
| 17 | + |
|
| 18 | + /** |
|
| 19 | + * Session ID use for YourMembership API |
|
| 20 | + * @var string |
|
| 21 | + */ |
|
| 22 | + private static $sessionId = null; |
|
| 23 | + /** |
|
| 24 | + * Call Counter for Your Membership for a given session |
|
| 25 | + * @var integer |
|
| 26 | + */ |
|
| 27 | + public static $callId = 0; |
|
| 28 | + /** |
|
| 29 | + * API Key Used for YourMembership API |
|
| 30 | + * @var string |
|
| 31 | + */ |
|
| 32 | + private $apiKey; |
|
| 33 | + /** |
|
| 34 | + * Sa Passcode is a supplementary API key used for YourMembership API |
|
| 35 | + * @var string |
|
| 36 | + */ |
|
| 37 | + private $saPasscode; |
|
| 38 | + |
|
| 39 | + |
|
| 40 | + public function __construct(string $apiKey, string $saPasscode) |
|
| 41 | + { |
|
| 42 | + $this->apiKey = $apiKey; |
|
| 43 | + $this->saPasscode = $saPasscode; |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * Create the Base Envelope for an API call to YourMembership |
|
| 48 | + * @method buildBasePayload |
|
| 49 | + * @author PA |
|
| 50 | + * @date 2017-01-09 |
|
| 51 | + * @return \SimpleXMLElement XML Envelope with necessary credential parameters |
|
| 52 | + */ |
|
| 53 | + public function buildBasePayload() : \SimpleXMLElement |
|
| 54 | + { |
|
| 55 | + /* |
|
| 56 | 56 | <YourMembership> |
| 57 | 57 | <Version>2.25</Version> |
| 58 | 58 | <ApiKey>3D638C5F-CCE2-4638-A2C1-355FA7BBC917</ApiKey> |
@@ -60,167 +60,167 @@ discard block |
||
| 60 | 60 | <SaPasscode>************</SaPasscode> |
| 61 | 61 | </YourMembership> |
| 62 | 62 | */ |
| 63 | - $xml = new \SimpleXMLElement('<YourMembership></YourMembership>'); |
|
| 64 | - $xml->addChild('Version', self::API_VERSION); |
|
| 65 | - $xml->addChild('ApiKey', $this->apiKey); |
|
| 66 | - $xml->addChild('CallID', self::$callId); |
|
| 67 | - $xml->addChild('SaPasscode', $this->saPasscode); |
|
| 68 | - |
|
| 69 | - return $xml; |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * Generates the XML for a API method call within |
|
| 74 | - * @method createCallPayload |
|
| 75 | - * @author PA |
|
| 76 | - * @throws YourMembershipRequestException |
|
| 77 | - * @date 2017-01-09 |
|
| 78 | - * @param string $method YourMembership API Function Name |
|
| 79 | - * @param array $arguments Array of Arguments to be passed as part of the YourMembership "Call" |
|
| 80 | - * @return \SimpleXMLElement |
|
| 81 | - */ |
|
| 82 | - public function createCallPayload(string $method, array $arguments) : \SimpleXMLElement |
|
| 83 | - { |
|
| 84 | - //Create Call Node |
|
| 85 | - $call = new \SimpleXMLElement('<Call> </Call>'); |
|
| 86 | - $call->addAttribute('Method', $method); |
|
| 87 | - |
|
| 88 | - //Add Arguments to the Call Node |
|
| 89 | - try { |
|
| 90 | - $call = $this->sxmlAddChildrenRecursive($call,$arguments); |
|
| 91 | - } catch(\Exception $e) { |
|
| 92 | - throw new YourMembershipRequestException($e->getMessage(), $e->getCode(), $method, $arguments, $e); |
|
| 93 | - } |
|
| 94 | - return $call; |
|
| 95 | - } |
|
| 96 | - /** |
|
| 97 | - * Recursively builds the array into a XML Tree |
|
| 98 | - * //NOTE Child arrays must be associative |
|
| 99 | - * @method sxmlAddChildrenRecursive |
|
| 100 | - * @author PA |
|
| 101 | - * @date 2017-01-12 |
|
| 102 | - * @param SimpleXMLElement $root Root XML Node |
|
| 103 | - * @param array $arguments Array of Arguments to be added to XML Node |
|
| 104 | - * @return SimpleXMLElement Resulting XML Tree |
|
| 105 | - */ |
|
| 106 | - private function sxmlAddChildrenRecursive(\SimpleXMLElement $root, array $arguments) : \SimpleXMLElement |
|
| 107 | - { |
|
| 108 | - foreach ($arguments as $key => $value) { |
|
| 109 | - if (is_array($value)) { |
|
| 110 | - $child = new \SimpleXMLElement(sprintf('<%s></%s>',$key, $key)); |
|
| 111 | - $this->sxmlAddChildrenRecursive($child, $value); |
|
| 112 | - $this->sxmlAppend($root,$child); |
|
| 113 | - } else { |
|
| 114 | - $root->addChild($key, $value); |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - } |
|
| 118 | - return $root; |
|
| 119 | - } |
|
| 120 | - /** |
|
| 121 | - * Builds The XML Request Body for the Your Membership API Call |
|
| 122 | - * @method buildXMLBody |
|
| 123 | - * @author PA |
|
| 124 | - * @date 2017-01-10 |
|
| 125 | - * @param string $method Your Membership API Function Name |
|
| 126 | - * @param array $arguments Your Membership Arguments |
|
| 127 | - * @return \SimpleXMLElement |
|
| 128 | - */ |
|
| 129 | - public function buildXMLBody(string $method, array $arguments) : \SimpleXMLElement |
|
| 130 | - { |
|
| 131 | - $xml = $this->buildBasePayload(); // Common Envelope |
|
| 132 | - |
|
| 133 | - if ($this->isSessionRequiredForMethod($method)) { |
|
| 134 | - $xml = $this->addSessionIdToRequest($xml); |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - $callPayload = $this->createCallPayload($method, $arguments); // Specific API Call Envelope |
|
| 138 | - |
|
| 139 | - // Put Api call into common envelope |
|
| 140 | - $this->sxmlAppend($xml, $callPayload); |
|
| 141 | - |
|
| 142 | - return $xml; |
|
| 143 | - } |
|
| 144 | - /** |
|
| 145 | - * Builds a Guzzle Request Object |
|
| 146 | - * @method buildRequest |
|
| 147 | - * @author PA |
|
| 148 | - * @date 2017-01-11 |
|
| 149 | - * @param string $method YourMembership API Method |
|
| 150 | - * @param array $arguments YourMembership API Method Call Arguments |
|
| 151 | - * @return \GuzzleHttp\Psr7\Request Guzzle Request Object |
|
| 152 | - */ |
|
| 153 | - public function buildRequest(string $method, array $arguments) : \GuzzleHttp\Psr7\Request |
|
| 154 | - { |
|
| 155 | - $requestBody = $this->buildXMLBody($method, $arguments)->asXML(); |
|
| 156 | - return new GuzzleRequest('POST', self::BASE_URL, ['Content-Type' => 'application/x-www-form-urlencoded; charset=UTF8'], $requestBody); |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - /** |
|
| 160 | - * Checks if Request Requires Session ID |
|
| 161 | - * @method isSessionRequiredForMethod |
|
| 162 | - * @author PA |
|
| 163 | - * @date 2017-01-10 |
|
| 164 | - * @param string $method YourMembership API Method |
|
| 165 | - * @return bool |
|
| 166 | - */ |
|
| 167 | - public function isSessionRequiredForMethod(string $method) : bool |
|
| 168 | - { |
|
| 169 | - //TODO Add config Logic for what API Methods require Session ID |
|
| 170 | - return ($method != 'Session.Create'); |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - /** |
|
| 174 | - * Helper for Deep Copy for of $from element into $to element for SimpleXML |
|
| 175 | - * @method sxmlAppend |
|
| 176 | - * @author PA |
|
| 177 | - * @date 2017-01-09 |
|
| 178 | - * @param \SimpleXMLElement $to |
|
| 179 | - * @param \SimpleXMLElement $from |
|
| 180 | - * @return void |
|
| 181 | - */ |
|
| 182 | - private function sxmlAppend(\SimpleXMLElement $to, \SimpleXMLElement $from) { |
|
| 183 | - $toDom = dom_import_simplexml($to); |
|
| 184 | - $fromDom = dom_import_simplexml($from); |
|
| 185 | - $toDom->appendChild($toDom->ownerDocument->importNode($fromDom, true)); |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - /** |
|
| 189 | - * Adds the Session Variable to the given XML Request Payload |
|
| 190 | - * @method addSessionIdToRequest |
|
| 191 | - * @author PA |
|
| 192 | - * @date 2017-01-10 |
|
| 193 | - * @param \SimpleXMLElement $requestXML Base Request XML Payload |
|
| 194 | - */ |
|
| 195 | - private function addSessionIdToRequest(\SimpleXMLElement $requestXML) : \SimpleXMLElement |
|
| 196 | - { |
|
| 197 | - $requestXML->addChild('SessionID', self::$sessionId); |
|
| 198 | - return $requestXML; |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - |
|
| 202 | - /** |
|
| 203 | - * Setter Method for SessionID |
|
| 204 | - * @method setSessionId |
|
| 205 | - * @author PA |
|
| 206 | - * @date 2017-01-10 |
|
| 207 | - * @param string $sessionId YourMembership Session ID |
|
| 208 | - */ |
|
| 209 | - public static function setSessionId(string $sessionId) |
|
| 210 | - { |
|
| 211 | - self::$sessionId = $sessionId; |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - /** |
|
| 215 | - * Checks if we have an active session available |
|
| 216 | - * @method hasSession |
|
| 217 | - * @author PA |
|
| 218 | - * @date 2017-01-11 |
|
| 219 | - * @return boolean |
|
| 220 | - */ |
|
| 221 | - public function hasSession() |
|
| 222 | - { |
|
| 223 | - return !is_null(self::$sessionId); |
|
| 224 | - } |
|
| 63 | + $xml = new \SimpleXMLElement('<YourMembership></YourMembership>'); |
|
| 64 | + $xml->addChild('Version', self::API_VERSION); |
|
| 65 | + $xml->addChild('ApiKey', $this->apiKey); |
|
| 66 | + $xml->addChild('CallID', self::$callId); |
|
| 67 | + $xml->addChild('SaPasscode', $this->saPasscode); |
|
| 68 | + |
|
| 69 | + return $xml; |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * Generates the XML for a API method call within |
|
| 74 | + * @method createCallPayload |
|
| 75 | + * @author PA |
|
| 76 | + * @throws YourMembershipRequestException |
|
| 77 | + * @date 2017-01-09 |
|
| 78 | + * @param string $method YourMembership API Function Name |
|
| 79 | + * @param array $arguments Array of Arguments to be passed as part of the YourMembership "Call" |
|
| 80 | + * @return \SimpleXMLElement |
|
| 81 | + */ |
|
| 82 | + public function createCallPayload(string $method, array $arguments) : \SimpleXMLElement |
|
| 83 | + { |
|
| 84 | + //Create Call Node |
|
| 85 | + $call = new \SimpleXMLElement('<Call> </Call>'); |
|
| 86 | + $call->addAttribute('Method', $method); |
|
| 87 | + |
|
| 88 | + //Add Arguments to the Call Node |
|
| 89 | + try { |
|
| 90 | + $call = $this->sxmlAddChildrenRecursive($call,$arguments); |
|
| 91 | + } catch(\Exception $e) { |
|
| 92 | + throw new YourMembershipRequestException($e->getMessage(), $e->getCode(), $method, $arguments, $e); |
|
| 93 | + } |
|
| 94 | + return $call; |
|
| 95 | + } |
|
| 96 | + /** |
|
| 97 | + * Recursively builds the array into a XML Tree |
|
| 98 | + * //NOTE Child arrays must be associative |
|
| 99 | + * @method sxmlAddChildrenRecursive |
|
| 100 | + * @author PA |
|
| 101 | + * @date 2017-01-12 |
|
| 102 | + * @param SimpleXMLElement $root Root XML Node |
|
| 103 | + * @param array $arguments Array of Arguments to be added to XML Node |
|
| 104 | + * @return SimpleXMLElement Resulting XML Tree |
|
| 105 | + */ |
|
| 106 | + private function sxmlAddChildrenRecursive(\SimpleXMLElement $root, array $arguments) : \SimpleXMLElement |
|
| 107 | + { |
|
| 108 | + foreach ($arguments as $key => $value) { |
|
| 109 | + if (is_array($value)) { |
|
| 110 | + $child = new \SimpleXMLElement(sprintf('<%s></%s>',$key, $key)); |
|
| 111 | + $this->sxmlAddChildrenRecursive($child, $value); |
|
| 112 | + $this->sxmlAppend($root,$child); |
|
| 113 | + } else { |
|
| 114 | + $root->addChild($key, $value); |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + } |
|
| 118 | + return $root; |
|
| 119 | + } |
|
| 120 | + /** |
|
| 121 | + * Builds The XML Request Body for the Your Membership API Call |
|
| 122 | + * @method buildXMLBody |
|
| 123 | + * @author PA |
|
| 124 | + * @date 2017-01-10 |
|
| 125 | + * @param string $method Your Membership API Function Name |
|
| 126 | + * @param array $arguments Your Membership Arguments |
|
| 127 | + * @return \SimpleXMLElement |
|
| 128 | + */ |
|
| 129 | + public function buildXMLBody(string $method, array $arguments) : \SimpleXMLElement |
|
| 130 | + { |
|
| 131 | + $xml = $this->buildBasePayload(); // Common Envelope |
|
| 132 | + |
|
| 133 | + if ($this->isSessionRequiredForMethod($method)) { |
|
| 134 | + $xml = $this->addSessionIdToRequest($xml); |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + $callPayload = $this->createCallPayload($method, $arguments); // Specific API Call Envelope |
|
| 138 | + |
|
| 139 | + // Put Api call into common envelope |
|
| 140 | + $this->sxmlAppend($xml, $callPayload); |
|
| 141 | + |
|
| 142 | + return $xml; |
|
| 143 | + } |
|
| 144 | + /** |
|
| 145 | + * Builds a Guzzle Request Object |
|
| 146 | + * @method buildRequest |
|
| 147 | + * @author PA |
|
| 148 | + * @date 2017-01-11 |
|
| 149 | + * @param string $method YourMembership API Method |
|
| 150 | + * @param array $arguments YourMembership API Method Call Arguments |
|
| 151 | + * @return \GuzzleHttp\Psr7\Request Guzzle Request Object |
|
| 152 | + */ |
|
| 153 | + public function buildRequest(string $method, array $arguments) : \GuzzleHttp\Psr7\Request |
|
| 154 | + { |
|
| 155 | + $requestBody = $this->buildXMLBody($method, $arguments)->asXML(); |
|
| 156 | + return new GuzzleRequest('POST', self::BASE_URL, ['Content-Type' => 'application/x-www-form-urlencoded; charset=UTF8'], $requestBody); |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * Checks if Request Requires Session ID |
|
| 161 | + * @method isSessionRequiredForMethod |
|
| 162 | + * @author PA |
|
| 163 | + * @date 2017-01-10 |
|
| 164 | + * @param string $method YourMembership API Method |
|
| 165 | + * @return bool |
|
| 166 | + */ |
|
| 167 | + public function isSessionRequiredForMethod(string $method) : bool |
|
| 168 | + { |
|
| 169 | + //TODO Add config Logic for what API Methods require Session ID |
|
| 170 | + return ($method != 'Session.Create'); |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + /** |
|
| 174 | + * Helper for Deep Copy for of $from element into $to element for SimpleXML |
|
| 175 | + * @method sxmlAppend |
|
| 176 | + * @author PA |
|
| 177 | + * @date 2017-01-09 |
|
| 178 | + * @param \SimpleXMLElement $to |
|
| 179 | + * @param \SimpleXMLElement $from |
|
| 180 | + * @return void |
|
| 181 | + */ |
|
| 182 | + private function sxmlAppend(\SimpleXMLElement $to, \SimpleXMLElement $from) { |
|
| 183 | + $toDom = dom_import_simplexml($to); |
|
| 184 | + $fromDom = dom_import_simplexml($from); |
|
| 185 | + $toDom->appendChild($toDom->ownerDocument->importNode($fromDom, true)); |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + /** |
|
| 189 | + * Adds the Session Variable to the given XML Request Payload |
|
| 190 | + * @method addSessionIdToRequest |
|
| 191 | + * @author PA |
|
| 192 | + * @date 2017-01-10 |
|
| 193 | + * @param \SimpleXMLElement $requestXML Base Request XML Payload |
|
| 194 | + */ |
|
| 195 | + private function addSessionIdToRequest(\SimpleXMLElement $requestXML) : \SimpleXMLElement |
|
| 196 | + { |
|
| 197 | + $requestXML->addChild('SessionID', self::$sessionId); |
|
| 198 | + return $requestXML; |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + |
|
| 202 | + /** |
|
| 203 | + * Setter Method for SessionID |
|
| 204 | + * @method setSessionId |
|
| 205 | + * @author PA |
|
| 206 | + * @date 2017-01-10 |
|
| 207 | + * @param string $sessionId YourMembership Session ID |
|
| 208 | + */ |
|
| 209 | + public static function setSessionId(string $sessionId) |
|
| 210 | + { |
|
| 211 | + self::$sessionId = $sessionId; |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + /** |
|
| 215 | + * Checks if we have an active session available |
|
| 216 | + * @method hasSession |
|
| 217 | + * @author PA |
|
| 218 | + * @date 2017-01-11 |
|
| 219 | + * @return boolean |
|
| 220 | + */ |
|
| 221 | + public function hasSession() |
|
| 222 | + { |
|
| 223 | + return !is_null(self::$sessionId); |
|
| 224 | + } |
|
| 225 | 225 | |
| 226 | 226 | } |
@@ -87,8 +87,8 @@ discard block |
||
| 87 | 87 | |
| 88 | 88 | //Add Arguments to the Call Node |
| 89 | 89 | try { |
| 90 | - $call = $this->sxmlAddChildrenRecursive($call,$arguments); |
|
| 91 | - } catch(\Exception $e) { |
|
| 90 | + $call = $this->sxmlAddChildrenRecursive($call, $arguments); |
|
| 91 | + } catch (\Exception $e) { |
|
| 92 | 92 | throw new YourMembershipRequestException($e->getMessage(), $e->getCode(), $method, $arguments, $e); |
| 93 | 93 | } |
| 94 | 94 | return $call; |
@@ -107,9 +107,9 @@ discard block |
||
| 107 | 107 | { |
| 108 | 108 | foreach ($arguments as $key => $value) { |
| 109 | 109 | if (is_array($value)) { |
| 110 | - $child = new \SimpleXMLElement(sprintf('<%s></%s>',$key, $key)); |
|
| 110 | + $child = new \SimpleXMLElement(sprintf('<%s></%s>', $key, $key)); |
|
| 111 | 111 | $this->sxmlAddChildrenRecursive($child, $value); |
| 112 | - $this->sxmlAppend($root,$child); |
|
| 112 | + $this->sxmlAppend($root, $child); |
|
| 113 | 113 | } else { |
| 114 | 114 | $root->addChild($key, $value); |
| 115 | 115 | } |
@@ -1,16 +1,15 @@ |
||
| 1 | 1 | <?php |
| 2 | - /** |
|
| 3 | - * Your Membership Settings |
|
| 4 | - * |
|
| 5 | - |
|
| 6 | - */ |
|
| 2 | + /** |
|
| 3 | + * Your Membership Settings |
|
| 4 | + * |
|
| 5 | + */ |
|
| 7 | 6 | return [ |
| 8 | - /** |
|
| 9 | - * Default Guzzle Client Settings used by the provider |
|
| 10 | - */ |
|
| 11 | - 'guzzle-client' => [ |
|
| 12 | - 'base_uri' => null, |
|
| 13 | - 'timeout' => 5.0 |
|
| 14 | - ], |
|
| 7 | + /** |
|
| 8 | + * Default Guzzle Client Settings used by the provider |
|
| 9 | + */ |
|
| 10 | + 'guzzle-client' => [ |
|
| 11 | + 'base_uri' => null, |
|
| 12 | + 'timeout' => 5.0 |
|
| 13 | + ], |
|
| 15 | 14 | |
| 16 | 15 | ]; |
@@ -8,117 +8,117 @@ |
||
| 8 | 8 | */ |
| 9 | 9 | class Response |
| 10 | 10 | { |
| 11 | - private $method; |
|
| 12 | - private $response; |
|
| 11 | + private $method; |
|
| 12 | + private $response; |
|
| 13 | 13 | |
| 14 | - public function __construct(string $method, $response) |
|
| 15 | - { |
|
| 16 | - $this->method = $method; |
|
| 14 | + public function __construct(string $method, $response) |
|
| 15 | + { |
|
| 16 | + $this->method = $method; |
|
| 17 | 17 | |
| 18 | - $body = $response->getBody()->getContents(); |
|
| 19 | - $this->response = new \SimpleXMLElement($body); |
|
| 18 | + $body = $response->getBody()->getContents(); |
|
| 19 | + $this->response = new \SimpleXMLElement($body); |
|
| 20 | 20 | |
| 21 | - } |
|
| 21 | + } |
|
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * Checks if the response contains an Error |
|
| 25 | - * @method hasError |
|
| 26 | - * @author PA |
|
| 27 | - * @date 2017-01-10 |
|
| 28 | - * @return bool hasError |
|
| 29 | - */ |
|
| 30 | - public function hasError() : bool |
|
| 31 | - { |
|
| 32 | - return ($this->getErrorCode() != 0); |
|
| 33 | - } |
|
| 23 | + /** |
|
| 24 | + * Checks if the response contains an Error |
|
| 25 | + * @method hasError |
|
| 26 | + * @author PA |
|
| 27 | + * @date 2017-01-10 |
|
| 28 | + * @return bool hasError |
|
| 29 | + */ |
|
| 30 | + public function hasError() : bool |
|
| 31 | + { |
|
| 32 | + return ($this->getErrorCode() != 0); |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * Fetches the Error Code from the Response |
|
| 37 | - * @method getErrorCode |
|
| 38 | - * @author PA |
|
| 39 | - * @date 2017-01-10 |
|
| 40 | - * @return int Error Code |
|
| 41 | - */ |
|
| 42 | - public function getErrorCode() : int |
|
| 43 | - { |
|
| 44 | - return (int) $this->response->ErrCode; |
|
| 45 | - } |
|
| 35 | + /** |
|
| 36 | + * Fetches the Error Code from the Response |
|
| 37 | + * @method getErrorCode |
|
| 38 | + * @author PA |
|
| 39 | + * @date 2017-01-10 |
|
| 40 | + * @return int Error Code |
|
| 41 | + */ |
|
| 42 | + public function getErrorCode() : int |
|
| 43 | + { |
|
| 44 | + return (int) $this->response->ErrCode; |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * Fetches the Error Message From Response |
|
| 49 | - * @method getError |
|
| 50 | - * @author PA |
|
| 51 | - * @date 2017-01-10 |
|
| 52 | - * @return string Error Message |
|
| 53 | - */ |
|
| 54 | - public function getError() : string |
|
| 55 | - { |
|
| 56 | - return (string) $this->response->ErrDesc; |
|
| 57 | - } |
|
| 47 | + /** |
|
| 48 | + * Fetches the Error Message From Response |
|
| 49 | + * @method getError |
|
| 50 | + * @author PA |
|
| 51 | + * @date 2017-01-10 |
|
| 52 | + * @return string Error Message |
|
| 53 | + */ |
|
| 54 | + public function getError() : string |
|
| 55 | + { |
|
| 56 | + return (string) $this->response->ErrDesc; |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * Converts the response to an Array |
|
| 61 | - * @method toArray |
|
| 62 | - * @throws YourMembershipRequestException |
|
| 63 | - * @author PA |
|
| 64 | - * @date 2017-01-10 |
|
| 65 | - * @return array Response |
|
| 66 | - */ |
|
| 67 | - public function toArray() : array |
|
| 68 | - { |
|
| 69 | - return $this->unwrapXMLObject(true); |
|
| 70 | - } |
|
| 59 | + /** |
|
| 60 | + * Converts the response to an Array |
|
| 61 | + * @method toArray |
|
| 62 | + * @throws YourMembershipRequestException |
|
| 63 | + * @author PA |
|
| 64 | + * @date 2017-01-10 |
|
| 65 | + * @return array Response |
|
| 66 | + */ |
|
| 67 | + public function toArray() : array |
|
| 68 | + { |
|
| 69 | + return $this->unwrapXMLObject(true); |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * Converts the response to an Object |
|
| 74 | - * @method toObject |
|
| 75 | - * @throws YourMembershipRequestException |
|
| 76 | - * @author PA |
|
| 77 | - * @date 2017-01-11 |
|
| 78 | - * @return stdClass Response |
|
| 79 | - */ |
|
| 80 | - public function toObject() : \stdClass |
|
| 81 | - { |
|
| 82 | - return $this->unwrapXMLObject(false); |
|
| 83 | - } |
|
| 72 | + /** |
|
| 73 | + * Converts the response to an Object |
|
| 74 | + * @method toObject |
|
| 75 | + * @throws YourMembershipRequestException |
|
| 76 | + * @author PA |
|
| 77 | + * @date 2017-01-11 |
|
| 78 | + * @return stdClass Response |
|
| 79 | + */ |
|
| 80 | + public function toObject() : \stdClass |
|
| 81 | + { |
|
| 82 | + return $this->unwrapXMLObject(false); |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - /** |
|
| 86 | - * Unwraps XML Object into either StdClass or Array |
|
| 87 | - * Lossy conversion, attributes are lost from XML |
|
| 88 | - * |
|
| 89 | - * @method unwrapXMLObject |
|
| 90 | - * @throws YourMembershipRequestException |
|
| 91 | - * @author PA |
|
| 92 | - * @date 2017-01-11 |
|
| 93 | - * @param bool $asArray unwrap the object into an array instead of object |
|
| 94 | - * @return mixed|null Unwrapped Response |
|
| 95 | - */ |
|
| 96 | - private function unwrapXMLObject(bool $asArray) |
|
| 97 | - { |
|
| 98 | - //We cannot unwrap objects that have errors, so throw an exception |
|
| 99 | - if ($this->hasError()) { |
|
| 100 | - throw new YourMembershipResponseException($this->getError(), $this->getErrorCode(), $this->method); |
|
| 101 | - } |
|
| 85 | + /** |
|
| 86 | + * Unwraps XML Object into either StdClass or Array |
|
| 87 | + * Lossy conversion, attributes are lost from XML |
|
| 88 | + * |
|
| 89 | + * @method unwrapXMLObject |
|
| 90 | + * @throws YourMembershipRequestException |
|
| 91 | + * @author PA |
|
| 92 | + * @date 2017-01-11 |
|
| 93 | + * @param bool $asArray unwrap the object into an array instead of object |
|
| 94 | + * @return mixed|null Unwrapped Response |
|
| 95 | + */ |
|
| 96 | + private function unwrapXMLObject(bool $asArray) |
|
| 97 | + { |
|
| 98 | + //We cannot unwrap objects that have errors, so throw an exception |
|
| 99 | + if ($this->hasError()) { |
|
| 100 | + throw new YourMembershipResponseException($this->getError(), $this->getErrorCode(), $this->method); |
|
| 101 | + } |
|
| 102 | 102 | |
| 103 | - return json_decode(json_encode($this->response->{$this->method}), $asArray); |
|
| 104 | - } |
|
| 105 | - /** |
|
| 106 | - * Returns the Result Count |
|
| 107 | - * @method getResultCount |
|
| 108 | - * @author PA |
|
| 109 | - * @date 2017-01-10 |
|
| 110 | - * @return int|false false if no ResultCount is present |
|
| 111 | - */ |
|
| 112 | - public function getResultCount() : int |
|
| 113 | - { |
|
| 114 | - $count = false; |
|
| 103 | + return json_decode(json_encode($this->response->{$this->method}), $asArray); |
|
| 104 | + } |
|
| 105 | + /** |
|
| 106 | + * Returns the Result Count |
|
| 107 | + * @method getResultCount |
|
| 108 | + * @author PA |
|
| 109 | + * @date 2017-01-10 |
|
| 110 | + * @return int|false false if no ResultCount is present |
|
| 111 | + */ |
|
| 112 | + public function getResultCount() : int |
|
| 113 | + { |
|
| 114 | + $count = false; |
|
| 115 | 115 | |
| 116 | - if (isset($this->response->{$this->method}->Results)) { |
|
| 117 | - $attributes = $this->response->{$this->method}->Results->attributes(); |
|
| 118 | - $count = (int) $attributes['ResultTotal'] ?? false; |
|
| 119 | - } |
|
| 116 | + if (isset($this->response->{$this->method}->Results)) { |
|
| 117 | + $attributes = $this->response->{$this->method}->Results->attributes(); |
|
| 118 | + $count = (int) $attributes['ResultTotal'] ?? false; |
|
| 119 | + } |
|
| 120 | 120 | |
| 121 | - return $count; |
|
| 122 | - } |
|
| 121 | + return $count; |
|
| 122 | + } |
|
| 123 | 123 | |
| 124 | 124 | } |
@@ -10,54 +10,54 @@ |
||
| 10 | 10 | * Package Config Name |
| 11 | 11 | * @var string |
| 12 | 12 | */ |
| 13 | - private $packageName = 'yourmembership'; |
|
| 13 | + private $packageName = 'yourmembership'; |
|
| 14 | 14 | /** |
| 15 | 15 | * Package Config Path |
| 16 | 16 | * @var string |
| 17 | 17 | */ |
| 18 | - private $packageConfigPath = __DIR__.'/config/yourmembership.php'; |
|
| 19 | - /** |
|
| 20 | - * Indicates if loading of the provider is deferred. |
|
| 21 | - * |
|
| 22 | - * @var bool |
|
| 23 | - */ |
|
| 24 | - protected $defer = true; |
|
| 18 | + private $packageConfigPath = __DIR__.'/config/yourmembership.php'; |
|
| 19 | + /** |
|
| 20 | + * Indicates if loading of the provider is deferred. |
|
| 21 | + * |
|
| 22 | + * @var bool |
|
| 23 | + */ |
|
| 24 | + protected $defer = true; |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * Register the service provider. |
|
| 28 | - * |
|
| 29 | - * @return void |
|
| 30 | - */ |
|
| 31 | - public function register() |
|
| 32 | - { |
|
| 33 | - $this->mergeConfigFrom( |
|
| 34 | - $this->packageConfigPath, $this->packageName |
|
| 35 | - ); |
|
| 26 | + /** |
|
| 27 | + * Register the service provider. |
|
| 28 | + * |
|
| 29 | + * @return void |
|
| 30 | + */ |
|
| 31 | + public function register() |
|
| 32 | + { |
|
| 33 | + $this->mergeConfigFrom( |
|
| 34 | + $this->packageConfigPath, $this->packageName |
|
| 35 | + ); |
|
| 36 | 36 | |
| 37 | - $this->app->bind(YourMembershipClient::class, function ($app, $parameters) { |
|
| 38 | - $guzzleClient = new \GuzzleHttp\Client($app['config']['yourmembership']['guzzle-client']); |
|
| 39 | - return new YourMembershipClient($guzzleClient, $parameters[0], $parameters[1]); |
|
| 40 | - }); |
|
| 41 | - } |
|
| 37 | + $this->app->bind(YourMembershipClient::class, function ($app, $parameters) { |
|
| 38 | + $guzzleClient = new \GuzzleHttp\Client($app['config']['yourmembership']['guzzle-client']); |
|
| 39 | + return new YourMembershipClient($guzzleClient, $parameters[0], $parameters[1]); |
|
| 40 | + }); |
|
| 41 | + } |
|
| 42 | 42 | /** |
| 43 | 43 | * Boot the service provider. |
| 44 | 44 | * |
| 45 | 45 | * @return void |
| 46 | 46 | */ |
| 47 | - public function boot() |
|
| 48 | - { |
|
| 49 | - $this->publishes([ |
|
| 50 | - $this->packageConfigPath => config_path('yourmembership.php'), |
|
| 51 | - ]); |
|
| 52 | - } |
|
| 47 | + public function boot() |
|
| 48 | + { |
|
| 49 | + $this->publishes([ |
|
| 50 | + $this->packageConfigPath => config_path('yourmembership.php'), |
|
| 51 | + ]); |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * Get the services provided by the provider. |
|
| 56 | - * |
|
| 57 | - * @return array |
|
| 58 | - */ |
|
| 59 | - public function provides() |
|
| 60 | - { |
|
| 61 | - return [YourMembershipClient::class]; |
|
| 62 | - } |
|
| 54 | + /** |
|
| 55 | + * Get the services provided by the provider. |
|
| 56 | + * |
|
| 57 | + * @return array |
|
| 58 | + */ |
|
| 59 | + public function provides() |
|
| 60 | + { |
|
| 61 | + return [YourMembershipClient::class]; |
|
| 62 | + } |
|
| 63 | 63 | } |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | * Package Config Path |
| 16 | 16 | * @var string |
| 17 | 17 | */ |
| 18 | - private $packageConfigPath = __DIR__.'/config/yourmembership.php'; |
|
| 18 | + private $packageConfigPath = __DIR__ . '/config/yourmembership.php'; |
|
| 19 | 19 | /** |
| 20 | 20 | * Indicates if loading of the provider is deferred. |
| 21 | 21 | * |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | $this->packageConfigPath, $this->packageName |
| 35 | 35 | ); |
| 36 | 36 | |
| 37 | - $this->app->bind(YourMembershipClient::class, function ($app, $parameters) { |
|
| 37 | + $this->app->bind(YourMembershipClient::class, function($app, $parameters) { |
|
| 38 | 38 | $guzzleClient = new \GuzzleHttp\Client($app['config']['yourmembership']['guzzle-client']); |
| 39 | 39 | return new YourMembershipClient($guzzleClient, $parameters[0], $parameters[1]); |
| 40 | 40 | }); |
@@ -32,6 +32,6 @@ |
||
| 32 | 32 | public function __toString() |
| 33 | 33 | { |
| 34 | 34 | return __CLASS__ . ": [{$this->apiMethod}]: {$this->message}\n"; |
| 35 | - } |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | 37 | } |