@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | |
50 | 50 | /** |
51 | 51 | * Método que verifica si existe una cabecera concreta |
52 | - * @param $header |
|
52 | + * @param string $header |
|
53 | 53 | * |
54 | 54 | * @return boolean |
55 | 55 | */ |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | * |
175 | 175 | * @param string $queryParams |
176 | 176 | * |
177 | - * @return mixed |
|
177 | + * @return string |
|
178 | 178 | */ |
179 | 179 | public function getQuery($queryParams) |
180 | 180 | { |
@@ -235,7 +235,7 @@ discard block |
||
235 | 235 | /** |
236 | 236 | * Devuelve un parámetro de $_SERVER |
237 | 237 | * @param string $param |
238 | - * @param $default |
|
238 | + * @param string $default |
|
239 | 239 | * @return string|null |
240 | 240 | */ |
241 | 241 | public function getServer($param, $default = null) |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | */ |
146 | 146 | public static function header($name, $default = null) |
147 | 147 | { |
148 | - return self::getInstance()->getHeader($name, $default); |
|
148 | + return self::getInstance()->getHeader($name, $default); |
|
149 | 149 | } |
150 | 150 | |
151 | 151 | /** |
@@ -158,10 +158,10 @@ discard block |
||
158 | 158 | $header = null; |
159 | 159 | if ($this->hasHeader($name)) { |
160 | 160 | $header = $this->header[$name]; |
161 | - } else if(array_key_exists('h_' . strtolower($name), $this->query)) { |
|
162 | - $header = $this->query['h_' . strtolower($name)]; |
|
163 | - } else if(array_key_exists('HTTP_' . strtoupper(str_replace('-', '_', $name)), $this->server)) { |
|
164 | - $header = $this->server['HTTP_' . strtoupper(str_replace('-', '_', $name))]; |
|
161 | + }else if (array_key_exists('h_'.strtolower($name), $this->query)) { |
|
162 | + $header = $this->query['h_'.strtolower($name)]; |
|
163 | + }else if (array_key_exists('HTTP_'.strtoupper(str_replace('-', '_', $name)), $this->server)) { |
|
164 | + $header = $this->server['HTTP_'.strtoupper(str_replace('-', '_', $name))]; |
|
165 | 165 | } |
166 | 166 | return $header ?: $default; |
167 | 167 | } |
@@ -258,7 +258,7 @@ discard block |
||
258 | 258 | { |
259 | 259 | if (null === $url) $url = $this->getServer('HTTP_ORIGIN'); |
260 | 260 | ob_start(); |
261 | - header('Location: ' . $url); |
|
261 | + header('Location: '.$url); |
|
262 | 262 | ob_end_clean(); |
263 | 263 | Security::getInstance()->updateSession(); |
264 | 264 | exit(_('Redireccionando...')); |
@@ -302,9 +302,9 @@ discard block |
||
302 | 302 | { |
303 | 303 | $url = $this->getServerName(); |
304 | 304 | $protocol = $protocol ? $this->getProtocol() : ''; |
305 | - if (!empty($protocol)) $url = $protocol . $url; |
|
305 | + if (!empty($protocol)) $url = $protocol.$url; |
|
306 | 306 | if (!in_array($this->getServer('SERVER_PORT'), [80, 443], true)) { |
307 | - $url .= ':' . $this->getServer('SERVER_PORT'); |
|
307 | + $url .= ':'.$this->getServer('SERVER_PORT'); |
|
308 | 308 | } |
309 | 309 | return $url; |
310 | 310 | } |
@@ -256,7 +256,9 @@ discard block |
||
256 | 256 | */ |
257 | 257 | public function redirect($url = null) |
258 | 258 | { |
259 | - if (null === $url) $url = $this->getServer('HTTP_ORIGIN'); |
|
259 | + if (null === $url) { |
|
260 | + $url = $this->getServer('HTTP_ORIGIN'); |
|
261 | + } |
|
260 | 262 | ob_start(); |
261 | 263 | header('Location: ' . $url); |
262 | 264 | ob_end_clean(); |
@@ -302,7 +304,9 @@ discard block |
||
302 | 304 | { |
303 | 305 | $url = $this->getServerName(); |
304 | 306 | $protocol = $protocol ? $this->getProtocol() : ''; |
305 | - if (!empty($protocol)) $url = $protocol . $url; |
|
307 | + if (!empty($protocol)) { |
|
308 | + $url = $protocol . $url; |
|
309 | + } |
|
306 | 310 | if (!in_array($this->getServer('SERVER_PORT'), [80, 443], true)) { |
307 | 311 | $url .= ':' . $this->getServer('SERVER_PORT'); |
308 | 312 | } |
@@ -1,13 +1,8 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | namespace PSFS\base\types; |
3 | 3 | |
4 | -use CORE\Models\Customer; |
|
5 | 4 | use CORE\Models\Map\CustomerTableMap; |
6 | 5 | use Propel\Runtime\ActiveQuery\ModelCriteria; |
7 | -use Propel\Runtime\ActiveRecord\ActiveRecordInterface; |
|
8 | -use Propel\Runtime\DataFetcher\ArrayDataFetcher; |
|
9 | -use Propel\Runtime\Formatter\ObjectFormatter; |
|
10 | -use Propel\Runtime\Map\ColumnMap; |
|
11 | 6 | use Propel\Runtime\Map\TableMap; |
12 | 7 | use Propel\Runtime\Propel; |
13 | 8 | use PSFS\base\config\Config; |
@@ -15,10 +10,8 @@ discard block |
||
15 | 10 | use PSFS\base\dto\Order; |
16 | 11 | use PSFS\base\Logger; |
17 | 12 | use PSFS\base\Request; |
18 | -use PSFS\base\Security; |
|
19 | 13 | use PSFS\base\Singleton; |
20 | 14 | use PSFS\base\types\helpers\ApiHelper; |
21 | -use PSFS\base\types\helpers\Inspector; |
|
22 | 15 | use PSFS\base\types\traits\Api\ManagerTrait; |
23 | 16 | |
24 | 17 | /** |
@@ -80,15 +80,15 @@ discard block |
||
80 | 80 | public function init() |
81 | 81 | { |
82 | 82 | parent::init(); |
83 | - Logger::log(get_called_class() . ' init', LOG_DEBUG); |
|
83 | + Logger::log(get_called_class().' init', LOG_DEBUG); |
|
84 | 84 | $this->domain = $this->getDomain(); |
85 | 85 | $this->hydrateRequestData(); |
86 | 86 | $this->hydrateOrders(); |
87 | - if($this instanceof CustomApi === false) { |
|
87 | + if ($this instanceof CustomApi === false) { |
|
88 | 88 | $this->createConnection($this->getTableMap()); |
89 | 89 | } |
90 | 90 | $this->setLoaded(true); |
91 | - Logger::log(get_called_class() . ' loaded', LOG_DEBUG); |
|
91 | + Logger::log(get_called_class().' loaded', LOG_DEBUG); |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | /** |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | protected function hydrateOrders() |
98 | 98 | { |
99 | 99 | if (count($this->query)) { |
100 | - Logger::log(get_called_class() . ' gathering query string', LOG_DEBUG); |
|
100 | + Logger::log(get_called_class().' gathering query string', LOG_DEBUG); |
|
101 | 101 | foreach ($this->query as $key => $value) { |
102 | 102 | if ($key === self::API_ORDER_FIELD && is_array($value)) { |
103 | 103 | foreach ($value as $field => $direction) { |
@@ -114,10 +114,10 @@ discard block |
||
114 | 114 | */ |
115 | 115 | protected function extractPagination() |
116 | 116 | { |
117 | - Logger::log(get_called_class() . ' extract pagination start', LOG_DEBUG); |
|
117 | + Logger::log(get_called_class().' extract pagination start', LOG_DEBUG); |
|
118 | 118 | $page = (array_key_exists(self::API_PAGE_FIELD, $this->query)) ? $this->query[self::API_PAGE_FIELD] : 1; |
119 | 119 | $limit = (array_key_exists(self::API_LIMIT_FIELD, $this->query)) ? $this->query[self::API_LIMIT_FIELD] : 100; |
120 | - Logger::log(get_called_class() . ' extract pagination end', LOG_DEBUG); |
|
120 | + Logger::log(get_called_class().' extract pagination end', LOG_DEBUG); |
|
121 | 121 | return array($page, $limit); |
122 | 122 | } |
123 | 123 | |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | */ |
129 | 129 | private function addOrders(ModelCriteria &$query) |
130 | 130 | { |
131 | - Logger::log(get_called_class() . ' extract orders start ', LOG_DEBUG); |
|
131 | + Logger::log(get_called_class().' extract orders start ', LOG_DEBUG); |
|
132 | 132 | $orderAdded = FALSE; |
133 | 133 | $tableMap = $this->getTableMap(); |
134 | 134 | foreach ($this->order->getOrders() as $field => $direction) { |
@@ -136,17 +136,17 @@ discard block |
||
136 | 136 | $orderAdded = TRUE; |
137 | 137 | if ($direction === Order::ASC) { |
138 | 138 | $query->addAscendingOrderByColumn($column->getPhpName()); |
139 | - } else { |
|
139 | + }else { |
|
140 | 140 | $query->addDescendingOrderByColumn($column->getPhpName()); |
141 | 141 | } |
142 | 142 | } |
143 | 143 | } |
144 | 144 | if (!$orderAdded) { |
145 | - foreach($this->getPkDbName() as $pk => $phpName) { |
|
145 | + foreach ($this->getPkDbName() as $pk => $phpName) { |
|
146 | 146 | $query->addAscendingOrderByColumn($pk); |
147 | 147 | } |
148 | 148 | } |
149 | - Logger::log(get_called_class() . ' extract orders end', LOG_DEBUG); |
|
149 | + Logger::log(get_called_class().' extract orders end', LOG_DEBUG); |
|
150 | 150 | } |
151 | 151 | |
152 | 152 | /** |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | foreach ($this->query as $field => $value) { |
162 | 162 | if (self::API_COMBO_FIELD === $field) { |
163 | 163 | ApiHelper::composerComboField($tableMap, $query, $this->extraColumns, $value); |
164 | - } elseif(!preg_match('/^__/', $field)) { |
|
164 | + } elseif (!preg_match('/^__/', $field)) { |
|
165 | 165 | ApiHelper::addModelField($tableMap, $query, $field, $value); |
166 | 166 | } |
167 | 167 | } |
@@ -182,10 +182,10 @@ discard block |
||
182 | 182 | list($page, $limit) = $this->extractPagination(); |
183 | 183 | if ($limit == -1) { |
184 | 184 | $this->list = $query->find($this->con); |
185 | - } else { |
|
185 | + }else { |
|
186 | 186 | $this->list = $query->paginate($page, $limit, $this->con); |
187 | 187 | } |
188 | - } catch (\Exception $e) { |
|
188 | + }catch (\Exception $e) { |
|
189 | 189 | Logger::log($e->getMessage(), LOG_ERR); |
190 | 190 | } |
191 | 191 | } |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | $code = 200; |
205 | 205 | list($return, $total, $pages) = $this->getList(); |
206 | 206 | $message = null; |
207 | - if(!$total) { |
|
207 | + if (!$total) { |
|
208 | 208 | $message = _('No se han encontrado elementos para la búsqueda'); |
209 | 209 | } |
210 | 210 | |
@@ -230,7 +230,7 @@ discard block |
||
230 | 230 | $pages = 1; |
231 | 231 | $message = null; |
232 | 232 | list($code, $return) = $this->getSingleResult($pk); |
233 | - if($code !== 200) { |
|
233 | + if ($code !== 200) { |
|
234 | 234 | $message = _('No se ha encontrado el elemento solicitado'); |
235 | 235 | } |
236 | 236 | |
@@ -259,11 +259,11 @@ discard block |
||
259 | 259 | $status = 200; |
260 | 260 | $saved = TRUE; |
261 | 261 | $model = $this->model->toArray(); |
262 | - } else { |
|
262 | + }else { |
|
263 | 263 | $message = _('No se ha podido guardar el modelo seleccionado'); |
264 | 264 | } |
265 | - } catch (\Exception $e) { |
|
266 | - $message = _('Ha ocurrido un error intentando guardar el elemento: ') .'<br>'. $e->getMessage(); |
|
265 | + }catch (\Exception $e) { |
|
266 | + $message = _('Ha ocurrido un error intentando guardar el elemento: ').'<br>'.$e->getMessage(); |
|
267 | 267 | Logger::log($e->getMessage(), LOG_ERR); |
268 | 268 | } |
269 | 269 | |
@@ -297,14 +297,14 @@ discard block |
||
297 | 297 | $updated = TRUE; |
298 | 298 | $status = 200; |
299 | 299 | $model = $this->model->toArray(); |
300 | - } else { |
|
300 | + }else { |
|
301 | 301 | $message = _('Ha ocurrido un error intentando actualizar el elemento, por favor revisa los logs'); |
302 | 302 | } |
303 | - } catch (\Exception $e) { |
|
303 | + }catch (\Exception $e) { |
|
304 | 304 | $message = $e->getMessage(); |
305 | 305 | Logger::getInstance(get_class($this->model))->errorLog($e->getMessage()); |
306 | 306 | } |
307 | - } else { |
|
307 | + }else { |
|
308 | 308 | $message = _('No se ha encontrado el modelo al que se hace referencia para actualizar'); |
309 | 309 | } |
310 | 310 | |
@@ -332,13 +332,13 @@ discard block |
||
332 | 332 | $this->con->beginTransaction(); |
333 | 333 | $this->hydrateModel($pk); |
334 | 334 | if (NULL !== $this->model) { |
335 | - if(method_exists('clearAllReferences', $this->model)) { |
|
335 | + if (method_exists('clearAllReferences', $this->model)) { |
|
336 | 336 | $this->model->clearAllReferences(true); |
337 | 337 | } |
338 | 338 | $this->model->delete($this->con); |
339 | 339 | $deleted = TRUE; |
340 | 340 | } |
341 | - } catch (\Exception $e) { |
|
341 | + }catch (\Exception $e) { |
|
342 | 342 | $message = _('Ha ocurrido un error intentando eliminar el elemento, por favor verifica que no tenga otros elementos relacionados'); |
343 | 343 | Logger::getInstance(get_class($this->model))->errorLog($e->getMessage()); |
344 | 344 | } |
@@ -366,7 +366,7 @@ discard block |
||
366 | 366 | $this->saveBulk(); |
367 | 367 | $saved = true; |
368 | 368 | $status = 200; |
369 | - } catch(\Exception $e) { |
|
369 | + }catch (\Exception $e) { |
|
370 | 370 | Logger::log($e->getMessage(), LOG_ERR, $this->getRequest()->getData()); |
371 | 371 | $message = _('Bulk insert rolled back'); |
372 | 372 | } |
@@ -388,7 +388,7 @@ discard block |
||
388 | 388 | |
389 | 389 | /** @var CustomerTableMap $tableMap */ |
390 | 390 | $modelPk = ApiHelper::extractPrimaryKeyColumnName($this->getTableMap()); |
391 | - foreach($this->list->getData() as $data) { |
|
391 | + foreach ($this->list->getData() as $data) { |
|
392 | 392 | $return[] = ApiHelper::mapArrayObject($this->getModelNamespace(), $modelPk, $this->query, $data); |
393 | 393 | } |
394 | 394 | return $return; |
@@ -405,20 +405,20 @@ discard block |
||
405 | 405 | try { |
406 | 406 | $this->paginate(); |
407 | 407 | if (null !== $this->list) { |
408 | - if(array_key_exists(self::API_FIELDS_RESULT_FIELD, $this->query) && Config::getParam('api.field.types')) { |
|
408 | + if (array_key_exists(self::API_FIELDS_RESULT_FIELD, $this->query) && Config::getParam('api.field.types')) { |
|
409 | 409 | $return = $this->extractDataWithFormat(); |
410 | - } else { |
|
410 | + }else { |
|
411 | 411 | $return = $this->list->toArray(null, false, TableMap::TYPE_PHPNAME, false); |
412 | 412 | } |
413 | 413 | $total = 0; |
414 | 414 | $pages = 0; |
415 | - if(null !== $this->list) { |
|
415 | + if (null !== $this->list) { |
|
416 | 416 | $total = $this->list->getNbResults(); |
417 | 417 | $pages = $this->list->getLastPage(); |
418 | 418 | } |
419 | 419 | } |
420 | - } catch (\Exception $e) { |
|
421 | - Logger::log(get_class($this) . ': ' . $e->getMessage(), LOG_ERR); |
|
420 | + }catch (\Exception $e) { |
|
421 | + Logger::log(get_class($this).': '.$e->getMessage(), LOG_ERR); |
|
422 | 422 | } |
423 | 423 | |
424 | 424 | return array($return, $total, $pages); |
@@ -436,7 +436,7 @@ discard block |
||
436 | 436 | $return = array(); |
437 | 437 | if (NULL === $model || !method_exists($model, 'toArray')) { |
438 | 438 | $code = 404; |
439 | - } else { |
|
439 | + }else { |
|
440 | 440 | $return = $model->toArray(); |
441 | 441 | } |
442 | 442 |
@@ -188,7 +188,7 @@ |
||
188 | 188 | } |
189 | 189 | |
190 | 190 | /** |
191 | - * @return integer|boolean |
|
191 | + * @return integer |
|
192 | 192 | */ |
193 | 193 | public static function needCache() |
194 | 194 | { |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | { |
55 | 55 | GeneratorHelper::createDir(dirname($path)); |
56 | 56 | if (false === FileHelper::writeFile($path, $data)) { |
57 | - throw new ConfigException(_('No se tienen los permisos suficientes para escribir en el fichero ') . $path); |
|
57 | + throw new ConfigException(_('No se tienen los permisos suficientes para escribir en el fichero ').$path); |
|
58 | 58 | } |
59 | 59 | } |
60 | 60 | |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | { |
69 | 69 | Logger::log('Gathering data from cache', LOG_DEBUG, ['path' => $path]); |
70 | 70 | $data = null; |
71 | - $absolutePath = $absolute ? $path : CACHE_DIR . DIRECTORY_SEPARATOR . $path; |
|
71 | + $absolutePath = $absolute ? $path : CACHE_DIR.DIRECTORY_SEPARATOR.$path; |
|
72 | 72 | if (file_exists($absolutePath)) { |
73 | 73 | $data = FileHelper::readFile($absolutePath); |
74 | 74 | } |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | private function hasExpiredCache($path, $expires = 300, $absolute = false) |
85 | 85 | { |
86 | 86 | Logger::log('Checking expiration', LOG_DEBUG, ['path' => $path]); |
87 | - $absolutePath = ($absolute) ? $path : CACHE_DIR . DIRECTORY_SEPARATOR . $path; |
|
87 | + $absolutePath = ($absolute) ? $path : CACHE_DIR.DIRECTORY_SEPARATOR.$path; |
|
88 | 88 | $lasModificationDate = filemtime($absolutePath); |
89 | 89 | return ($lasModificationDate + $expires <= time()); |
90 | 90 | } |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | { |
152 | 152 | Logger::log('Store data in cache', LOG_DEBUG, ['path' => $path]); |
153 | 153 | $data = self::transformData($data, $transform); |
154 | - $absolutePath = $absolute ? $path : CACHE_DIR . DIRECTORY_SEPARATOR . $path; |
|
154 | + $absolutePath = $absolute ? $path : CACHE_DIR.DIRECTORY_SEPARATOR.$path; |
|
155 | 155 | $this->saveTextToFile($data, $absolutePath); |
156 | 156 | } |
157 | 157 | |
@@ -168,11 +168,11 @@ discard block |
||
168 | 168 | { |
169 | 169 | $data = null; |
170 | 170 | Logger::log('Reading data from cache', LOG_DEBUG, ['path' => $path]); |
171 | - if (file_exists(CACHE_DIR . DIRECTORY_SEPARATOR . $path)) { |
|
171 | + if (file_exists(CACHE_DIR.DIRECTORY_SEPARATOR.$path)) { |
|
172 | 172 | if (is_callable($function) && $this->hasExpiredCache($path, $expires)) { |
173 | 173 | $data = $function(); |
174 | 174 | $this->storeData($path, $data, $transform, false, $expires); |
175 | - } else { |
|
175 | + }else { |
|
176 | 176 | $data = $this->getDataFromFile($path, $transform); |
177 | 177 | } |
178 | 178 | } |
@@ -224,13 +224,13 @@ discard block |
||
224 | 224 | } |
225 | 225 | |
226 | 226 | public function flushCache() { |
227 | - if(Config::getParam('cache.data.enable', false)) { |
|
227 | + if (Config::getParam('cache.data.enable', false)) { |
|
228 | 228 | Logger::log('Flushing cache', LOG_DEBUG); |
229 | 229 | $action = Security::getInstance()->getSessionKey(self::CACHE_SESSION_VAR); |
230 | - if(is_array($action)) { |
|
231 | - $hashPath = FileHelper::generateCachePath($action, $action['params']) . '..' . DIRECTORY_SEPARATOR . ' .. ' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR; |
|
232 | - if(!file_exists($hashPath)) { |
|
233 | - $hashPath = CACHE_DIR . DIRECTORY_SEPARATOR . $hashPath; |
|
230 | + if (is_array($action)) { |
|
231 | + $hashPath = FileHelper::generateCachePath($action, $action['params']).'..'.DIRECTORY_SEPARATOR.' .. '.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR; |
|
232 | + if (!file_exists($hashPath)) { |
|
233 | + $hashPath = CACHE_DIR.DIRECTORY_SEPARATOR.$hashPath; |
|
234 | 234 | } |
235 | 235 | FileHelper::deleteDir($hashPath); |
236 | 236 | } |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | * @param string $msg |
86 | 86 | * @param array $context |
87 | 87 | * |
88 | - * @return bool |
|
88 | + * @return boolean|null |
|
89 | 89 | */ |
90 | 90 | public function debugLog($msg = '', array $context = []) |
91 | 91 | { |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | } |
94 | 94 | |
95 | 95 | /** |
96 | - * @param $msg |
|
96 | + * @param string $msg |
|
97 | 97 | * @param array $context |
98 | 98 | * |
99 | 99 | * @return bool |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | } |
105 | 105 | |
106 | 106 | /** |
107 | - * @param $msg |
|
107 | + * @param string $msg |
|
108 | 108 | * @param array $context |
109 | 109 | * @return bool |
110 | 110 | */ |
@@ -15,8 +15,8 @@ discard block |
||
15 | 15 | |
16 | 16 | |
17 | 17 | if (!defined('LOG_DIR')) { |
18 | - GeneratorHelper::createDir(BASE_DIR . DIRECTORY_SEPARATOR . 'logs'); |
|
19 | - define('LOG_DIR', BASE_DIR . DIRECTORY_SEPARATOR . 'logs'); |
|
18 | + GeneratorHelper::createDir(BASE_DIR.DIRECTORY_SEPARATOR.'logs'); |
|
19 | + define('LOG_DIR', BASE_DIR.DIRECTORY_SEPARATOR.'logs'); |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | /** |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | $config = Config::getInstance(); |
51 | 51 | $args = func_get_args(); |
52 | 52 | list($logger, $debug, $path) = $this->setup($config, $args); |
53 | - $this->stream = fopen($path . DIRECTORY_SEPARATOR . date('Ymd') . '.log', 'a+'); |
|
53 | + $this->stream = fopen($path.DIRECTORY_SEPARATOR.date('Ymd').'.log', 'a+'); |
|
54 | 54 | $this->addPushLogger($logger, $debug, $config); |
55 | 55 | $this->log_level = Config::getParam('log.level', 'info'); |
56 | 56 | } |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | private function createLoggerPath(Config $config) |
192 | 192 | { |
193 | 193 | $logger = $this->setLoggerName($config); |
194 | - $path = LOG_DIR . DIRECTORY_SEPARATOR . $logger . DIRECTORY_SEPARATOR . date('Y') . DIRECTORY_SEPARATOR . date('m'); |
|
194 | + $path = LOG_DIR.DIRECTORY_SEPARATOR.$logger.DIRECTORY_SEPARATOR.date('Y').DIRECTORY_SEPARATOR.date('m'); |
|
195 | 195 | GeneratorHelper::createDir($path); |
196 | 196 | |
197 | 197 | return $path; |
@@ -204,10 +204,10 @@ discard block |
||
204 | 204 | */ |
205 | 205 | public static function log($msg, $type = LOG_DEBUG, array $context = null) |
206 | 206 | { |
207 | - if(null === $context) { |
|
207 | + if (null === $context) { |
|
208 | 208 | $context = []; |
209 | 209 | } |
210 | - if(Config::getParam('profiling.enable')) { |
|
210 | + if (Config::getParam('profiling.enable')) { |
|
211 | 211 | Inspector::stats($msg); |
212 | 212 | } |
213 | 213 | switch ($type) { |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | } |
180 | 180 | |
181 | 181 | /** |
182 | - * @param $route |
|
182 | + * @param string|null $route |
|
183 | 183 | * @throws AccessDeniedException |
184 | 184 | * @throws AdminCredentialsException |
185 | 185 | * @throws RouterException |
@@ -535,7 +535,7 @@ discard block |
||
535 | 535 | /** |
536 | 536 | * @param bool $hydrateRoute |
537 | 537 | * @param $modulePath |
538 | - * @param $externalModulePath |
|
538 | + * @param string $externalModulePath |
|
539 | 539 | */ |
540 | 540 | private function loadExternalAutoloader($hydrateRoute, SplFileInfo $modulePath, $externalModulePath) |
541 | 541 | { |
@@ -550,7 +550,7 @@ discard block |
||
550 | 550 | } |
551 | 551 | |
552 | 552 | /** |
553 | - * @param $hydrateRoute |
|
553 | + * @param boolean $hydrateRoute |
|
554 | 554 | * @param $module |
555 | 555 | * @return mixed |
556 | 556 | */ |
@@ -75,11 +75,11 @@ discard block |
||
75 | 75 | */ |
76 | 76 | public function init() |
77 | 77 | { |
78 | - list($this->routing, $this->slugs) = $this->cache->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . 'urls.json', $this->cacheType, TRUE); |
|
78 | + list($this->routing, $this->slugs) = $this->cache->getDataFromFile(CONFIG_DIR.DIRECTORY_SEPARATOR.'urls.json', $this->cacheType, TRUE); |
|
79 | 79 | if (empty($this->routing) || Config::getInstance()->getDebugMode()) { |
80 | 80 | $this->debugLoad(); |
81 | - } else { |
|
82 | - $this->domains = $this->cache->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . 'domains.json', $this->cacheType, TRUE); |
|
81 | + }else { |
|
82 | + $this->domains = $this->cache->getDataFromFile(CONFIG_DIR.DIRECTORY_SEPARATOR.'domains.json', $this->cacheType, TRUE); |
|
83 | 83 | } |
84 | 84 | $this->checkExternalModules(false); |
85 | 85 | $this->setLoaded(); |
@@ -117,9 +117,9 @@ discard block |
||
117 | 117 | } |
118 | 118 | |
119 | 119 | $not_found_route = Config::getParam('route.404'); |
120 | - if(null !== $not_found_route) { |
|
120 | + if (null !== $not_found_route) { |
|
121 | 121 | Request::getInstance()->redirect($this->getRoute($not_found_route, true)); |
122 | - } else { |
|
122 | + }else { |
|
123 | 123 | return $template->render('error.html.twig', array( |
124 | 124 | 'exception' => $e, |
125 | 125 | 'trace' => $e->getTraceAsString(), |
@@ -170,12 +170,12 @@ discard block |
||
170 | 170 | try { |
171 | 171 | //Search action and execute |
172 | 172 | $this->searchAction($route); |
173 | - } catch (AccessDeniedException $e) { |
|
174 | - Logger::log(_('Solicitamos credenciales de acceso a zona restringida'), LOG_WARNING, ['file' => $e->getFile() . '[' . $e->getLine() . ']']); |
|
173 | + }catch (AccessDeniedException $e) { |
|
174 | + Logger::log(_('Solicitamos credenciales de acceso a zona restringida'), LOG_WARNING, ['file' => $e->getFile().'['.$e->getLine().']']); |
|
175 | 175 | return Admin::staticAdminLogon($route); |
176 | - } catch (RouterException $r) { |
|
176 | + }catch (RouterException $r) { |
|
177 | 177 | Logger::log($r->getMessage(), LOG_WARNING); |
178 | - } catch (\Exception $e) { |
|
178 | + }catch (\Exception $e) { |
|
179 | 179 | Logger::log($e->getMessage(), LOG_ERR); |
180 | 180 | throw $e; |
181 | 181 | } |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | */ |
193 | 193 | protected function searchAction($route) |
194 | 194 | { |
195 | - Logger::log('Searching action to execute: ' . $route, LOG_INFO); |
|
195 | + Logger::log('Searching action to execute: '.$route, LOG_INFO); |
|
196 | 196 | //Revisamos si tenemos la ruta registrada |
197 | 197 | $parts = parse_url($route); |
198 | 198 | $path = array_key_exists('path', $parts) ? $parts['path'] : $route; |
@@ -207,12 +207,12 @@ discard block |
||
207 | 207 | /** @var $class \PSFS\base\types\Controller */ |
208 | 208 | $class = RouterHelper::getClassToCall($action); |
209 | 209 | try { |
210 | - if($this->checkRequirements($action, $get)) { |
|
210 | + if ($this->checkRequirements($action, $get)) { |
|
211 | 211 | $this->executeCachedRoute($route, $action, $class, $get); |
212 | - } else { |
|
212 | + }else { |
|
213 | 213 | throw new RouterException(_('La ruta no es válida'), 400); |
214 | 214 | } |
215 | - } catch (\Exception $e) { |
|
215 | + }catch (\Exception $e) { |
|
216 | 216 | Logger::log($e->getMessage(), LOG_ERR); |
217 | 217 | throw $e; |
218 | 218 | } |
@@ -227,15 +227,15 @@ discard block |
||
227 | 227 | * @return bool |
228 | 228 | */ |
229 | 229 | private function checkRequirements(array $action, $params = []) { |
230 | - if(!empty($params) && !empty($action['requirements'])) { |
|
230 | + if (!empty($params) && !empty($action['requirements'])) { |
|
231 | 231 | $checked = 0; |
232 | - foreach(array_keys($params) as $key) { |
|
233 | - if(in_array($key, $action['requirements'], true)) { |
|
232 | + foreach (array_keys($params) as $key) { |
|
233 | + if (in_array($key, $action['requirements'], true)) { |
|
234 | 234 | $checked++; |
235 | 235 | } |
236 | 236 | } |
237 | 237 | $valid = count($action['requirements']) === $checked; |
238 | - } else { |
|
238 | + }else { |
|
239 | 239 | $valid = true; |
240 | 240 | } |
241 | 241 | return $valid; |
@@ -285,14 +285,14 @@ discard block |
||
285 | 285 | $this->checkExternalModules(); |
286 | 286 | if (file_exists($modulesPath)) { |
287 | 287 | $modules = $this->finder->directories()->in($modulesPath)->depth(0); |
288 | - if($modules->hasResults()) { |
|
288 | + if ($modules->hasResults()) { |
|
289 | 289 | foreach ($modules->getIterator() as $modulePath) { |
290 | 290 | $module = $modulePath->getBasename(); |
291 | - $this->routing = $this->inspectDir($modulesPath . DIRECTORY_SEPARATOR . $module, $module, $this->routing); |
|
291 | + $this->routing = $this->inspectDir($modulesPath.DIRECTORY_SEPARATOR.$module, $module, $this->routing); |
|
292 | 292 | } |
293 | 293 | } |
294 | 294 | } |
295 | - $this->cache->storeData(CONFIG_DIR . DIRECTORY_SEPARATOR . 'domains.json', $this->domains, Cache::JSON, TRUE); |
|
295 | + $this->cache->storeData(CONFIG_DIR.DIRECTORY_SEPARATOR.'domains.json', $this->domains, Cache::JSON, TRUE); |
|
296 | 296 | } |
297 | 297 | |
298 | 298 | /** |
@@ -308,7 +308,7 @@ discard block |
||
308 | 308 | $home_params = NULL; |
309 | 309 | foreach ($this->routing as $pattern => $params) { |
310 | 310 | list($method, $route) = RouterHelper::extractHttpRoute($pattern); |
311 | - if (preg_match('/' . preg_quote($route, '/') . '$/i', '/' . $home)) { |
|
311 | + if (preg_match('/'.preg_quote($route, '/').'$/i', '/'.$home)) { |
|
312 | 312 | $home_params = $params; |
313 | 313 | } |
314 | 314 | } |
@@ -329,14 +329,14 @@ discard block |
||
329 | 329 | private function inspectDir($origen, $namespace = 'PSFS', $routing = []) |
330 | 330 | { |
331 | 331 | $files = $this->finder->files()->in($origen)->path('/(controller|api)/i')->depth(1)->name('*.php'); |
332 | - if($files->hasResults()) { |
|
332 | + if ($files->hasResults()) { |
|
333 | 333 | foreach ($files->getIterator() as $file) { |
334 | - if(method_exists($file, 'getRelativePathname') && $namespace !== 'PSFS') { |
|
335 | - $filename = '\\' . str_replace('/', '\\', str_replace($origen, '', $file->getRelativePathname())); |
|
336 | - } else { |
|
334 | + if (method_exists($file, 'getRelativePathname') && $namespace !== 'PSFS') { |
|
335 | + $filename = '\\'.str_replace('/', '\\', str_replace($origen, '', $file->getRelativePathname())); |
|
336 | + }else { |
|
337 | 337 | $filename = str_replace('/', '\\', str_replace($origen, '', $file->getPathname())); |
338 | 338 | } |
339 | - $routing = $this->addRouting($namespace . str_replace('.php', '', $filename), $routing, $namespace); |
|
339 | + $routing = $this->addRouting($namespace.str_replace('.php', '', $filename), $routing, $namespace); |
|
340 | 340 | } |
341 | 341 | } |
342 | 342 | $this->finder = new Finder(); |
@@ -365,7 +365,7 @@ discard block |
||
365 | 365 | private function addRouting($namespace, &$routing, $module = 'PSFS') |
366 | 366 | { |
367 | 367 | if (self::exists($namespace)) { |
368 | - if(I18nHelper::checkI18Class($namespace)) { |
|
368 | + if (I18nHelper::checkI18Class($namespace)) { |
|
369 | 369 | return $routing; |
370 | 370 | } |
371 | 371 | $reflection = new \ReflectionClass($namespace); |
@@ -407,7 +407,7 @@ discard block |
||
407 | 407 | if (!$this->domains) { |
408 | 408 | $this->domains = []; |
409 | 409 | } |
410 | - $domain = '@' . $class->getConstant('DOMAIN') . '/'; |
|
410 | + $domain = '@'.$class->getConstant('DOMAIN').'/'; |
|
411 | 411 | if (!array_key_exists($domain, $this->domains)) { |
412 | 412 | $this->domains[$domain] = RouterHelper::extractDomainInfo($class, $domain); |
413 | 413 | } |
@@ -423,11 +423,11 @@ discard block |
||
423 | 423 | */ |
424 | 424 | public function simpatize() |
425 | 425 | { |
426 | - $translationFileName = 'translations' . DIRECTORY_SEPARATOR . 'routes_translations.php'; |
|
427 | - $absoluteTranslationFileName = CACHE_DIR . DIRECTORY_SEPARATOR . $translationFileName; |
|
426 | + $translationFileName = 'translations'.DIRECTORY_SEPARATOR.'routes_translations.php'; |
|
427 | + $absoluteTranslationFileName = CACHE_DIR.DIRECTORY_SEPARATOR.$translationFileName; |
|
428 | 428 | $this->generateSlugs($absoluteTranslationFileName); |
429 | 429 | GeneratorHelper::createDir(CONFIG_DIR); |
430 | - Cache::getInstance()->storeData(CONFIG_DIR . DIRECTORY_SEPARATOR . 'urls.json', array($this->routing, $this->slugs), Cache::JSON, TRUE); |
|
430 | + Cache::getInstance()->storeData(CONFIG_DIR.DIRECTORY_SEPARATOR.'urls.json', array($this->routing, $this->slugs), Cache::JSON, TRUE); |
|
431 | 431 | |
432 | 432 | return $this; |
433 | 433 | } |
@@ -443,18 +443,18 @@ discard block |
||
443 | 443 | public function getRoute($slug = '', $absolute = FALSE, array $params = []) |
444 | 444 | { |
445 | 445 | if ('' === $slug) { |
446 | - return $absolute ? Request::getInstance()->getRootUrl() . '/' : '/'; |
|
446 | + return $absolute ? Request::getInstance()->getRootUrl().'/' : '/'; |
|
447 | 447 | } |
448 | 448 | if (!is_array($this->slugs) || !array_key_exists($slug, $this->slugs)) { |
449 | 449 | throw new RouterException(_('No existe la ruta especificada')); |
450 | 450 | } |
451 | - $url = $absolute ? Request::getInstance()->getRootUrl() . $this->slugs[$slug] : $this->slugs[$slug]; |
|
451 | + $url = $absolute ? Request::getInstance()->getRootUrl().$this->slugs[$slug] : $this->slugs[$slug]; |
|
452 | 452 | if (!empty($params)) { |
453 | 453 | foreach ($params as $key => $value) { |
454 | - $url = str_replace('{' . $key . '}', $value, $url); |
|
454 | + $url = str_replace('{'.$key.'}', $value, $url); |
|
455 | 455 | } |
456 | 456 | } elseif (!empty($this->routing[$this->slugs[$slug]]['default'])) { |
457 | - $url = $absolute ? Request::getInstance()->getRootUrl() . $this->routing[$this->slugs[$slug]]['default'] : $this->routing[$this->slugs[$slug]]['default']; |
|
457 | + $url = $absolute ? Request::getInstance()->getRootUrl().$this->routing[$this->slugs[$slug]]['default'] : $this->routing[$this->slugs[$slug]]['default']; |
|
458 | 458 | } |
459 | 459 | |
460 | 460 | return preg_replace('/(GET|POST|PUT|DELETE|ALL)\#\|\#/', '', $url); |
@@ -496,17 +496,17 @@ discard block |
||
496 | 496 | */ |
497 | 497 | protected function executeCachedRoute($route, $action, $class, $params = NULL) |
498 | 498 | { |
499 | - Logger::log('Executing route ' . $route, LOG_INFO); |
|
499 | + Logger::log('Executing route '.$route, LOG_INFO); |
|
500 | 500 | $action['params'] = array_merge($action['params'], $params, Request::getInstance()->getQueryParams()); |
501 | 501 | Security::getInstance()->setSessionKey(Cache::CACHE_SESSION_VAR, $action); |
502 | 502 | $cache = Cache::needCache(); |
503 | 503 | $execute = TRUE; |
504 | 504 | if (FALSE !== $cache && $action['http'] === 'GET' && Config::getParam('debug') === FALSE) { |
505 | 505 | list($path, $cacheDataName) = $this->cache->getRequestCacheHash(); |
506 | - $cachedData = $this->cache->readFromCache('json' . DIRECTORY_SEPARATOR . $path . $cacheDataName, |
|
506 | + $cachedData = $this->cache->readFromCache('json'.DIRECTORY_SEPARATOR.$path.$cacheDataName, |
|
507 | 507 | $cache); |
508 | 508 | if (NULL !== $cachedData) { |
509 | - $headers = $this->cache->readFromCache('json' . DIRECTORY_SEPARATOR . $path . $cacheDataName . '.headers', |
|
509 | + $headers = $this->cache->readFromCache('json'.DIRECTORY_SEPARATOR.$path.$cacheDataName.'.headers', |
|
510 | 510 | $cache, null, Cache::JSON); |
511 | 511 | Template::getInstance()->renderCache($cachedData, $headers); |
512 | 512 | $execute = FALSE; |
@@ -549,11 +549,11 @@ discard block |
||
549 | 549 | private function loadExternalAutoloader($hydrateRoute, SplFileInfo $modulePath, $externalModulePath) |
550 | 550 | { |
551 | 551 | $extModule = $modulePath->getBasename(); |
552 | - $moduleAutoloader = realpath($externalModulePath . DIRECTORY_SEPARATOR . $extModule . DIRECTORY_SEPARATOR . 'autoload.php'); |
|
553 | - if(file_exists($moduleAutoloader)) { |
|
552 | + $moduleAutoloader = realpath($externalModulePath.DIRECTORY_SEPARATOR.$extModule.DIRECTORY_SEPARATOR.'autoload.php'); |
|
553 | + if (file_exists($moduleAutoloader)) { |
|
554 | 554 | include_once $moduleAutoloader; |
555 | 555 | if ($hydrateRoute) { |
556 | - $this->routing = $this->inspectDir($externalModulePath . DIRECTORY_SEPARATOR . $extModule, '\\' . $extModule, $this->routing); |
|
556 | + $this->routing = $this->inspectDir($externalModulePath.DIRECTORY_SEPARATOR.$extModule, '\\'.$extModule, $this->routing); |
|
557 | 557 | } |
558 | 558 | } |
559 | 559 | } |
@@ -567,14 +567,14 @@ discard block |
||
567 | 567 | { |
568 | 568 | try { |
569 | 569 | $module = preg_replace('/(\\\|\/)/', DIRECTORY_SEPARATOR, $module); |
570 | - $externalModulePath = VENDOR_DIR . DIRECTORY_SEPARATOR . $module . DIRECTORY_SEPARATOR . 'src'; |
|
570 | + $externalModulePath = VENDOR_DIR.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.'src'; |
|
571 | 571 | $externalModule = $this->finder->directories()->in($externalModulePath)->depth(0); |
572 | - if($externalModule->hasResults()) { |
|
572 | + if ($externalModule->hasResults()) { |
|
573 | 573 | foreach ($externalModule->getIterator() as $modulePath) { |
574 | 574 | $this->loadExternalAutoloader($hydrateRoute, $modulePath, $externalModulePath); |
575 | 575 | } |
576 | 576 | } |
577 | - } catch (\Exception $e) { |
|
577 | + }catch (\Exception $e) { |
|
578 | 578 | Logger::log($e->getMessage(), LOG_WARNING); |
579 | 579 | $module = null; |
580 | 580 | } |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | */ |
10 | 10 | class FileHelper { |
11 | 11 | /** |
12 | - * @param mixed $data |
|
12 | + * @param string $data |
|
13 | 13 | * @param string $path |
14 | 14 | * @return int |
15 | 15 | */ |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | } |
53 | 53 | |
54 | 54 | /** |
55 | - * @param $path |
|
55 | + * @param string $path |
|
56 | 56 | * @throws IOException |
57 | 57 | */ |
58 | 58 | public static function deleteDir($path) { |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | */ |
24 | 24 | public static function readFile($path) { |
25 | 25 | $data = false; |
26 | - if(file_exists($path)) { |
|
26 | + if (file_exists($path)) { |
|
27 | 27 | $data = @file_get_contents($path); |
28 | 28 | } |
29 | 29 | return $data; |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | * @return string |
37 | 37 | */ |
38 | 38 | public static function generateHashFilename($verb, $slug, array $query = []) { |
39 | - return sha1(strtolower($verb) . ' ' . $slug . ' ' . strtolower(http_build_query($query))); |
|
39 | + return sha1(strtolower($verb).' '.$slug.' '.strtolower(http_build_query($query))); |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | /** |
@@ -47,8 +47,8 @@ discard block |
||
47 | 47 | public static function generateCachePath(array $action, array $query = []) { |
48 | 48 | $class = GeneratorHelper::extractClassFromNamespace($action['class']); |
49 | 49 | $filename = self::generateHashFilename($action['http'], $action['slug'], $query); |
50 | - $subPath = substr($filename, 0, 2) . DIRECTORY_SEPARATOR . substr($filename, 2, 2); |
|
51 | - return $action['module'] . DIRECTORY_SEPARATOR . $class . DIRECTORY_SEPARATOR . $action['method'] . DIRECTORY_SEPARATOR . $subPath . DIRECTORY_SEPARATOR; |
|
50 | + $subPath = substr($filename, 0, 2).DIRECTORY_SEPARATOR.substr($filename, 2, 2); |
|
51 | + return $action['module'].DIRECTORY_SEPARATOR.$class.DIRECTORY_SEPARATOR.$action['method'].DIRECTORY_SEPARATOR.$subPath.DIRECTORY_SEPARATOR; |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | /** |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | */ |
23 | 23 | public function __construct() |
24 | 24 | { |
25 | - Logger::log(get_class($this) . ' constructor invoked'); |
|
25 | + Logger::log(get_class($this).' constructor invoked'); |
|
26 | 26 | $this->init(); |
27 | 27 | } |
28 | 28 | |
@@ -80,14 +80,14 @@ discard block |
||
80 | 80 | $calledClass = static::class; |
81 | 81 | try { |
82 | 82 | $instance = InjectorHelper::constructInyectableInstance($variable, $singleton, $classNameSpace, $calledClass); |
83 | - $setter = 'set' . ucfirst($variable); |
|
83 | + $setter = 'set'.ucfirst($variable); |
|
84 | 84 | if (method_exists($calledClass, $setter)) { |
85 | 85 | $this->$setter($instance); |
86 | - } else { |
|
86 | + }else { |
|
87 | 87 | $this->$variable = $instance; |
88 | 88 | } |
89 | - } catch (\Exception $e) { |
|
90 | - Logger::log($e->getMessage() . ': ' . $e->getFile() . ' [' . $e->getLine() . ']', LOG_ERR); |
|
89 | + }catch (\Exception $e) { |
|
90 | + Logger::log($e->getMessage().': '.$e->getFile().' ['.$e->getLine().']', LOG_ERR); |
|
91 | 91 | throw $e; |
92 | 92 | } |
93 | 93 | return $this; |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | { |
103 | 103 | if (!$this->isLoaded()) { |
104 | 104 | $filename = sha1(get_class($this)); |
105 | - $cacheFilename = 'reflections' . DIRECTORY_SEPARATOR . substr($filename, 0, 2) . DIRECTORY_SEPARATOR . substr($filename, 2, 2) . DIRECTORY_SEPARATOR . $filename . ".json"; |
|
105 | + $cacheFilename = 'reflections'.DIRECTORY_SEPARATOR.substr($filename, 0, 2).DIRECTORY_SEPARATOR.substr($filename, 2, 2).DIRECTORY_SEPARATOR.$filename.".json"; |
|
106 | 106 | /** @var \PSFS\base\Cache $cacheService */ |
107 | 107 | $cacheService = Cache::getInstance(); |
108 | 108 | /** @var \PSFS\base\config\Config $configService */ |
@@ -120,8 +120,8 @@ discard block |
||
120 | 120 | } |
121 | 121 | } |
122 | 122 | $this->setLoaded(); |
123 | - } else { |
|
124 | - Logger::log(get_class($this) . ' already loaded', LOG_INFO); |
|
123 | + }else { |
|
124 | + Logger::log(get_class($this).' already loaded', LOG_INFO); |
|
125 | 125 | } |
126 | 126 | } |
127 | 127 | } |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | session_start(); |
74 | 74 | } |
75 | 75 | // Fix for phpunits |
76 | - if(!isset($_SESSION)) { |
|
76 | + if (!isset($_SESSION)) { |
|
77 | 77 | $_SESSION = []; |
78 | 78 | } |
79 | 79 | } |
@@ -127,11 +127,11 @@ discard block |
||
127 | 127 | public static function save($user) |
128 | 128 | { |
129 | 129 | $saved = true; |
130 | - $admins = Cache::getInstance()->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . 'admins.json', Cache::JSONGZ, true) ?: []; |
|
131 | - $admins[$user['username']]['hash'] = sha1($user['username'] . $user['password']); |
|
130 | + $admins = Cache::getInstance()->getDataFromFile(CONFIG_DIR.DIRECTORY_SEPARATOR.'admins.json', Cache::JSONGZ, true) ?: []; |
|
131 | + $admins[$user['username']]['hash'] = sha1($user['username'].$user['password']); |
|
132 | 132 | $admins[$user['username']]['profile'] = $user['profile']; |
133 | 133 | |
134 | - Cache::getInstance()->storeData(CONFIG_DIR . DIRECTORY_SEPARATOR . 'admins.json', $admins, Cache::JSONGZ, true); |
|
134 | + Cache::getInstance()->storeData(CONFIG_DIR.DIRECTORY_SEPARATOR.'admins.json', $admins, Cache::JSONGZ, true); |
|
135 | 135 | return $saved; |
136 | 136 | } |
137 | 137 | |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | */ |
175 | 175 | public function getAdmins() |
176 | 176 | { |
177 | - return Cache::getInstance()->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . 'admins.json', Cache::JSONGZ, true); |
|
177 | + return Cache::getInstance()->getDataFromFile(CONFIG_DIR.DIRECTORY_SEPARATOR.'admins.json', Cache::JSONGZ, true); |
|
178 | 178 | } |
179 | 179 | |
180 | 180 | /** |
@@ -199,9 +199,9 @@ discard block |
||
199 | 199 | } |
200 | 200 | if (!empty($user) && !empty($admins[$user])) { |
201 | 201 | $auth = $admins[$user]['hash']; |
202 | - $this->authorized = ($auth === sha1($user . $pass)); |
|
202 | + $this->authorized = ($auth === sha1($user.$pass)); |
|
203 | 203 | if ($this->authorized) { |
204 | - $this->updateAdmin($user , $admins[$user]['profile']); |
|
204 | + $this->updateAdmin($user, $admins[$user]['profile']); |
|
205 | 205 | ResponseHelper::setCookieHeaders([ |
206 | 206 | [ |
207 | 207 | 'name' => $this->getHash(), |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | ]); |
213 | 213 | $this->setSessionKey(self::LOGGED_USER_TOKEN, base64_encode("{$user}:{$pass}")); |
214 | 214 | } |
215 | - } else { |
|
215 | + }else { |
|
216 | 216 | $this->admin = null; |
217 | 217 | $this->setSessionKey(self::ADMIN_ID_TOKEN, null); |
218 | 218 | } |
@@ -17,11 +17,11 @@ discard block |
||
17 | 17 | public static function checkApiActions($namespace, $domain, $api) { |
18 | 18 | $actions = []; |
19 | 19 | $reflector = new \ReflectionClass($namespace); |
20 | - if(null !== $reflector) { |
|
21 | - foreach($reflector->getMethods(\ReflectionMethod::IS_PUBLIC) as $apiAction) { |
|
20 | + if (null !== $reflector) { |
|
21 | + foreach ($reflector->getMethods(\ReflectionMethod::IS_PUBLIC) as $apiAction) { |
|
22 | 22 | $docComments = $apiAction->getDocComment(); |
23 | 23 | $action = self::extractAction($docComments); |
24 | - if(null !== $action) { |
|
24 | + if (null !== $action) { |
|
25 | 25 | list($route, $info) = RouterHelper::extractRouteInfo($apiAction, $api, $domain); |
26 | 26 | list($method, $cleanRoute) = RouterHelper::extractHttpRoute($route); |
27 | 27 | $formAction = new FormAction(); |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | { |
45 | 45 | $action = null; |
46 | 46 | if (false !== preg_match('/@action\s+([^\s]+)/', $doc, $matches)) { |
47 | - if(count($matches) > 1) { |
|
47 | + if (count($matches) > 1) { |
|
48 | 48 | list(, $action) = $matches; |
49 | 49 | } |
50 | 50 | } |