@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | protected $isJson = true; |
| 60 | 60 | |
| 61 | 61 | private function closeConnection() { |
| 62 | - if(null !== $this->con) { |
|
| 62 | + if (null !== $this->con) { |
|
| 63 | 63 | curl_close($this->con); |
| 64 | 64 | } |
| 65 | 65 | } |
@@ -239,7 +239,7 @@ discard block |
||
| 239 | 239 | $this->url = NULL; |
| 240 | 240 | $this->params = array(); |
| 241 | 241 | $this->headers = array(); |
| 242 | - Logger::log("Context service for " . get_called_class() . " cleared!"); |
|
| 242 | + Logger::log("Context service for ".get_called_class()." cleared!"); |
|
| 243 | 243 | $this->closeConnection(); |
| 244 | 244 | } |
| 245 | 245 | |
@@ -281,17 +281,17 @@ discard block |
||
| 281 | 281 | } |
| 282 | 282 | |
| 283 | 283 | protected function applyOptions() { |
| 284 | - if(count($this->options)) { |
|
| 284 | + if (count($this->options)) { |
|
| 285 | 285 | curl_setopt_array($this->con, $this->options); |
| 286 | 286 | } |
| 287 | 287 | } |
| 288 | 288 | |
| 289 | 289 | protected function applyHeaders() { |
| 290 | 290 | $headers = []; |
| 291 | - foreach($this->headers as $key => $value) { |
|
| 292 | - $headers[] = $key . ': ' . $value; |
|
| 291 | + foreach ($this->headers as $key => $value) { |
|
| 292 | + $headers[] = $key.': '.$value; |
|
| 293 | 293 | } |
| 294 | - if(count($headers)) { |
|
| 294 | + if (count($headers)) { |
|
| 295 | 295 | curl_setopt($this->con, CURLOPT_HTTPHEADER, $headers); |
| 296 | 296 | } |
| 297 | 297 | } |
@@ -302,13 +302,13 @@ discard block |
||
| 302 | 302 | case 'GET': |
| 303 | 303 | default: |
| 304 | 304 | $this->addOption(CURLOPT_CUSTOMREQUEST, "GET"); |
| 305 | - $this->setUrl($this->getUrl() . '?' . http_build_query($this->params)); |
|
| 305 | + $this->setUrl($this->getUrl().'?'.http_build_query($this->params)); |
|
| 306 | 306 | break; |
| 307 | 307 | case 'POST': |
| 308 | 308 | $this->addOption(CURLOPT_CUSTOMREQUEST, "POST"); |
| 309 | - if($this->getIsJson()) { |
|
| 309 | + if ($this->getIsJson()) { |
|
| 310 | 310 | $this->addOption(CURLOPT_POSTFIELDS, json_encode($this->params)); |
| 311 | - } else { |
|
| 311 | + }else { |
|
| 312 | 312 | $this->addOption(CURLOPT_POSTFIELDS, http_build_query($this->params)); |
| 313 | 313 | } |
| 314 | 314 | break; |
@@ -318,17 +318,17 @@ discard block |
||
| 318 | 318 | case 'PUT': |
| 319 | 319 | $this->addOption(CURLOPT_CUSTOMREQUEST, "PUT"); |
| 320 | 320 | |
| 321 | - if($this->getIsJson()) { |
|
| 321 | + if ($this->getIsJson()) { |
|
| 322 | 322 | $this->addOption(CURLOPT_POSTFIELDS, json_encode($this->params)); |
| 323 | - } else { |
|
| 323 | + }else { |
|
| 324 | 324 | $this->addOption(CURLOPT_POSTFIELDS, http_build_query($this->params)); |
| 325 | 325 | } |
| 326 | 326 | break; |
| 327 | 327 | case 'PATCH': |
| 328 | 328 | $this->addOption(CURLOPT_CUSTOMREQUEST, "PATCH"); |
| 329 | - if($this->getIsJson()) { |
|
| 329 | + if ($this->getIsJson()) { |
|
| 330 | 330 | $this->addOption(CURLOPT_POSTFIELDS, json_encode($this->params)); |
| 331 | - } else { |
|
| 331 | + }else { |
|
| 332 | 332 | $this->addOption(CURLOPT_POSTFIELDS, http_build_query($this->params)); |
| 333 | 333 | } |
| 334 | 334 | break; |
@@ -345,14 +345,14 @@ discard block |
||
| 345 | 345 | $this->setDefaults(); |
| 346 | 346 | $this->applyOptions(); |
| 347 | 347 | $this->applyHeaders(); |
| 348 | - if('debug' === Config::getParam('log.level')) { |
|
| 348 | + if ('debug' === Config::getParam('log.level')) { |
|
| 349 | 349 | curl_setopt($this->con, CURLOPT_VERBOSE, true); |
| 350 | 350 | $verbose = fopen('php://temp', 'w+'); |
| 351 | 351 | curl_setopt($this->con, CURLOPT_STDERR, $verbose); |
| 352 | 352 | } |
| 353 | 353 | $result = curl_exec($this->con); |
| 354 | 354 | $this->result = $this->isJson ? json_decode($result, true) : $result; |
| 355 | - if('debug' === Config::getParam('log.level')) { |
|
| 355 | + if ('debug' === Config::getParam('log.level')) { |
|
| 356 | 356 | rewind($verbose); |
| 357 | 357 | $verboseLog = stream_get_contents($verbose); |
| 358 | 358 | Logger::log($verboseLog, LOG_DEBUG, [ |
@@ -361,7 +361,7 @@ discard block |
||
| 361 | 361 | 'url' => $this->getUrl(), |
| 362 | 362 | ]); |
| 363 | 363 | } |
| 364 | - Logger::log($this->url . ' response: ', LOG_DEBUG, $this->result); |
|
| 364 | + Logger::log($this->url.' response: ', LOG_DEBUG, $this->result); |
|
| 365 | 365 | $this->info = curl_getinfo($this->con); |
| 366 | 366 | } |
| 367 | 367 | |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | protected function createConnection(TableMap $tableMap) |
| 27 | 27 | { |
| 28 | 28 | $this->con = Propel::getConnection($tableMap::DATABASE_NAME); |
| 29 | - if(method_exists($this->con, 'useDebug')) { |
|
| 29 | + if (method_exists($this->con, 'useDebug')) { |
|
| 30 | 30 | Logger::log('Enabling debug queries mode', LOG_INFO); |
| 31 | 31 | $this->con->useDebug(Config::getParam('debug')); |
| 32 | 32 | } |
@@ -39,12 +39,12 @@ discard block |
||
| 39 | 39 | */ |
| 40 | 40 | protected function closeTransaction($status) |
| 41 | 41 | { |
| 42 | - if(null !== $this->con) { |
|
| 42 | + if (null !== $this->con) { |
|
| 43 | 43 | $this->traceDebugQuery(); |
| 44 | 44 | if (null !== $this->con && $this->con->inTransaction()) { |
| 45 | 45 | if ($status === 200) { |
| 46 | 46 | $this->con->commit(); |
| 47 | - } else { |
|
| 47 | + }else { |
|
| 48 | 48 | $this->con->rollBack(); |
| 49 | 49 | } |
| 50 | 50 | } |
@@ -72,15 +72,15 @@ discard block |
||
| 72 | 72 | public function init() |
| 73 | 73 | { |
| 74 | 74 | parent::init(); |
| 75 | - Logger::log(get_called_class() . ' init', LOG_DEBUG); |
|
| 75 | + Logger::log(get_called_class().' init', LOG_DEBUG); |
|
| 76 | 76 | $this->domain = $this->getDomain(); |
| 77 | 77 | $this->hydrateRequestData(); |
| 78 | 78 | $this->hydrateOrders(); |
| 79 | - if($this instanceof CustomApi === false) { |
|
| 79 | + if ($this instanceof CustomApi === false) { |
|
| 80 | 80 | $this->createConnection($this->getTableMap()); |
| 81 | 81 | } |
| 82 | 82 | $this->setLoaded(true); |
| 83 | - Logger::log(get_called_class() . ' loaded', LOG_DEBUG); |
|
| 83 | + Logger::log(get_called_class().' loaded', LOG_DEBUG); |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | /** |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | protected function hydrateOrders() |
| 90 | 90 | { |
| 91 | 91 | if (count($this->query)) { |
| 92 | - Logger::log(get_called_class() . ' gathering query string', LOG_DEBUG); |
|
| 92 | + Logger::log(get_called_class().' gathering query string', LOG_DEBUG); |
|
| 93 | 93 | foreach ($this->query as $key => $value) { |
| 94 | 94 | if ($key === self::API_ORDER_FIELD) { |
| 95 | 95 | foreach ($value as $field => $direction) { |
@@ -106,10 +106,10 @@ discard block |
||
| 106 | 106 | */ |
| 107 | 107 | protected function extractPagination() |
| 108 | 108 | { |
| 109 | - Logger::log(get_called_class() . ' extract pagination start', LOG_DEBUG); |
|
| 109 | + Logger::log(get_called_class().' extract pagination start', LOG_DEBUG); |
|
| 110 | 110 | $page = (array_key_exists(self::API_PAGE_FIELD, $this->query)) ? $this->query[self::API_PAGE_FIELD] : 1; |
| 111 | 111 | $limit = (array_key_exists(self::API_LIMIT_FIELD, $this->query)) ? $this->query[self::API_LIMIT_FIELD] : 100; |
| 112 | - Logger::log(get_called_class() . ' extract pagination end', LOG_DEBUG); |
|
| 112 | + Logger::log(get_called_class().' extract pagination end', LOG_DEBUG); |
|
| 113 | 113 | return array($page, $limit); |
| 114 | 114 | } |
| 115 | 115 | |
@@ -118,9 +118,9 @@ discard block |
||
| 118 | 118 | * |
| 119 | 119 | * @param ModelCriteria $query |
| 120 | 120 | */ |
| 121 | - private function addOrders(ModelCriteria &$query) |
|
| 121 | + private function addOrders(ModelCriteria & $query) |
|
| 122 | 122 | { |
| 123 | - Logger::log(get_called_class() . ' extract orders start ', LOG_DEBUG); |
|
| 123 | + Logger::log(get_called_class().' extract orders start ', LOG_DEBUG); |
|
| 124 | 124 | $orderAdded = FALSE; |
| 125 | 125 | $tableMap = $this->getTableMap(); |
| 126 | 126 | foreach ($this->order->getOrders() as $field => $direction) { |
@@ -128,17 +128,17 @@ discard block |
||
| 128 | 128 | $orderAdded = TRUE; |
| 129 | 129 | if ($direction === Order::ASC) { |
| 130 | 130 | $query->addAscendingOrderByColumn($column->getPhpName()); |
| 131 | - } else { |
|
| 131 | + }else { |
|
| 132 | 132 | $query->addDescendingOrderByColumn($column->getPhpName()); |
| 133 | 133 | } |
| 134 | 134 | } |
| 135 | 135 | } |
| 136 | 136 | if (!$orderAdded) { |
| 137 | - foreach($this->getPkDbName() as $pk => $phpName) { |
|
| 137 | + foreach ($this->getPkDbName() as $pk => $phpName) { |
|
| 138 | 138 | $query->addAscendingOrderByColumn($pk); |
| 139 | 139 | } |
| 140 | 140 | } |
| 141 | - Logger::log(get_called_class() . ' extract orders end', LOG_DEBUG); |
|
| 141 | + Logger::log(get_called_class().' extract orders end', LOG_DEBUG); |
|
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | /** |
@@ -146,14 +146,14 @@ discard block |
||
| 146 | 146 | * |
| 147 | 147 | * @param ModelCriteria $query |
| 148 | 148 | */ |
| 149 | - protected function addFilters(ModelCriteria &$query) |
|
| 149 | + protected function addFilters(ModelCriteria & $query) |
|
| 150 | 150 | { |
| 151 | 151 | if (count($this->query) > 0) { |
| 152 | 152 | $tableMap = $this->getTableMap(); |
| 153 | 153 | foreach ($this->query as $field => $value) { |
| 154 | 154 | if (self::API_COMBO_FIELD === $field) { |
| 155 | 155 | ApiHelper::composerComboField($tableMap, $query, $this->extraColumns, $value); |
| 156 | - } elseif(!preg_match('/^__/', $field)) { |
|
| 156 | + } elseif (!preg_match('/^__/', $field)) { |
|
| 157 | 157 | ApiHelper::addModelField($tableMap, $query, $field, $value); |
| 158 | 158 | } |
| 159 | 159 | } |
@@ -174,10 +174,10 @@ discard block |
||
| 174 | 174 | list($page, $limit) = $this->extractPagination(); |
| 175 | 175 | if ($limit == -1) { |
| 176 | 176 | $this->list = $query->find($this->con); |
| 177 | - } else { |
|
| 177 | + }else { |
|
| 178 | 178 | $this->list = $query->paginate($page, $limit, $this->con); |
| 179 | 179 | } |
| 180 | - } catch (\Exception $e) { |
|
| 180 | + }catch (\Exception $e) { |
|
| 181 | 181 | Logger::log($e->getMessage(), LOG_ERR); |
| 182 | 182 | } |
| 183 | 183 | } |
@@ -196,7 +196,7 @@ discard block |
||
| 196 | 196 | $code = 200; |
| 197 | 197 | list($return, $total, $pages) = $this->getList(); |
| 198 | 198 | $message = null; |
| 199 | - if(!$total) { |
|
| 199 | + if (!$total) { |
|
| 200 | 200 | $message = _('No se han encontrado elementos para la búsqueda'); |
| 201 | 201 | } |
| 202 | 202 | |
@@ -222,7 +222,7 @@ discard block |
||
| 222 | 222 | $pages = 1; |
| 223 | 223 | $message = null; |
| 224 | 224 | list($code, $return) = $this->getSingleResult($pk); |
| 225 | - if($code !== 200) { |
|
| 225 | + if ($code !== 200) { |
|
| 226 | 226 | $message = _('No se ha encontrado el elemento solicitado'); |
| 227 | 227 | } |
| 228 | 228 | |
@@ -251,11 +251,11 @@ discard block |
||
| 251 | 251 | $status = 200; |
| 252 | 252 | $saved = TRUE; |
| 253 | 253 | $model = $this->model->toArray(); |
| 254 | - } else { |
|
| 254 | + }else { |
|
| 255 | 255 | $message = _('No se ha podido guardar el modelo seleccionado'); |
| 256 | 256 | } |
| 257 | - } catch (\Exception $e) { |
|
| 258 | - $message = _('Ha ocurrido un error intentando guardar el elemento: ') .'<br>'. $e->getMessage(); |
|
| 257 | + }catch (\Exception $e) { |
|
| 258 | + $message = _('Ha ocurrido un error intentando guardar el elemento: ').'<br>'.$e->getMessage(); |
|
| 259 | 259 | Logger::log($e->getMessage(), LOG_ERR); |
| 260 | 260 | } |
| 261 | 261 | |
@@ -289,14 +289,14 @@ discard block |
||
| 289 | 289 | $updated = TRUE; |
| 290 | 290 | $status = 200; |
| 291 | 291 | $model = $this->model->toArray(); |
| 292 | - } else { |
|
| 292 | + }else { |
|
| 293 | 293 | $message = _('Ha ocurrido un error intentando actualizar el elemento, por favor revisa los logs'); |
| 294 | 294 | } |
| 295 | - } catch (\Exception $e) { |
|
| 295 | + }catch (\Exception $e) { |
|
| 296 | 296 | $message = $e->getMessage(); |
| 297 | 297 | Logger::getInstance(get_class($this->model))->errorLog($e->getMessage()); |
| 298 | 298 | } |
| 299 | - } else { |
|
| 299 | + }else { |
|
| 300 | 300 | $message = _('No se ha encontrado el modelo al que se hace referencia para actualizar'); |
| 301 | 301 | } |
| 302 | 302 | |
@@ -326,7 +326,7 @@ discard block |
||
| 326 | 326 | $this->model->delete($this->con); |
| 327 | 327 | $deleted = TRUE; |
| 328 | 328 | } |
| 329 | - } catch (\Exception $e) { |
|
| 329 | + }catch (\Exception $e) { |
|
| 330 | 330 | $message = _('Ha ocurrido un error intentando eliminar el elemento, por favor verifica que no tenga otros elementos relacionados'); |
| 331 | 331 | Logger::getInstance(get_class($this->model))->errorLog($e->getMessage()); |
| 332 | 332 | } |
@@ -360,8 +360,8 @@ discard block |
||
| 360 | 360 | $total = $this->list->getNbResults(); |
| 361 | 361 | $pages = $this->list->getLastPage(); |
| 362 | 362 | } |
| 363 | - } catch (\Exception $e) { |
|
| 364 | - Logger::log(get_class($this) . ': ' . $e->getMessage(), LOG_ERR); |
|
| 363 | + }catch (\Exception $e) { |
|
| 364 | + Logger::log(get_class($this).': '.$e->getMessage(), LOG_ERR); |
|
| 365 | 365 | } |
| 366 | 366 | |
| 367 | 367 | return array($return, $total, $pages); |
@@ -379,7 +379,7 @@ discard block |
||
| 379 | 379 | $return = array(); |
| 380 | 380 | if (NULL === $model || !method_exists($model, 'toArray')) { |
| 381 | 381 | $code = 404; |
| 382 | - } else { |
|
| 382 | + }else { |
|
| 383 | 383 | $return = $model->toArray(); |
| 384 | 384 | } |
| 385 | 385 | |