@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | |
| 5 | 5 | use SugarAPI\SDK\Request\Interfaces\RequestInterface; |
| 6 | 6 | |
| 7 | -abstract class AbstractRequest implements RequestInterface{ |
|
| 7 | +abstract class AbstractRequest implements RequestInterface { |
|
| 8 | 8 | |
| 9 | 9 | /** |
| 10 | 10 | * The HTTP Request Type |
@@ -67,14 +67,14 @@ discard block |
||
| 67 | 67 | */ |
| 68 | 68 | protected $type; |
| 69 | 69 | |
| 70 | - public function __construct($url = null){ |
|
| 70 | + public function __construct($url = null) { |
|
| 71 | 71 | $this->start(); |
| 72 | - if (!empty($url)){ |
|
| 72 | + if (!empty($url)) { |
|
| 73 | 73 | $this->setURL($url); |
| 74 | 74 | } |
| 75 | 75 | $this->setType(); |
| 76 | - foreach(static::$_DEFAULT_OPTIONS as $option => $value){ |
|
| 77 | - $this->setOption($option,$value); |
|
| 76 | + foreach (static::$_DEFAULT_OPTIONS as $option => $value) { |
|
| 77 | + $this->setOption($option, $value); |
|
| 78 | 78 | } |
| 79 | 79 | } |
| 80 | 80 | |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | */ |
| 84 | 84 | public function setURL($url) { |
| 85 | 85 | $this->url = $url; |
| 86 | - $this->setOption(CURLOPT_URL,$this->url); |
|
| 86 | + $this->setOption(CURLOPT_URL, $this->url); |
|
| 87 | 87 | return $this; |
| 88 | 88 | } |
| 89 | 89 | |
@@ -165,22 +165,22 @@ discard block |
||
| 165 | 165 | /** |
| 166 | 166 | * @inheritdoc |
| 167 | 167 | */ |
| 168 | - public function getResponse(){ |
|
| 168 | + public function getResponse() { |
|
| 169 | 169 | return $this->CurlResponse; |
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | /** |
| 173 | 173 | * Set the Type on the Request |
| 174 | 174 | */ |
| 175 | - protected function setType(){ |
|
| 175 | + protected function setType() { |
|
| 176 | 176 | $this->type = static::$_TYPE; |
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | /** |
| 180 | 180 | * @inheritdoc |
| 181 | 181 | */ |
| 182 | - public function reset(){ |
|
| 183 | - if (is_object($this->CurlRequest)){ |
|
| 182 | + public function reset() { |
|
| 183 | + if (is_object($this->CurlRequest)) { |
|
| 184 | 184 | $this->close(); |
| 185 | 185 | } |
| 186 | 186 | $this->start(); |
@@ -198,7 +198,7 @@ discard block |
||
| 198 | 198 | /** |
| 199 | 199 | * @inheritdoc |
| 200 | 200 | */ |
| 201 | - public function close(){ |
|
| 201 | + public function close() { |
|
| 202 | 202 | curl_close($this->CurlRequest); |
| 203 | 203 | unset($this->CurlRequest); |
| 204 | 204 | return $this; |
@@ -133,6 +133,7 @@ |
||
| 133 | 133 | |
| 134 | 134 | /** |
| 135 | 135 | * @inheritdoc |
| 136 | + * @param string $body |
|
| 136 | 137 | */ |
| 137 | 138 | public function setBody($body) { |
| 138 | 139 | $this->body = $body; |
@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | |
| 5 | 5 | use SugarAPI\SDK\Request\Abstracts\AbstractRequest; |
| 6 | 6 | |
| 7 | -class POST extends AbstractRequest{ |
|
| 7 | +class POST extends AbstractRequest { |
|
| 8 | 8 | |
| 9 | 9 | protected static $_TYPE = 'POST'; |
| 10 | 10 | |
@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | * |
| 14 | 14 | * Set the Curl POST Option to True |
| 15 | 15 | */ |
| 16 | - protected function setType(){ |
|
| 16 | + protected function setType() { |
|
| 17 | 17 | parent::setType(); |
| 18 | 18 | $this->setOption(CURLOPT_POST, 1); |
| 19 | 19 | } |
@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | |
| 5 | 5 | use SugarAPI\SDK\Request\Abstracts\AbstractRequest; |
| 6 | 6 | |
| 7 | -class DELETE extends AbstractRequest{ |
|
| 7 | +class DELETE extends AbstractRequest { |
|
| 8 | 8 | |
| 9 | 9 | protected static $_TYPE = 'DELETE'; |
| 10 | 10 | |
@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | * |
| 14 | 14 | * Set the Curl Custom Request Option to DELETE |
| 15 | 15 | */ |
| 16 | - protected function setType(){ |
|
| 16 | + protected function setType() { |
|
| 17 | 17 | parent::setType(); |
| 18 | 18 | $this->setOption(CURLOPT_CUSTOMREQUEST, "DELETE"); |
| 19 | 19 | } |
@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | |
| 5 | 5 | use SugarAPI\SDK\Request\Abstracts\AbstractRequest; |
| 6 | 6 | |
| 7 | -class PUT extends AbstractRequest{ |
|
| 7 | +class PUT extends AbstractRequest { |
|
| 8 | 8 | |
| 9 | 9 | protected static $_TYPE = 'PUT'; |
| 10 | 10 | |
@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | * |
| 14 | 14 | * Set the Curl Custom Request Option to PUT |
| 15 | 15 | */ |
| 16 | - protected function setType(){ |
|
| 16 | + protected function setType() { |
|
| 17 | 17 | parent::setType(); |
| 18 | 18 | $this->setOption(CURLOPT_CUSTOMREQUEST, "PUT"); |
| 19 | 19 | } |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | * @param $value - Header Value |
| 24 | 24 | * @return SugarAPI\SDK\Request Object |
| 25 | 25 | */ |
| 26 | - public function addHeader($name,$value); |
|
| 26 | + public function addHeader($name, $value); |
|
| 27 | 27 | |
| 28 | 28 | /** |
| 29 | 29 | * Sets the Headers on the Curl Request object, called during Sending. Appends to Request Headers property |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | * @param $value - Curl Option Value |
| 51 | 51 | * @return SugarAPI\SDK\Request Object |
| 52 | 52 | */ |
| 53 | - public function setOption($option,$value); |
|
| 53 | + public function setOption($option, $value); |
|
| 54 | 54 | |
| 55 | 55 | /** |
| 56 | 56 | * Set the URL on the Request Object |
@@ -189,10 +189,10 @@ discard block |
||
| 189 | 189 | if ($urlVarCount!==$optionCount){ |
| 190 | 190 | if (empty($this->Module)){ |
| 191 | 191 | throw new EntryPointExecutionFailure('missing_module'); |
| 192 | - }else{ |
|
| 192 | + } else{ |
|
| 193 | 193 | throw new EntryPointExecutionFailure('missing_options'); |
| 194 | 194 | } |
| 195 | - }else{ |
|
| 195 | + } else{ |
|
| 196 | 196 | return true; |
| 197 | 197 | } |
| 198 | 198 | } |
@@ -203,18 +203,18 @@ discard block |
||
| 203 | 203 | protected function validateData(){ |
| 204 | 204 | if (empty($this->_REQUIRED_DATA)||count($this->_REQUIRED_DATA)==0){ |
| 205 | 205 | return true; |
| 206 | - }else{ |
|
| 206 | + } else{ |
|
| 207 | 207 | $errors = array(); |
| 208 | 208 | foreach($this->_REQUIRED_DATA as $property){ |
| 209 | 209 | if (isset($this->Data[$property]) || $this->Data[$property]!==null){ |
| 210 | 210 | continue; |
| 211 | - }else{ |
|
| 211 | + } else{ |
|
| 212 | 212 | $errors[] = $property; |
| 213 | 213 | } |
| 214 | 214 | } |
| 215 | 215 | if (count($errors)>0){ |
| 216 | 216 | throw new EntryPointExecutionFailure('missing_data'); |
| 217 | - }else{ |
|
| 217 | + } else{ |
|
| 218 | 218 | return true; |
| 219 | 219 | } |
| 220 | 220 | } |
@@ -22,13 +22,13 @@ discard block |
||
| 22 | 22 | protected $Request; |
| 23 | 23 | protected $Response; |
| 24 | 24 | |
| 25 | - public function __construct($url,$options = array()){ |
|
| 25 | + public function __construct($url, $options = array()) { |
|
| 26 | 26 | $this->url = $url; |
| 27 | 27 | $this->Module = $this->_MODULE; |
| 28 | 28 | |
| 29 | 29 | if (!empty($options)) { |
| 30 | 30 | if (empty($this->Module)) { |
| 31 | - if (strpos($this->_URL, '$module') !== FALSE) { |
|
| 31 | + if (strpos($this->_URL, '$module')!==FALSE) { |
|
| 32 | 32 | $this->module($options[0]); |
| 33 | 33 | array_shift($options); |
| 34 | 34 | } |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | /** |
| 42 | 42 | * @inheritdoc |
| 43 | 43 | */ |
| 44 | - public function module($module){ |
|
| 44 | + public function module($module) { |
|
| 45 | 45 | $this->Module = $module; |
| 46 | 46 | return $this; |
| 47 | 47 | } |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | /** |
| 50 | 50 | * @inheritdoc |
| 51 | 51 | */ |
| 52 | - public function options(array $options){ |
|
| 52 | + public function options(array $options) { |
|
| 53 | 53 | $this->Options = $options; |
| 54 | 54 | return $this; |
| 55 | 55 | } |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | /** |
| 58 | 58 | * @inheritdoc |
| 59 | 59 | */ |
| 60 | - public function data(array $data){ |
|
| 60 | + public function data(array $data) { |
|
| 61 | 61 | $this->Data = $data; |
| 62 | 62 | $this->Request->setBody($this->Data); |
| 63 | 63 | return $this; |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | /** |
| 67 | 67 | * @inheritdoc |
| 68 | 68 | */ |
| 69 | - public function execute(){ |
|
| 69 | + public function execute() { |
|
| 70 | 70 | if ($this->verifyURL() && $this->validateData()) { |
| 71 | 71 | $this->configureURL(); |
| 72 | 72 | $this->Request->setURL($this->url); |
@@ -96,28 +96,28 @@ discard block |
||
| 96 | 96 | /** |
| 97 | 97 | * |
| 98 | 98 | */ |
| 99 | - public function getData(){ |
|
| 99 | + public function getData() { |
|
| 100 | 100 | return $this->Data; |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | /** |
| 104 | 104 | * @inheritdoc |
| 105 | 105 | */ |
| 106 | - public function getURL(){ |
|
| 106 | + public function getURL() { |
|
| 107 | 107 | return $this->url; |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | /** |
| 111 | 111 | * @inheritdoc |
| 112 | 112 | */ |
| 113 | - public function getResponse(){ |
|
| 113 | + public function getResponse() { |
|
| 114 | 114 | return $this->Response; |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | /** |
| 118 | 118 | * @inheritdoc |
| 119 | 119 | */ |
| 120 | - public function getRequest(){ |
|
| 120 | + public function getRequest() { |
|
| 121 | 121 | return $this->Request; |
| 122 | 122 | } |
| 123 | 123 | |
@@ -126,32 +126,32 @@ discard block |
||
| 126 | 126 | * - Replaces $module with $this->Module |
| 127 | 127 | * - Replcaes all other variables starting with $, with options in the order they were given |
| 128 | 128 | */ |
| 129 | - protected function configureURL(){ |
|
| 129 | + protected function configureURL() { |
|
| 130 | 130 | $url = $this->_URL; |
| 131 | - if (strpos($this->_URL,"$")!==FALSE) { |
|
| 132 | - if (count($this->Options) > 0 || !empty($this->Module)) { |
|
| 131 | + if (strpos($this->_URL, "$")!==FALSE) { |
|
| 132 | + if (count($this->Options)>0 || !empty($this->Module)) { |
|
| 133 | 133 | $urlParts = explode("/", $this->_URL); |
| 134 | 134 | $o = 0; |
| 135 | 135 | foreach ($urlParts as $key => $part) { |
| 136 | - if (strpos($part, '$module') !== FALSE) { |
|
| 136 | + if (strpos($part, '$module')!==FALSE) { |
|
| 137 | 137 | if (isset($this->Module)) { |
| 138 | 138 | $urlParts[$key] = $this->Module; |
| 139 | 139 | continue; |
| 140 | - } else { |
|
| 140 | + }else { |
|
| 141 | 141 | if (isset($this->Options[$o])) { |
| 142 | 142 | $this->Module = $this->Options[$o]; |
| 143 | 143 | array_shift($this->Options); |
| 144 | 144 | } |
| 145 | 145 | } |
| 146 | 146 | } |
| 147 | - if (strpos($part, "$") !== FALSE) { |
|
| 147 | + if (strpos($part, "$")!==FALSE) { |
|
| 148 | 148 | if (isset($this->Options[$o])) { |
| 149 | 149 | $urlParts[$key] = $this->Options[$o]; |
| 150 | 150 | $o++; |
| 151 | 151 | } |
| 152 | 152 | } |
| 153 | 153 | } |
| 154 | - $url = implode($urlParts,"/"); |
|
| 154 | + $url = implode($urlParts, "/"); |
|
| 155 | 155 | } |
| 156 | 156 | } |
| 157 | 157 | $this->url = $this->url.$url; |
@@ -160,15 +160,15 @@ discard block |
||
| 160 | 160 | /** |
| 161 | 161 | * Setup the Request Object property, setup on initial Construct of EntryPoint |
| 162 | 162 | */ |
| 163 | - protected function setupRequest(){ |
|
| 163 | + protected function setupRequest() { |
|
| 164 | 164 | $this->Request = new POST(); |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | /** |
| 168 | 168 | * Setup the Response Object Property, not called until after Request Execution |
| 169 | 169 | */ |
| 170 | - protected function setupResponse(){ |
|
| 171 | - $this->Response = new JSONResponse($this->Request->getResponse(),$this->Request->getCurlObject()); |
|
| 170 | + protected function setupResponse() { |
|
| 171 | + $this->Response = new JSONResponse($this->Request->getResponse(), $this->Request->getCurlObject()); |
|
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | /** |
@@ -176,20 +176,20 @@ discard block |
||
| 176 | 176 | * @return bool |
| 177 | 177 | * @throws EntryPointExecutionFailure |
| 178 | 178 | */ |
| 179 | - protected function verifyURL(){ |
|
| 180 | - $urlVarCount = substr_count($this->_URL,"$"); |
|
| 179 | + protected function verifyURL() { |
|
| 180 | + $urlVarCount = substr_count($this->_URL, "$"); |
|
| 181 | 181 | $optionCount = 0; |
| 182 | - if (!empty($this->Module)){ |
|
| 182 | + if (!empty($this->Module)) { |
|
| 183 | 183 | $optionCount++; |
| 184 | 184 | } |
| 185 | 185 | $optionCount += count($this->Options); |
| 186 | - if ($urlVarCount!==$optionCount){ |
|
| 187 | - if (empty($this->Module) && strpos($this->_URL,'$module')){ |
|
| 186 | + if ($urlVarCount!==$optionCount) { |
|
| 187 | + if (empty($this->Module) && strpos($this->_URL, '$module')) { |
|
| 188 | 188 | throw new EntryPointException('Module is required for EntryPoint '.get_called_class()); |
| 189 | - }else{ |
|
| 189 | + }else { |
|
| 190 | 190 | throw new EntryPointException('EntryPoint URL ('.$this->_URL.') requires more parameters than passed.'); |
| 191 | 191 | } |
| 192 | - }else{ |
|
| 192 | + }else { |
|
| 193 | 193 | return true; |
| 194 | 194 | } |
| 195 | 195 | } |
@@ -197,21 +197,21 @@ discard block |
||
| 197 | 197 | /** |
| 198 | 198 | * @return bool |
| 199 | 199 | */ |
| 200 | - protected function validateData(){ |
|
| 201 | - if (empty($this->_REQUIRED_DATA)||count($this->_REQUIRED_DATA)==0){ |
|
| 200 | + protected function validateData() { |
|
| 201 | + if (empty($this->_REQUIRED_DATA) || count($this->_REQUIRED_DATA)==0) { |
|
| 202 | 202 | return true; |
| 203 | - }else{ |
|
| 203 | + }else { |
|
| 204 | 204 | $errors = array(); |
| 205 | - foreach($this->_REQUIRED_DATA as $property){ |
|
| 206 | - if (isset($this->Data[$property]) || $this->Data[$property]!==null){ |
|
| 205 | + foreach ($this->_REQUIRED_DATA as $property) { |
|
| 206 | + if (isset($this->Data[$property]) || $this->Data[$property]!==null) { |
|
| 207 | 207 | continue; |
| 208 | - }else{ |
|
| 208 | + }else { |
|
| 209 | 209 | $errors[] = $property; |
| 210 | 210 | } |
| 211 | 211 | } |
| 212 | - if (count($errors)>0){ |
|
| 213 | - throw new EntryPointException('EntryPoint requires specific properties in Request data. Missing the following '.implode($errors,",")); |
|
| 214 | - }else{ |
|
| 212 | + if (count($errors)>0) { |
|
| 213 | + throw new EntryPointException('EntryPoint requires specific properties in Request data. Missing the following '.implode($errors, ",")); |
|
| 214 | + }else { |
|
| 215 | 215 | return true; |
| 216 | 216 | } |
| 217 | 217 | } |
@@ -1,7 +1,7 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -require_once __DIR__ . '/../vendor/autoload.php'; |
|
| 3 | +require_once __DIR__.'/../vendor/autoload.php'; |
|
| 4 | 4 | |
| 5 | -$SugarAPI = new \SugarAPI\SDK\SugarAPI('instances.this/Ent/7621/',array('username' => 'admin','password'=>'asdf')); |
|
| 5 | +$SugarAPI = new \SugarAPI\SDK\SugarAPI('instances.this/Ent/7621/', array('username' => 'admin', 'password'=>'asdf')); |
|
| 6 | 6 | $SugarAPI->login(); |
| 7 | 7 | print_r($SugarAPI->getToken()); |
| 8 | 8 | \ No newline at end of file |
@@ -68,6 +68,9 @@ |
||
| 68 | 68 | } |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | + /** |
|
| 72 | + * @param string $className |
|
| 73 | + */ |
|
| 71 | 74 | public function registerEntryPoint($funcName,$className){ |
| 72 | 75 | if (isset($this->entryPoints[$funcName])){ |
| 73 | 76 | throw new SDKException('SDK method already defined. Method '.$funcName.' references Class '.$className); |
@@ -2,8 +2,6 @@ |
||
| 2 | 2 | |
| 3 | 3 | namespace SugarAPI\SDK; |
| 4 | 4 | |
| 5 | -use SugarAPI\SDK\Exception\InitializationFailure; |
|
| 6 | -use SugarAPI\SDK\Exception\InvalidEntryPoint; |
|
| 7 | 5 | use SugarAPI\SDK\Exception\AuthenticationException; |
| 8 | 6 | use SugarAPI\SDK\Exception\SDKException; |
| 9 | 7 | |
@@ -28,102 +28,102 @@ |
||
| 28 | 28 | |
| 29 | 29 | private $entryPoints = array(); |
| 30 | 30 | |
| 31 | - public function __construct($instance='',array $authOptions = array()){ |
|
| 31 | + public function __construct($instance = '', array $authOptions = array()) { |
|
| 32 | 32 | $this->loadDefaults(); |
| 33 | - if (!empty($instance)){ |
|
| 33 | + if (!empty($instance)) { |
|
| 34 | 34 | $this->setInstance($instance); |
| 35 | 35 | } |
| 36 | - if (!empty($authOptions)){ |
|
| 36 | + if (!empty($authOptions)) { |
|
| 37 | 37 | $this->setAuthOptions($authOptions); |
| 38 | 38 | } |
| 39 | 39 | $this->registerSDKEntryPoints(); |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | - protected function loadDefaults(){ |
|
| 43 | - include __DIR__ .DIRECTORY_SEPARATOR.'defaults.php'; |
|
| 42 | + protected function loadDefaults() { |
|
| 43 | + include __DIR__.DIRECTORY_SEPARATOR.'defaults.php'; |
|
| 44 | 44 | if (isset($defaults)) { |
| 45 | 45 | static::$_DEFAULTS = $defaults; |
| 46 | - if (isset($defaults['instance'])){ |
|
| 46 | + if (isset($defaults['instance'])) { |
|
| 47 | 47 | $this->setInstance($defaults['instance']); |
| 48 | 48 | } |
| 49 | - if (isset($defaults['auth']) && is_array($defaults['auth'])){ |
|
| 49 | + if (isset($defaults['auth']) && is_array($defaults['auth'])) { |
|
| 50 | 50 | $this->setAuthOptions($defaults['auth']); |
| 51 | 51 | } |
| 52 | 52 | } |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | - public function setAuthOptions(array $options){ |
|
| 56 | - foreach($this->authOptions as $key => $value){ |
|
| 57 | - if (isset($options[$key])){ |
|
| 55 | + public function setAuthOptions(array $options) { |
|
| 56 | + foreach ($this->authOptions as $key => $value) { |
|
| 57 | + if (isset($options[$key])) { |
|
| 58 | 58 | $this->authOptions[$key] = $options[$key]; |
| 59 | 59 | } |
| 60 | 60 | } |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | - protected function registerSDKEntryPoints(){ |
|
| 64 | - require __DIR__ .DIRECTORY_SEPARATOR.'EntryPoint' .DIRECTORY_SEPARATOR.'registry.php'; |
|
| 65 | - foreach($entryPoints as $funcName => $className){ |
|
| 63 | + protected function registerSDKEntryPoints() { |
|
| 64 | + require __DIR__.DIRECTORY_SEPARATOR.'EntryPoint'.DIRECTORY_SEPARATOR.'registry.php'; |
|
| 65 | + foreach ($entryPoints as $funcName => $className) { |
|
| 66 | 66 | $className = "SugarAPI\\SDK\\EntryPoint\\".$className; |
| 67 | - $this->registerEntryPoint($funcName,$className); |
|
| 67 | + $this->registerEntryPoint($funcName, $className); |
|
| 68 | 68 | } |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | - public function registerEntryPoint($funcName,$className){ |
|
| 72 | - if (isset($this->entryPoints[$funcName])){ |
|
| 71 | + public function registerEntryPoint($funcName, $className) { |
|
| 72 | + if (isset($this->entryPoints[$funcName])) { |
|
| 73 | 73 | throw new SDKException('SDK method already defined. Method '.$funcName.' references Class '.$className); |
| 74 | 74 | } |
| 75 | 75 | $this->entryPoints[$funcName] = $className; |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | - public function __call($name,$params){ |
|
| 79 | - if (array_key_exists($name,$this->entryPoints)){ |
|
| 78 | + public function __call($name, $params) { |
|
| 79 | + if (array_key_exists($name, $this->entryPoints)) { |
|
| 80 | 80 | $Class = $this->entryPoints[$name]; |
| 81 | - $EntryPoint = new $Class($this->url,$params); |
|
| 81 | + $EntryPoint = new $Class($this->url, $params); |
|
| 82 | 82 | |
| 83 | - if ($EntryPoint->authRequired()){ |
|
| 83 | + if ($EntryPoint->authRequired()) { |
|
| 84 | 84 | if (isset($this->authToken)) { |
| 85 | 85 | $EntryPoint->getRequest()->addHeader('OAuth-Token', $this->authToken->access_token); |
| 86 | - }else{ |
|
| 86 | + }else { |
|
| 87 | 87 | throw new AuthenticationException('no_auth'); |
| 88 | 88 | } |
| 89 | 89 | } |
| 90 | 90 | return $EntryPoint; |
| 91 | - }else{ |
|
| 91 | + }else { |
|
| 92 | 92 | throw new SDKException('Method '.$name.', is not a registered method of the SugarAPI SDK'); |
| 93 | 93 | } |
| 94 | 94 | } |
| 95 | - public function login(){ |
|
| 96 | - if (empty($this->authOptions['username']) || empty($this->authOptions['password'])){ |
|
| 95 | + public function login() { |
|
| 96 | + if (empty($this->authOptions['username']) || empty($this->authOptions['password'])) { |
|
| 97 | 97 | throw new AuthenticationException("Username or Password was not provided."); |
| 98 | 98 | } |
| 99 | 99 | $EP = $this->accessToken(); |
| 100 | 100 | $response = $EP->data($this->authOptions)->execute()->getResponse(); |
| 101 | - if ($response->getStatus()=='200'){ |
|
| 101 | + if ($response->getStatus()=='200') { |
|
| 102 | 102 | $this->authToken = $response->getBody(); |
| 103 | - }else{ |
|
| 103 | + }else { |
|
| 104 | 104 | throw new AuthenticationException($response->getBody()); |
| 105 | 105 | } |
| 106 | 106 | } |
| 107 | - public function setInstance($instance){ |
|
| 108 | - if (strpos("https",$instance)!==FALSE){ |
|
| 107 | + public function setInstance($instance) { |
|
| 108 | + if (strpos("https", $instance)!==FALSE) { |
|
| 109 | 109 | $this->secure = TRUE; |
| 110 | 110 | } |
| 111 | - if (strpos("http",$instance)===FALSE){ |
|
| 111 | + if (strpos("http", $instance)===FALSE) { |
|
| 112 | 112 | $instance = "http://".$instance; |
| 113 | 113 | } |
| 114 | - if (strpos("rest/v10",$instance)!==FALSE){ |
|
| 115 | - $instance = str_replace("rest/v10","",$instance); |
|
| 114 | + if (strpos("rest/v10", $instance)!==FALSE) { |
|
| 115 | + $instance = str_replace("rest/v10", "", $instance); |
|
| 116 | 116 | } |
| 117 | 117 | $this->instance = $instance; |
| 118 | - $this->url = rtrim($this->instance,"/").self::API_URL; |
|
| 118 | + $this->url = rtrim($this->instance, "/").self::API_URL; |
|
| 119 | 119 | } |
| 120 | - public function getURL(){ |
|
| 120 | + public function getURL() { |
|
| 121 | 121 | return $this->url; |
| 122 | 122 | } |
| 123 | - public function getToken(){ |
|
| 123 | + public function getToken() { |
|
| 124 | 124 | return $this->authToken; |
| 125 | 125 | } |
| 126 | - public function getAuthOptions(){ |
|
| 126 | + public function getAuthOptions() { |
|
| 127 | 127 | return $this->authOptions; |
| 128 | 128 | } |
| 129 | 129 | } |
| 130 | 130 | \ No newline at end of file |
@@ -83,12 +83,12 @@ discard block |
||
| 83 | 83 | if ($EntryPoint->authRequired()){ |
| 84 | 84 | if (isset($this->authToken)) { |
| 85 | 85 | $EntryPoint->getRequest()->addHeader('OAuth-Token', $this->authToken->access_token); |
| 86 | - }else{ |
|
| 86 | + } else{ |
|
| 87 | 87 | throw new AuthenticationException('no_auth'); |
| 88 | 88 | } |
| 89 | 89 | } |
| 90 | 90 | return $EntryPoint; |
| 91 | - }else{ |
|
| 91 | + } else{ |
|
| 92 | 92 | throw new SDKException('Method '.$name.', is not a registered method of the SugarAPI SDK'); |
| 93 | 93 | } |
| 94 | 94 | } |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | $response = $EP->data($this->authOptions)->execute()->getResponse(); |
| 101 | 101 | if ($response->getStatus()=='200'){ |
| 102 | 102 | $this->authToken = $response->getBody(); |
| 103 | - }else{ |
|
| 103 | + } else{ |
|
| 104 | 104 | throw new AuthenticationException($response->getBody()); |
| 105 | 105 | } |
| 106 | 106 | } |
@@ -4,7 +4,7 @@ |
||
| 4 | 4 | |
| 5 | 5 | use SugarAPI\SDK\EntryPoint\Abstracts\GET\FileEntryPoint as GETFileEntryPoint; |
| 6 | 6 | |
| 7 | -class RecordFileField extends GETFileEntryPoint{ |
|
| 7 | +class RecordFileField extends GETFileEntryPoint { |
|
| 8 | 8 | |
| 9 | 9 | protected $_URL = '$module/$record/file/$field'; |
| 10 | 10 | |