@@ -9,7 +9,6 @@ |
||
9 | 9 | use PSFS\base\types\helpers\AdminHelper; |
10 | 10 | use PSFS\base\types\helpers\GeneratorHelper; |
11 | 11 | use PSFS\base\types\helpers\I18nHelper; |
12 | -use PSFS\base\types\helpers\RequestHelper; |
|
13 | 12 | use PSFS\base\types\helpers\RouterHelper; |
14 | 13 | use PSFS\base\types\helpers\SecurityHelper; |
15 | 14 | use PSFS\base\types\traits\SingletonTrait; |
@@ -67,11 +67,11 @@ discard block |
||
67 | 67 | */ |
68 | 68 | public function init() |
69 | 69 | { |
70 | - list($this->routing, $this->slugs) = $this->cache->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . "urls.json", $this->cacheType, TRUE); |
|
70 | + list($this->routing, $this->slugs) = $this->cache->getDataFromFile(CONFIG_DIR.DIRECTORY_SEPARATOR."urls.json", $this->cacheType, TRUE); |
|
71 | 71 | if (empty($this->routing) || Config::getInstance()->getDebugMode()) { |
72 | 72 | $this->debugLoad(); |
73 | - } else { |
|
74 | - $this->domains = $this->cache->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . "domains.json", $this->cacheType, TRUE); |
|
73 | + }else { |
|
74 | + $this->domains = $this->cache->getDataFromFile(CONFIG_DIR.DIRECTORY_SEPARATOR."domains.json", $this->cacheType, TRUE); |
|
75 | 75 | } |
76 | 76 | $this->checkExternalModules(false); |
77 | 77 | $this->setLoaded(true); |
@@ -106,11 +106,11 @@ discard block |
||
106 | 106 | if (preg_match('/json/i', Request::getInstance()->getServer('CONTENT_TYPE')) || $isJson) { |
107 | 107 | $response = new JsonResponse(null, false, 0, 0, $e->getMessage()); |
108 | 108 | return $template->output(json_encode($response), 'application/json'); |
109 | - } else { |
|
109 | + }else { |
|
110 | 110 | $not_found_rouote = Config::getParam('route.404'); |
111 | - if(null !== $not_found_rouote) { |
|
111 | + if (null !== $not_found_rouote) { |
|
112 | 112 | Request::getInstance()->redirect($this->getRoute($not_found_rouote, true)); |
113 | - } else { |
|
113 | + }else { |
|
114 | 114 | return $template->render('error.html.twig', array( |
115 | 115 | 'exception' => $e, |
116 | 116 | 'trace' => $e->getTraceAsString(), |
@@ -165,12 +165,12 @@ discard block |
||
165 | 165 | try { |
166 | 166 | //Search action and execute |
167 | 167 | $this->searchAction($route); |
168 | - } catch (AccessDeniedException $e) { |
|
168 | + }catch (AccessDeniedException $e) { |
|
169 | 169 | Logger::log(_('Solicitamos credenciales de acceso a zona restringida')); |
170 | 170 | return Admin::staticAdminLogon($route); |
171 | - } catch (RouterException $r) { |
|
171 | + }catch (RouterException $r) { |
|
172 | 172 | Logger::log($r->getMessage(), LOG_WARNING); |
173 | - } catch (\Exception $e) { |
|
173 | + }catch (\Exception $e) { |
|
174 | 174 | Logger::log($e->getMessage(), LOG_ERR); |
175 | 175 | throw $e; |
176 | 176 | } |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | */ |
188 | 188 | protected function searchAction($route) |
189 | 189 | { |
190 | - Logger::log('Searching action to execute: ' . $route, LOG_INFO); |
|
190 | + Logger::log('Searching action to execute: '.$route, LOG_INFO); |
|
191 | 191 | //Revisamos si tenemos la ruta registrada |
192 | 192 | $parts = parse_url($route); |
193 | 193 | $path = (array_key_exists('path', $parts)) ? $parts['path'] : $route; |
@@ -202,12 +202,12 @@ discard block |
||
202 | 202 | /** @var $class \PSFS\base\types\Controller */ |
203 | 203 | $class = RouterHelper::getClassToCall($action); |
204 | 204 | try { |
205 | - if($this->checkRequirements($action, $get)) { |
|
205 | + if ($this->checkRequirements($action, $get)) { |
|
206 | 206 | $this->executeCachedRoute($route, $action, $class, $get); |
207 | - } else { |
|
207 | + }else { |
|
208 | 208 | throw new RouterException(_('La ruta no es válida'), 400); |
209 | 209 | } |
210 | - } catch (\Exception $e) { |
|
210 | + }catch (\Exception $e) { |
|
211 | 211 | Logger::log($e->getMessage(), LOG_ERR); |
212 | 212 | throw new \RuntimeException($e->getMessage(), 404, $e); |
213 | 213 | } |
@@ -223,16 +223,16 @@ discard block |
||
223 | 223 | */ |
224 | 224 | private function checkRequirements(array $action, array $params = []) { |
225 | 225 | $valid = true; |
226 | - if(!empty($action['requirements'])) { |
|
227 | - if(!empty($params)) { |
|
226 | + if (!empty($action['requirements'])) { |
|
227 | + if (!empty($params)) { |
|
228 | 228 | $checked = 0; |
229 | - foreach(array_keys($params) as $key) { |
|
230 | - if(in_array($key, $action['requirements'])) { |
|
229 | + foreach (array_keys($params) as $key) { |
|
230 | + if (in_array($key, $action['requirements'])) { |
|
231 | 231 | $checked++; |
232 | 232 | } |
233 | 233 | } |
234 | 234 | $valid = count($action['requirements']) == $checked; |
235 | - } else { |
|
235 | + }else { |
|
236 | 236 | $valid = false; |
237 | 237 | } |
238 | 238 | } |
@@ -253,7 +253,7 @@ discard block |
||
253 | 253 | */ |
254 | 254 | private function getExternalModules() { |
255 | 255 | $externalModules = Config::getParam('modules.extend', ''); |
256 | - if(Config::getParam('psfs.auth', false)) { |
|
256 | + if (Config::getParam('psfs.auth', false)) { |
|
257 | 257 | $externalModules .= ',psfs/auth'; |
258 | 258 | } |
259 | 259 | return $externalModules; |
@@ -270,17 +270,17 @@ discard block |
||
270 | 270 | $externalModules = explode(',', $externalModules); |
271 | 271 | foreach ($externalModules as &$module) { |
272 | 272 | $module = preg_replace('/(\\\|\/)/', DIRECTORY_SEPARATOR, $module); |
273 | - $externalModulePath = VENDOR_DIR . DIRECTORY_SEPARATOR . $module . DIRECTORY_SEPARATOR . 'src'; |
|
273 | + $externalModulePath = VENDOR_DIR.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.'src'; |
|
274 | 274 | if (file_exists($externalModulePath)) { |
275 | 275 | $externalModule = $this->finder->directories()->in($externalModulePath)->depth(0); |
276 | 276 | if (!empty($externalModule)) { |
277 | 277 | foreach ($externalModule as $modulePath) { |
278 | 278 | $extModule = $modulePath->getBasename(); |
279 | - $moduleAutoloader = realpath($externalModulePath . DIRECTORY_SEPARATOR . $extModule . DIRECTORY_SEPARATOR . 'autoload.php'); |
|
279 | + $moduleAutoloader = realpath($externalModulePath.DIRECTORY_SEPARATOR.$extModule.DIRECTORY_SEPARATOR.'autoload.php'); |
|
280 | 280 | if (file_exists($moduleAutoloader)) { |
281 | 281 | @include $moduleAutoloader; |
282 | 282 | if ($hydrateRoute) { |
283 | - $this->routing = $this->inspectDir($externalModulePath . DIRECTORY_SEPARATOR . $extModule, '\\' . $extModule, $this->routing); |
|
283 | + $this->routing = $this->inspectDir($externalModulePath.DIRECTORY_SEPARATOR.$extModule, '\\'.$extModule, $this->routing); |
|
284 | 284 | } |
285 | 285 | } |
286 | 286 | } |
@@ -303,10 +303,10 @@ discard block |
||
303 | 303 | $modules = $this->finder->directories()->in($modulesPath)->depth(0); |
304 | 304 | foreach ($modules as $modulePath) { |
305 | 305 | $module = $modulePath->getBasename(); |
306 | - $this->routing = $this->inspectDir($modulesPath . DIRECTORY_SEPARATOR . $module, $module, $this->routing); |
|
306 | + $this->routing = $this->inspectDir($modulesPath.DIRECTORY_SEPARATOR.$module, $module, $this->routing); |
|
307 | 307 | } |
308 | 308 | } |
309 | - $this->cache->storeData(CONFIG_DIR . DIRECTORY_SEPARATOR . "domains.json", $this->domains, Cache::JSON, TRUE); |
|
309 | + $this->cache->storeData(CONFIG_DIR.DIRECTORY_SEPARATOR."domains.json", $this->domains, Cache::JSON, TRUE); |
|
310 | 310 | } |
311 | 311 | |
312 | 312 | /** |
@@ -321,7 +321,7 @@ discard block |
||
321 | 321 | $home_params = NULL; |
322 | 322 | foreach ($this->routing as $pattern => $params) { |
323 | 323 | list($method, $route) = RouterHelper::extractHttpRoute($pattern); |
324 | - if (preg_match("/" . preg_quote($route, "/") . "$/i", "/" . $home)) { |
|
324 | + if (preg_match("/".preg_quote($route, "/")."$/i", "/".$home)) { |
|
325 | 325 | $home_params = $params; |
326 | 326 | } |
327 | 327 | } |
@@ -346,7 +346,7 @@ discard block |
||
346 | 346 | $files = $this->finder->files()->in($origen)->path('/(controller|api)/i')->depth(1)->name("*.php"); |
347 | 347 | foreach ($files as $file) { |
348 | 348 | $filename = str_replace("/", '\\', str_replace($origen, '', $file->getPathname())); |
349 | - $routing = $this->addRouting($namespace . str_replace('.php', '', $filename), $routing, $namespace); |
|
349 | + $routing = $this->addRouting($namespace.str_replace('.php', '', $filename), $routing, $namespace); |
|
350 | 350 | } |
351 | 351 | $this->finder = new Finder(); |
352 | 352 | |
@@ -416,7 +416,7 @@ discard block |
||
416 | 416 | if (!$this->domains) { |
417 | 417 | $this->domains = []; |
418 | 418 | } |
419 | - $domain = "@" . $class->getConstant("DOMAIN") . "/"; |
|
419 | + $domain = "@".$class->getConstant("DOMAIN")."/"; |
|
420 | 420 | if (!array_key_exists($domain, $this->domains)) { |
421 | 421 | $this->domains[$domain] = RouterHelper::extractDomainInfo($class, $domain); |
422 | 422 | } |
@@ -431,11 +431,11 @@ discard block |
||
431 | 431 | */ |
432 | 432 | public function simpatize() |
433 | 433 | { |
434 | - $translationFileName = "translations" . DIRECTORY_SEPARATOR . "routes_translations.php"; |
|
435 | - $absoluteTranslationFileName = CACHE_DIR . DIRECTORY_SEPARATOR . $translationFileName; |
|
434 | + $translationFileName = "translations".DIRECTORY_SEPARATOR."routes_translations.php"; |
|
435 | + $absoluteTranslationFileName = CACHE_DIR.DIRECTORY_SEPARATOR.$translationFileName; |
|
436 | 436 | $this->generateSlugs($absoluteTranslationFileName); |
437 | 437 | GeneratorHelper::createDir(CONFIG_DIR); |
438 | - Cache::getInstance()->storeData(CONFIG_DIR . DIRECTORY_SEPARATOR . "urls.json", array($this->routing, $this->slugs), Cache::JSON, TRUE); |
|
438 | + Cache::getInstance()->storeData(CONFIG_DIR.DIRECTORY_SEPARATOR."urls.json", array($this->routing, $this->slugs), Cache::JSON, TRUE); |
|
439 | 439 | |
440 | 440 | return $this; |
441 | 441 | } |
@@ -453,16 +453,16 @@ discard block |
||
453 | 453 | public function getRoute($slug = '', $absolute = FALSE, $params = []) |
454 | 454 | { |
455 | 455 | if (strlen($slug) === 0) { |
456 | - return ($absolute) ? Request::getInstance()->getRootUrl() . '/' : '/'; |
|
456 | + return ($absolute) ? Request::getInstance()->getRootUrl().'/' : '/'; |
|
457 | 457 | } |
458 | 458 | if (!is_array($this->slugs) || !array_key_exists($slug, $this->slugs)) { |
459 | 459 | throw new RouterException(_("No existe la ruta especificada")); |
460 | 460 | } |
461 | - $url = ($absolute) ? Request::getInstance()->getRootUrl() . $this->slugs[$slug] : $this->slugs[$slug]; |
|
461 | + $url = ($absolute) ? Request::getInstance()->getRootUrl().$this->slugs[$slug] : $this->slugs[$slug]; |
|
462 | 462 | if (!empty($params)) foreach ($params as $key => $value) { |
463 | - $url = str_replace("{" . $key . "}", $value, $url); |
|
463 | + $url = str_replace("{".$key."}", $value, $url); |
|
464 | 464 | } elseif (!empty($this->routing[$this->slugs[$slug]]["default"])) { |
465 | - $url = ($absolute) ? Request::getInstance()->getRootUrl() . $this->routing[$this->slugs[$slug]]["default"] : $this->routing[$this->slugs[$slug]]["default"]; |
|
465 | + $url = ($absolute) ? Request::getInstance()->getRootUrl().$this->routing[$this->slugs[$slug]]["default"] : $this->routing[$this->slugs[$slug]]["default"]; |
|
466 | 466 | } |
467 | 467 | |
468 | 468 | return preg_replace('/(GET|POST|PUT|DELETE|ALL)\#\|\#/', '', $url); |
@@ -507,17 +507,17 @@ discard block |
||
507 | 507 | */ |
508 | 508 | protected function executeCachedRoute($route, $action, $class, $params = NULL) |
509 | 509 | { |
510 | - Logger::log('Executing route ' . $route, LOG_INFO); |
|
510 | + Logger::log('Executing route '.$route, LOG_INFO); |
|
511 | 511 | $action['params'] = array_merge($action['params'], $params, Request::getInstance()->getQueryParams()); |
512 | 512 | Security::getInstance()->setSessionKey("__CACHE__", $action); |
513 | 513 | $cache = Cache::needCache(); |
514 | 514 | $execute = TRUE; |
515 | 515 | if (FALSE !== $cache && Config::getInstance()->getDebugMode() === FALSE && $action['http'] === 'GET') { |
516 | 516 | list($path, $cacheDataName) = $this->cache->getRequestCacheHash(); |
517 | - $cachedData = $this->cache->readFromCache("json" . DIRECTORY_SEPARATOR . $path . $cacheDataName, |
|
517 | + $cachedData = $this->cache->readFromCache("json".DIRECTORY_SEPARATOR.$path.$cacheDataName, |
|
518 | 518 | $cache, null); |
519 | 519 | if (NULL !== $cachedData) { |
520 | - $headers = $this->cache->readFromCache("json" . DIRECTORY_SEPARATOR . $path . $cacheDataName . ".headers", |
|
520 | + $headers = $this->cache->readFromCache("json".DIRECTORY_SEPARATOR.$path.$cacheDataName.".headers", |
|
521 | 521 | $cache, null, Cache::JSON); |
522 | 522 | Template::getInstance()->renderCache($cachedData, $headers); |
523 | 523 | $execute = FALSE; |
@@ -3,15 +3,12 @@ |
||
3 | 3 | |
4 | 4 | use Propel\Runtime\ActiveQuery\ModelCriteria; |
5 | 5 | use Propel\Runtime\Map\TableMap; |
6 | -use PSFS\base\config\Config; |
|
7 | 6 | use PSFS\base\dto\JsonResponse; |
8 | 7 | use PSFS\base\dto\Order; |
9 | 8 | use PSFS\base\Logger; |
10 | 9 | use PSFS\base\Request; |
11 | -use PSFS\base\Security; |
|
12 | 10 | use PSFS\base\Singleton; |
13 | 11 | use PSFS\base\types\helpers\ApiHelper; |
14 | -use PSFS\base\types\helpers\Inspector; |
|
15 | 12 | use PSFS\base\types\traits\Api\ManagerTrait; |
16 | 13 | |
17 | 14 | /** |
@@ -71,13 +71,13 @@ discard block |
||
71 | 71 | public function init() |
72 | 72 | { |
73 | 73 | parent::init(); |
74 | - Logger::log(get_called_class() . ' init', LOG_DEBUG); |
|
74 | + Logger::log(get_called_class().' init', LOG_DEBUG); |
|
75 | 75 | $this->domain = $this->getDomain(); |
76 | 76 | $this->hydrateRequestData(); |
77 | 77 | $this->hydrateOrders(); |
78 | 78 | $this->createConnection($this->getTableMap()); |
79 | 79 | $this->setLoaded(true); |
80 | - Logger::log(get_called_class() . ' loaded', LOG_DEBUG); |
|
80 | + Logger::log(get_called_class().' loaded', LOG_DEBUG); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | /** |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | private function hydrateOrders() |
87 | 87 | { |
88 | 88 | if (count($this->query)) { |
89 | - Logger::log(get_called_class() . ' gathering query string', LOG_DEBUG); |
|
89 | + Logger::log(get_called_class().' gathering query string', LOG_DEBUG); |
|
90 | 90 | foreach ($this->query as $key => $value) { |
91 | 91 | if ($key === self::API_ORDER_FIELD) { |
92 | 92 | foreach ($value as $field => $direction) { |
@@ -103,10 +103,10 @@ discard block |
||
103 | 103 | */ |
104 | 104 | protected function extractPagination() |
105 | 105 | { |
106 | - Logger::log(get_called_class() . ' extract pagination start', LOG_DEBUG); |
|
106 | + Logger::log(get_called_class().' extract pagination start', LOG_DEBUG); |
|
107 | 107 | $page = (array_key_exists(self::API_PAGE_FIELD, $this->query)) ? $this->query[self::API_PAGE_FIELD] : 1; |
108 | 108 | $limit = (array_key_exists(self::API_LIMIT_FIELD, $this->query)) ? $this->query[self::API_LIMIT_FIELD] : 100; |
109 | - Logger::log(get_called_class() . ' extract pagination end', LOG_DEBUG); |
|
109 | + Logger::log(get_called_class().' extract pagination end', LOG_DEBUG); |
|
110 | 110 | return array($page, $limit); |
111 | 111 | } |
112 | 112 | |
@@ -115,9 +115,9 @@ discard block |
||
115 | 115 | * |
116 | 116 | * @param ModelCriteria $query |
117 | 117 | */ |
118 | - private function addOrders(ModelCriteria &$query) |
|
118 | + private function addOrders(ModelCriteria & $query) |
|
119 | 119 | { |
120 | - Logger::log(get_called_class() . ' extract orders start ', LOG_DEBUG); |
|
120 | + Logger::log(get_called_class().' extract orders start ', LOG_DEBUG); |
|
121 | 121 | $orderAdded = FALSE; |
122 | 122 | $tableMap = $this->getTableMap(); |
123 | 123 | foreach ($this->order->getOrders() as $field => $direction) { |
@@ -125,17 +125,17 @@ discard block |
||
125 | 125 | $orderAdded = TRUE; |
126 | 126 | if ($direction === Order::ASC) { |
127 | 127 | $query->addAscendingOrderByColumn($column->getPhpName()); |
128 | - } else { |
|
128 | + }else { |
|
129 | 129 | $query->addDescendingOrderByColumn($column->getPhpName()); |
130 | 130 | } |
131 | 131 | } |
132 | 132 | } |
133 | 133 | if (!$orderAdded) { |
134 | - foreach($this->getPkDbName() as $pk => $phpName) { |
|
134 | + foreach ($this->getPkDbName() as $pk => $phpName) { |
|
135 | 135 | $query->addAscendingOrderByColumn($pk); |
136 | 136 | } |
137 | 137 | } |
138 | - Logger::log(get_called_class() . ' extract orders end', LOG_DEBUG); |
|
138 | + Logger::log(get_called_class().' extract orders end', LOG_DEBUG); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | /** |
@@ -143,14 +143,14 @@ discard block |
||
143 | 143 | * |
144 | 144 | * @param ModelCriteria $query |
145 | 145 | */ |
146 | - private function addFilters(ModelCriteria &$query) |
|
146 | + private function addFilters(ModelCriteria & $query) |
|
147 | 147 | { |
148 | 148 | if (count($this->query) > 0) { |
149 | 149 | $tableMap = $this->getTableMap(); |
150 | 150 | foreach ($this->query as $field => $value) { |
151 | 151 | if (self::API_COMBO_FIELD === $field) { |
152 | 152 | ApiHelper::composerComboField($tableMap, $query, $this->extraColumns, $value); |
153 | - } elseif(!preg_match('/^__/', $field)) { |
|
153 | + } elseif (!preg_match('/^__/', $field)) { |
|
154 | 154 | ApiHelper::addModelField($tableMap, $query, $field, $value); |
155 | 155 | } |
156 | 156 | } |
@@ -171,10 +171,10 @@ discard block |
||
171 | 171 | list($page, $limit) = $this->extractPagination(); |
172 | 172 | if ($limit == -1) { |
173 | 173 | $this->list = $query->find($this->con); |
174 | - } else { |
|
174 | + }else { |
|
175 | 175 | $this->list = $query->paginate($page, $limit, $this->con); |
176 | 176 | } |
177 | - } catch (\Exception $e) { |
|
177 | + }catch (\Exception $e) { |
|
178 | 178 | Logger::log($e->getMessage(), LOG_ERR); |
179 | 179 | } |
180 | 180 | } |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | $code = 200; |
194 | 194 | list($return, $total, $pages) = $this->getList(); |
195 | 195 | $message = null; |
196 | - if(!$total) { |
|
196 | + if (!$total) { |
|
197 | 197 | $message = _('No se han encontrado elementos para la búsqueda'); |
198 | 198 | } |
199 | 199 | |
@@ -219,7 +219,7 @@ discard block |
||
219 | 219 | $pages = 1; |
220 | 220 | $message = null; |
221 | 221 | list($code, $return) = $this->getSingleResult($pk); |
222 | - if($code !== 200) { |
|
222 | + if ($code !== 200) { |
|
223 | 223 | $message = _('No se ha encontrado el elemento solicitado'); |
224 | 224 | } |
225 | 225 | |
@@ -248,11 +248,11 @@ discard block |
||
248 | 248 | $status = 200; |
249 | 249 | $saved = TRUE; |
250 | 250 | $model = $this->model->toArray(); |
251 | - } else { |
|
251 | + }else { |
|
252 | 252 | $message = _('No se ha podido modificar el modelo seleccionado'); |
253 | 253 | } |
254 | - } catch (\Exception $e) { |
|
255 | - $message = _('Ha ocurrido un error intentando guardar el elemento: ') .'<br>'. $e->getMessage(); |
|
254 | + }catch (\Exception $e) { |
|
255 | + $message = _('Ha ocurrido un error intentando guardar el elemento: ').'<br>'.$e->getMessage(); |
|
256 | 256 | Logger::log($e->getMessage(), LOG_ERR); |
257 | 257 | } |
258 | 258 | |
@@ -286,14 +286,14 @@ discard block |
||
286 | 286 | $updated = TRUE; |
287 | 287 | $status = 200; |
288 | 288 | $model = $this->model->toArray(); |
289 | - } else { |
|
289 | + }else { |
|
290 | 290 | $message = _('Ha ocurrido un error intentando actualizar el elemento, por favor revisa los logs'); |
291 | 291 | } |
292 | - } catch (\Exception $e) { |
|
292 | + }catch (\Exception $e) { |
|
293 | 293 | $message = $e->getMessage(); |
294 | 294 | Logger::getInstance(get_class($this->model))->errorLog($e->getMessage()); |
295 | 295 | } |
296 | - } else { |
|
296 | + }else { |
|
297 | 297 | $message = _('No se ha encontrado el modelo al que se hace referencia para actualizar'); |
298 | 298 | } |
299 | 299 | |
@@ -323,7 +323,7 @@ discard block |
||
323 | 323 | $this->model->delete($this->con); |
324 | 324 | $deleted = TRUE; |
325 | 325 | } |
326 | - } catch (\Exception $e) { |
|
326 | + }catch (\Exception $e) { |
|
327 | 327 | $message = _('Ha ocurrido un error intentando eliminar el elemento, por favor verifica que no tenga otros elementos relacionados'); |
328 | 328 | Logger::getInstance(get_class($this->model))->errorLog($e->getMessage()); |
329 | 329 | } |
@@ -357,8 +357,8 @@ discard block |
||
357 | 357 | $total = $this->list->getNbResults(); |
358 | 358 | $pages = $this->list->getLastPage(); |
359 | 359 | } |
360 | - } catch (\Exception $e) { |
|
361 | - Logger::log(get_class($this) . ': ' . $e->getMessage(), LOG_ERR); |
|
360 | + }catch (\Exception $e) { |
|
361 | + Logger::log(get_class($this).': '.$e->getMessage(), LOG_ERR); |
|
362 | 362 | } |
363 | 363 | |
364 | 364 | return array($return, $total, $pages); |
@@ -376,7 +376,7 @@ discard block |
||
376 | 376 | $return = array(); |
377 | 377 | if (NULL === $model || !method_exists($model, 'toArray')) { |
378 | 378 | $code = 404; |
379 | - } else { |
|
379 | + }else { |
|
380 | 380 | $return = $model->toArray(); |
381 | 381 | } |
382 | 382 |
@@ -2,15 +2,11 @@ |
||
2 | 2 | namespace PSFS\base\types; |
3 | 3 | |
4 | 4 | use PSFS\base\config\Config; |
5 | -use PSFS\base\exception\RouterException; |
|
6 | -use PSFS\base\Request; |
|
7 | -use PSFS\base\Router; |
|
8 | 5 | use PSFS\base\Singleton; |
9 | 6 | use PSFS\base\types\helpers\GeneratorHelper; |
10 | 7 | use PSFS\base\types\helpers\Inspector; |
11 | 8 | use PSFS\base\types\interfaces\ControllerInterface; |
12 | 9 | use PSFS\base\types\traits\JsonTrait; |
13 | -use PSFS\base\types\traits\OutputTrait; |
|
14 | 10 | use PSFS\base\types\traits\RouteTrait; |
15 | 11 | |
16 | 12 | /** |
@@ -41,11 +41,11 @@ discard block |
||
41 | 41 | public function render($template, array $vars = array(), $cookies = array(), $domain = null) |
42 | 42 | { |
43 | 43 | $vars['__menu__'] = $this->getMenu(); |
44 | - if(Config::getParam('profiling.enable')) { |
|
44 | + if (Config::getParam('profiling.enable')) { |
|
45 | 45 | $vars['__profiling__'] = Inspector::getStats(); |
46 | 46 | } |
47 | 47 | $domain = (null === $domain) ? $this->getDomain() : $domain; |
48 | - return $this->tpl->render($domain . $template, $vars, $cookies); |
|
48 | + return $this->tpl->render($domain.$template, $vars, $cookies); |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | /** |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | { |
77 | 77 | $vars['__menu__'] = $this->getMenu(); |
78 | 78 | $domain = $domain ?: $this->getDomain(); |
79 | - return $this->tpl->dump($domain . $template, $vars); |
|
79 | + return $this->tpl->dump($domain.$template, $vars); |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | /** |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | */ |
8 | 8 | class FileHelper { |
9 | 9 | /** |
10 | - * @param mixed $data |
|
10 | + * @param string $data |
|
11 | 11 | * @param string $path |
12 | 12 | * @return int |
13 | 13 | */ |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | |
18 | 18 | /** |
19 | 19 | * @param string $path |
20 | - * @return mixed|bool |
|
20 | + * @return string|false |
|
21 | 21 | */ |
22 | 22 | public static function readFile($path) { |
23 | 23 | $data = false; |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
53 | - * @param $path |
|
53 | + * @param string $path |
|
54 | 54 | * @return bool |
55 | 55 | */ |
56 | 56 | public static function deleteDir($path) { |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | */ |
22 | 22 | public static function readFile($path) { |
23 | 23 | $data = false; |
24 | - if(file_exists($path)) { |
|
24 | + if (file_exists($path)) { |
|
25 | 25 | $data = file_get_contents($path); |
26 | 26 | } |
27 | 27 | return $data; |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | * @return string |
35 | 35 | */ |
36 | 36 | public static function generateHashFilename($verb, $slug, array $query = []) { |
37 | - return sha1(strtolower($verb) . " " . $slug . " " . strtolower(http_build_query($query))); |
|
37 | + return sha1(strtolower($verb)." ".$slug." ".strtolower(http_build_query($query))); |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | /** |
@@ -45,8 +45,8 @@ discard block |
||
45 | 45 | public static function generateCachePath(array $action, array $query = []) { |
46 | 46 | $class = GeneratorHelper::extractClassFromNamespace($action['class']); |
47 | 47 | $filename = self::generateHashFilename($action["http"], $action["slug"], $query); |
48 | - $subPath = substr($filename, 0, 2) . DIRECTORY_SEPARATOR . substr($filename, 2, 2); |
|
49 | - return $action['module'] . DIRECTORY_SEPARATOR . $class . DIRECTORY_SEPARATOR . $action['method'] . DIRECTORY_SEPARATOR . $subPath . DIRECTORY_SEPARATOR; |
|
48 | + $subPath = substr($filename, 0, 2).DIRECTORY_SEPARATOR.substr($filename, 2, 2); |
|
49 | + return $action['module'].DIRECTORY_SEPARATOR.$class.DIRECTORY_SEPARATOR.$action['method'].DIRECTORY_SEPARATOR.$subPath.DIRECTORY_SEPARATOR; |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
@@ -56,7 +56,6 @@ discard block |
||
56 | 56 | public static function deleteDir($path) { |
57 | 57 | $class_func = array(__CLASS__, __FUNCTION__); |
58 | 58 | return is_file($path) ? |
59 | - @unlink($path) : |
|
60 | - array_map($class_func, glob($path.'/*')) == @rmdir($path); |
|
59 | + @unlink($path) : array_map($class_func, glob($path.'/*')) == @rmdir($path); |
|
61 | 60 | } |
62 | 61 | } |
63 | 62 | \ No newline at end of file |
@@ -14,6 +14,9 @@ |
||
14 | 14 | ]; |
15 | 15 | } |
16 | 16 | |
17 | + /** |
|
18 | + * @param string $name |
|
19 | + */ |
|
17 | 20 | public static function stats($name = null) { |
18 | 21 | self::$profiling[] = self::collect($name); |
19 | 22 | } |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | protected static function calculateStats(array $stats, $ts, $mem = 0, $files = 0) { |
29 | 29 | return [ |
30 | 30 | 'ts' => round($stats['ts'] - $ts, 4), |
31 | - 'mem' => round(($stats['mem'] - $mem) / 1024 / 1024, 4), |
|
31 | + 'mem' => round(($stats['mem'] - $mem)/1024/1024, 4), |
|
32 | 32 | 'files' => $stats['files'] - $files, |
33 | 33 | 'name' => $stats['name'], |
34 | 34 | ]; |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | $ts = $_SERVER['REQUEST_TIME_FLOAT'] ?: 0; |
43 | 43 | $mem = 0; |
44 | 44 | $files = 0; |
45 | - foreach(self::$profiling as $key => &$value) { |
|
45 | + foreach (self::$profiling as $key => &$value) { |
|
46 | 46 | $value = self::calculateStats($value, $ts, $mem, $files); |
47 | 47 | } |
48 | 48 | self::$profiling[] = self::calculateStats(self::collect('Profiling collect ends'), $ts, $mem, $files); |
@@ -18,7 +18,7 @@ |
||
18 | 18 | * @param mixed $response |
19 | 19 | * @param int $statusCode |
20 | 20 | * |
21 | - * @return mixed JSON |
|
21 | + * @return string|null JSON |
|
22 | 22 | */ |
23 | 23 | public function json($response, $statusCode = 200) |
24 | 24 | { |
@@ -22,19 +22,19 @@ |
||
22 | 22 | */ |
23 | 23 | public function json($response, $statusCode = 200) |
24 | 24 | { |
25 | - if(Config::getParam('json.encodeUTF8', false)) { |
|
25 | + if (Config::getParam('json.encodeUTF8', false)) { |
|
26 | 26 | $response = I18nHelper::utf8Encode($response); |
27 | 27 | } |
28 | - if(Config::getParam('profiling.enable')) { |
|
29 | - if(is_array($response)) { |
|
28 | + if (Config::getParam('profiling.enable')) { |
|
29 | + if (is_array($response)) { |
|
30 | 30 | $response['profiling'] = Inspector::getStats(); |
31 | - } elseif($response instanceof JsonResponse) { |
|
31 | + } elseif ($response instanceof JsonResponse) { |
|
32 | 32 | $response = ProfilingJsonResponse::createFromPrevious($response, Inspector::getStats()); |
33 | 33 | } |
34 | 34 | } |
35 | 35 | $data = json_encode($response, JSON_UNESCAPED_UNICODE | JSON_NUMERIC_CHECK); |
36 | - if(Config::getParam('angular.protection', false)) { |
|
37 | - $data = ")]}',\n" . $data; |
|
36 | + if (Config::getParam('angular.protection', false)) { |
|
37 | + $data = ")]}',\n".$data; |
|
38 | 38 | } |
39 | 39 | $this->setStatus($statusCode); |
40 | 40 | return $this->output($data, "application/json"); |
@@ -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 | /** |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | $config = Config::getInstance(); |
50 | 50 | $args = func_get_args(); |
51 | 51 | list($logger, $debug, $path) = $this->setup($config, $args); |
52 | - $this->stream = fopen($path . DIRECTORY_SEPARATOR . date("Ymd") . ".log", "a+"); |
|
52 | + $this->stream = fopen($path.DIRECTORY_SEPARATOR.date("Ymd").".log", "a+"); |
|
53 | 53 | $this->addPushLogger($logger, $debug, $config); |
54 | 54 | $this->log_level = Config::getParam('log.level', 'info'); |
55 | 55 | } |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | private function createLoggerPath(Config $config) |
204 | 204 | { |
205 | 205 | $logger = $this->setLoggerName($config); |
206 | - $path = LOG_DIR . DIRECTORY_SEPARATOR . $logger . DIRECTORY_SEPARATOR . date('Y') . DIRECTORY_SEPARATOR . date('m'); |
|
206 | + $path = LOG_DIR.DIRECTORY_SEPARATOR.$logger.DIRECTORY_SEPARATOR.date('Y').DIRECTORY_SEPARATOR.date('m'); |
|
207 | 207 | GeneratorHelper::createDir($path); |
208 | 208 | |
209 | 209 | return $path; |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | */ |
218 | 218 | public static function log($msg, $type = LOG_DEBUG, $context = []) |
219 | 219 | { |
220 | - if(Config::getParam('profiling.enable')) { |
|
220 | + if (Config::getParam('profiling.enable')) { |
|
221 | 221 | Inspector::stats($msg); |
222 | 222 | } |
223 | 223 | switch ($type) { |
@@ -265,7 +265,7 @@ discard block |
||
265 | 265 | */ |
266 | 266 | private function addMinimalContext($context = []) |
267 | 267 | { |
268 | - if(!is_array($context)) { |
|
268 | + if (!is_array($context)) { |
|
269 | 269 | $context = []; |
270 | 270 | } |
271 | 271 | $context['uri'] = null !== $_SERVER && array_key_exists('REQUEST_URI', $_SERVER) ? $_SERVER['REQUEST_URI'] : 'Unknow'; |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | $this->setStatusCode(Template::STATUS_OK); |
121 | 121 | break; |
122 | 122 | default: |
123 | - $this->setStatusCode('HTTP/1.0 ' . $status ?: 200); |
|
123 | + $this->setStatusCode('HTTP/1.0 '.$status ?: 200); |
|
124 | 124 | break; |
125 | 125 | } |
126 | 126 | return $this; |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | ResponseHelper::setStatusHeader($this->getStatusCode()); |
139 | 139 | ResponseHelper::setAuthHeaders($this->isPublicZone()); |
140 | 140 | ResponseHelper::setCookieHeaders($cookies); |
141 | - header('Content-type: ' . $contentType); |
|
141 | + header('Content-type: '.$contentType); |
|
142 | 142 | |
143 | 143 | } |
144 | 144 | |
@@ -154,15 +154,15 @@ discard block |
||
154 | 154 | Logger::log('Start output response'); |
155 | 155 | ob_start(); |
156 | 156 | $this->setReponseHeaders($contentType, $cookies); |
157 | - header('Content-length: ' . strlen($output)); |
|
157 | + header('Content-length: '.strlen($output)); |
|
158 | 158 | |
159 | 159 | $needCache = Cache::needCache(); |
160 | 160 | $cache = Cache::getInstance(); |
161 | 161 | list($path, $cacheDataName) = $cache->getRequestCacheHash(); |
162 | 162 | if (false !== $needCache && $this->getStatusCode() === Template::STATUS_OK && null !== $cacheDataName) { |
163 | 163 | Logger::log('Saving output response into cache'); |
164 | - $cache->storeData("json" . DIRECTORY_SEPARATOR . $path . $cacheDataName, $output); |
|
165 | - $cache->storeData("json" . DIRECTORY_SEPARATOR . $path . $cacheDataName . ".headers", headers_list(), Cache::JSON); |
|
164 | + $cache->storeData("json".DIRECTORY_SEPARATOR.$path.$cacheDataName, $output); |
|
165 | + $cache->storeData("json".DIRECTORY_SEPARATOR.$path.$cacheDataName.".headers", headers_list(), Cache::JSON); |
|
166 | 166 | } elseif (Request::getInstance()->getMethod() !== 'GET') { |
167 | 167 | $cache->flushCache(); |
168 | 168 | } |
@@ -182,11 +182,11 @@ discard block |
||
182 | 182 | Logger::log('Close template render'); |
183 | 183 | $uri = Request::requestUri(); |
184 | 184 | Security::getInstance()->setSessionKey("lastRequest", array( |
185 | - "url" => Request::getInstance()->getRootUrl() . $uri, |
|
185 | + "url" => Request::getInstance()->getRootUrl().$uri, |
|
186 | 186 | "ts" => microtime(true), |
187 | 187 | )); |
188 | 188 | Security::getInstance()->updateSession(); |
189 | - Logger::log('End request: ' . $uri, LOG_INFO); |
|
189 | + Logger::log('End request: '.$uri, LOG_INFO); |
|
190 | 190 | exit; |
191 | 191 | } |
192 | 192 | |
@@ -224,17 +224,17 @@ discard block |
||
224 | 224 | ///////////////////////////////////////////////////////////// |
225 | 225 | // Date in the past sets the value to already have been expired. |
226 | 226 | header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); |
227 | - header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); |
|
227 | + header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); |
|
228 | 228 | header('Cache-Control: no-store, no-cache, must-revalidate'); // HTTP/1.1 |
229 | 229 | header('Cache-Control: pre-check=0, post-check=0, max-age=0'); // HTTP/1.1 |
230 | 230 | header("Pragma: no-cache"); |
231 | 231 | header("Expires: 0"); |
232 | 232 | header('Content-Transfer-Encoding: binary'); |
233 | - header("Content-type: " . $content); |
|
234 | - header("Content-length: " . strlen($data)); |
|
235 | - header('Content-Disposition: attachment; filename="' . $filename . '"'); |
|
233 | + header("Content-type: ".$content); |
|
234 | + header("Content-length: ".strlen($data)); |
|
235 | + header('Content-Disposition: attachment; filename="'.$filename.'"'); |
|
236 | 236 | header("Access-Control-Expose-Headers: Filename"); |
237 | - header("Filename: " . $filename); |
|
237 | + header("Filename: ".$filename); |
|
238 | 238 | echo $data; |
239 | 239 | ob_flush(); |
240 | 240 | ob_end_clean(); |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | public static function getClassToCall($action) |
23 | 23 | { |
24 | 24 | Logger::log('Getting class to call for executing the request action', LOG_DEBUG, $action); |
25 | - $actionClass = class_exists($action["class"]) ? $action["class"] : "\\" . $action["class"]; |
|
25 | + $actionClass = class_exists($action["class"]) ? $action["class"] : "\\".$action["class"]; |
|
26 | 26 | $class = (method_exists($actionClass, "getInstance")) ? $actionClass::getInstance() : new $actionClass; |
27 | 27 | return $class; |
28 | 28 | } |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | $expr = preg_quote($expr, '/'); |
109 | 109 | $expr = str_replace('###', '(.*)', $expr); |
110 | 110 | $expr2 = preg_replace('/\(\.\*\)$/', '', $expr); |
111 | - $matched = preg_match('/^' . $expr . '\/?$/i', $path) || preg_match('/^' . $expr2 . '?$/i', $path); |
|
111 | + $matched = preg_match('/^'.$expr.'\/?$/i', $path) || preg_match('/^'.$expr2.'?$/i', $path); |
|
112 | 112 | return $matched; |
113 | 113 | } |
114 | 114 | |
@@ -119,8 +119,8 @@ discard block |
||
119 | 119 | */ |
120 | 120 | public static function extractDomainInfo(\ReflectionClass $class, $domain) |
121 | 121 | { |
122 | - $path = dirname($class->getFileName()) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR; |
|
123 | - $path = realpath($path) . DIRECTORY_SEPARATOR; |
|
122 | + $path = dirname($class->getFileName()).DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR; |
|
123 | + $path = realpath($path).DIRECTORY_SEPARATOR; |
|
124 | 124 | $tpl_path = "templates"; |
125 | 125 | $public_path = "public"; |
126 | 126 | $model_path = "models"; |
@@ -130,13 +130,13 @@ discard block |
||
130 | 130 | $model_path = ucfirst($model_path); |
131 | 131 | } |
132 | 132 | if ($class->hasConstant("TPL")) { |
133 | - $tpl_path .= DIRECTORY_SEPARATOR . $class->getConstant("TPL"); |
|
133 | + $tpl_path .= DIRECTORY_SEPARATOR.$class->getConstant("TPL"); |
|
134 | 134 | } |
135 | 135 | return [ |
136 | 136 | "base" => $path, |
137 | - "template" => $path . $tpl_path, |
|
138 | - "model" => $path . $model_path, |
|
139 | - "public" => $path . $public_path, |
|
137 | + "template" => $path.$tpl_path, |
|
138 | + "model" => $path.$model_path, |
|
139 | + "public" => $path.$public_path, |
|
140 | 140 | ]; |
141 | 141 | } |
142 | 142 | |
@@ -159,11 +159,11 @@ discard block |
||
159 | 159 | if (count($parameters) > 0) foreach ($parameters as $param) { |
160 | 160 | if ($param->isOptional() && !is_array($param->getDefaultValue())) { |
161 | 161 | $params[$param->getName()] = $param->getDefaultValue(); |
162 | - $default = str_replace('{' . $param->getName() . '}', $param->getDefaultValue(), $regex); |
|
163 | - } elseif(!$param->isOptional()) { |
|
162 | + $default = str_replace('{'.$param->getName().'}', $param->getDefaultValue(), $regex); |
|
163 | + } elseif (!$param->isOptional()) { |
|
164 | 164 | $requirements[] = $param->getName(); |
165 | 165 | } |
166 | - } else $default = $regex; |
|
166 | + }else $default = $regex; |
|
167 | 167 | |
168 | 168 | return [$regex, $default, $params, $requirements]; |
169 | 169 | } |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | $default = str_replace('{__DOMAIN__}', $module, $default); |
244 | 244 | $httpMethod = RouterHelper::extractReflectionHttpMethod($docComments); |
245 | 245 | $label = RouterHelper::extractReflectionLabel(str_replace('{__API__}', $api, $docComments)); |
246 | - $route = $httpMethod . "#|#" . $regex; |
|
246 | + $route = $httpMethod."#|#".$regex; |
|
247 | 247 | $route = preg_replace('/(\\r|\\f|\\t|\\n)/', '', $route); |
248 | 248 | $info = [ |
249 | 249 | "method" => $method->getName(), |
@@ -59,8 +59,10 @@ discard block |
||
59 | 59 | $_route = explode("/", $url['path']); |
60 | 60 | $_pattern = explode("/", $pattern); |
61 | 61 | $get = array(); |
62 | - if (!empty($_pattern)) foreach ($_pattern as $index => $component) { |
|
62 | + if (!empty($_pattern)) { |
|
63 | + foreach ($_pattern as $index => $component) { |
|
63 | 64 | $_get = array(); |
65 | + } |
|
64 | 66 | preg_match_all('/^\{(.*)\}$/i', $component, $_get); |
65 | 67 | if (!empty($_get[1]) && isset($_route[$index])) { |
66 | 68 | $get[array_pop($_get[1])] = $_route[$index]; |
@@ -156,14 +158,18 @@ discard block |
||
156 | 158 | $parameters = $method->getParameters(); |
157 | 159 | $requirements = []; |
158 | 160 | /** @var \ReflectionParameter $param */ |
159 | - if (count($parameters) > 0) foreach ($parameters as $param) { |
|
161 | + if (count($parameters) > 0) { |
|
162 | + foreach ($parameters as $param) { |
|
160 | 163 | if ($param->isOptional() && !is_array($param->getDefaultValue())) { |
161 | 164 | $params[$param->getName()] = $param->getDefaultValue(); |
165 | + } |
|
162 | 166 | $default = str_replace('{' . $param->getName() . '}', $param->getDefaultValue(), $regex); |
163 | 167 | } elseif(!$param->isOptional()) { |
164 | 168 | $requirements[] = $param->getName(); |
165 | 169 | } |
166 | - } else $default = $regex; |
|
170 | + } else { |
|
171 | + $default = $regex; |
|
172 | + } |
|
167 | 173 | |
168 | 174 | return [$regex, $default, $params, $requirements]; |
169 | 175 | } |