@@ -543,7 +543,7 @@ |
||
543 | 543 | /** |
544 | 544 | * @param $hydrateRoute |
545 | 545 | * @param $modulePath |
546 | - * @param $externalModulePath |
|
546 | + * @param string $externalModulePath |
|
547 | 547 | */ |
548 | 548 | private function loadExternalAutoloader(bool $hydrateRoute, SplFileInfo $modulePath, $externalModulePath) |
549 | 549 | { |
@@ -68,11 +68,11 @@ discard block |
||
68 | 68 | */ |
69 | 69 | public function init() |
70 | 70 | { |
71 | - list($this->routing, $this->slugs) = $this->cache->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . "urls.json", $this->cacheType, TRUE); |
|
71 | + list($this->routing, $this->slugs) = $this->cache->getDataFromFile(CONFIG_DIR.DIRECTORY_SEPARATOR."urls.json", $this->cacheType, TRUE); |
|
72 | 72 | if (empty($this->routing) || Config::getInstance()->getDebugMode()) { |
73 | 73 | $this->debugLoad(); |
74 | - } else { |
|
75 | - $this->domains = $this->cache->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . "domains.json", $this->cacheType, TRUE); |
|
74 | + }else { |
|
75 | + $this->domains = $this->cache->getDataFromFile(CONFIG_DIR.DIRECTORY_SEPARATOR."domains.json", $this->cacheType, TRUE); |
|
76 | 76 | } |
77 | 77 | $this->checkExternalModules(false); |
78 | 78 | $this->setLoaded(true); |
@@ -107,11 +107,11 @@ discard block |
||
107 | 107 | if (preg_match('/json/i', Request::getInstance()->getServer('CONTENT_TYPE')) || $isJson) { |
108 | 108 | $response = new JsonResponse(null, false, 0, 0, $e->getMessage()); |
109 | 109 | return $template->output(json_encode($response), 'application/json'); |
110 | - } else { |
|
110 | + }else { |
|
111 | 111 | $not_found_rouote = Config::getParam('route.404'); |
112 | - if(null !== $not_found_rouote) { |
|
112 | + if (null !== $not_found_rouote) { |
|
113 | 113 | Request::getInstance()->redirect($this->getRoute($not_found_rouote, true)); |
114 | - } else { |
|
114 | + }else { |
|
115 | 115 | return $template->render('error.html.twig', array( |
116 | 116 | 'exception' => $e, |
117 | 117 | 'trace' => $e->getTraceAsString(), |
@@ -166,12 +166,12 @@ discard block |
||
166 | 166 | try { |
167 | 167 | //Search action and execute |
168 | 168 | $this->searchAction($route); |
169 | - } catch (AccessDeniedException $e) { |
|
169 | + }catch (AccessDeniedException $e) { |
|
170 | 170 | Logger::log(_('Solicitamos credenciales de acceso a zona restringida')); |
171 | 171 | return Admin::staticAdminLogon($route); |
172 | - } catch (RouterException $r) { |
|
172 | + }catch (RouterException $r) { |
|
173 | 173 | Logger::log($r->getMessage(), LOG_WARNING); |
174 | - } catch (\Exception $e) { |
|
174 | + }catch (\Exception $e) { |
|
175 | 175 | Logger::log($e->getMessage(), LOG_ERR); |
176 | 176 | throw $e; |
177 | 177 | } |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | */ |
189 | 189 | protected function searchAction($route) |
190 | 190 | { |
191 | - Logger::log('Searching action to execute: ' . $route, LOG_INFO); |
|
191 | + Logger::log('Searching action to execute: '.$route, LOG_INFO); |
|
192 | 192 | //Revisamos si tenemos la ruta registrada |
193 | 193 | $parts = parse_url($route); |
194 | 194 | $path = (array_key_exists('path', $parts)) ? $parts['path'] : $route; |
@@ -203,12 +203,12 @@ discard block |
||
203 | 203 | /** @var $class \PSFS\base\types\Controller */ |
204 | 204 | $class = RouterHelper::getClassToCall($action); |
205 | 205 | try { |
206 | - if($this->checkRequirements($action, $get)) { |
|
206 | + if ($this->checkRequirements($action, $get)) { |
|
207 | 207 | $this->executeCachedRoute($route, $action, $class, $get); |
208 | - } else { |
|
208 | + }else { |
|
209 | 209 | throw new RouterException(_('La ruta no es válida'), 400); |
210 | 210 | } |
211 | - } catch (\Exception $e) { |
|
211 | + }catch (\Exception $e) { |
|
212 | 212 | Logger::log($e->getMessage(), LOG_ERR); |
213 | 213 | throw new \RuntimeException($e->getMessage(), 404, $e); |
214 | 214 | } |
@@ -224,16 +224,16 @@ discard block |
||
224 | 224 | */ |
225 | 225 | private function checkRequirements(array $action, array $params = []) { |
226 | 226 | $valid = true; |
227 | - if(!empty($action['requirements'])) { |
|
228 | - if(!empty($params)) { |
|
227 | + if (!empty($action['requirements'])) { |
|
228 | + if (!empty($params)) { |
|
229 | 229 | $checked = 0; |
230 | - foreach(array_keys($params) as $key) { |
|
231 | - if(in_array($key, $action['requirements'])) { |
|
230 | + foreach (array_keys($params) as $key) { |
|
231 | + if (in_array($key, $action['requirements'])) { |
|
232 | 232 | $checked++; |
233 | 233 | } |
234 | 234 | } |
235 | 235 | $valid = count($action['requirements']) == $checked; |
236 | - } else { |
|
236 | + }else { |
|
237 | 237 | $valid = false; |
238 | 238 | } |
239 | 239 | } |
@@ -254,7 +254,7 @@ discard block |
||
254 | 254 | */ |
255 | 255 | private function getExternalModules() { |
256 | 256 | $externalModules = Config::getParam('modules.extend', ''); |
257 | - if(Config::getParam('psfs.auth', false)) { |
|
257 | + if (Config::getParam('psfs.auth', false)) { |
|
258 | 258 | $externalModules .= ',psfs/auth'; |
259 | 259 | } |
260 | 260 | return $externalModules; |
@@ -288,10 +288,10 @@ discard block |
||
288 | 288 | $modules = $this->finder->directories()->in($modulesPath)->depth(0); |
289 | 289 | foreach ($modules 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 | - $this->cache->storeData(CONFIG_DIR . DIRECTORY_SEPARATOR . "domains.json", $this->domains, Cache::JSON, TRUE); |
|
294 | + $this->cache->storeData(CONFIG_DIR.DIRECTORY_SEPARATOR."domains.json", $this->domains, Cache::JSON, TRUE); |
|
295 | 295 | } |
296 | 296 | |
297 | 297 | /** |
@@ -306,7 +306,7 @@ discard block |
||
306 | 306 | $home_params = NULL; |
307 | 307 | foreach ($this->routing as $pattern => $params) { |
308 | 308 | list($method, $route) = RouterHelper::extractHttpRoute($pattern); |
309 | - if (preg_match("/" . preg_quote($route, "/") . "$/i", "/" . $home)) { |
|
309 | + if (preg_match("/".preg_quote($route, "/")."$/i", "/".$home)) { |
|
310 | 310 | $home_params = $params; |
311 | 311 | } |
312 | 312 | } |
@@ -331,7 +331,7 @@ discard block |
||
331 | 331 | $files = $this->finder->files()->in($origen)->path('/(controller|api)/i')->depth(1)->name("*.php"); |
332 | 332 | foreach ($files as $file) { |
333 | 333 | $filename = str_replace("/", '\\', str_replace($origen, '', $file->getPathname())); |
334 | - $routing = $this->addRouting($namespace . str_replace('.php', '', $filename), $routing, $namespace); |
|
334 | + $routing = $this->addRouting($namespace.str_replace('.php', '', $filename), $routing, $namespace); |
|
335 | 335 | } |
336 | 336 | $this->finder = new Finder(); |
337 | 337 | |
@@ -401,7 +401,7 @@ discard block |
||
401 | 401 | if (!$this->domains) { |
402 | 402 | $this->domains = []; |
403 | 403 | } |
404 | - $domain = "@" . $class->getConstant("DOMAIN") . "/"; |
|
404 | + $domain = "@".$class->getConstant("DOMAIN")."/"; |
|
405 | 405 | if (!array_key_exists($domain, $this->domains)) { |
406 | 406 | $this->domains[$domain] = RouterHelper::extractDomainInfo($class, $domain); |
407 | 407 | } |
@@ -416,11 +416,11 @@ discard block |
||
416 | 416 | */ |
417 | 417 | public function simpatize() |
418 | 418 | { |
419 | - $translationFileName = "translations" . DIRECTORY_SEPARATOR . "routes_translations.php"; |
|
420 | - $absoluteTranslationFileName = CACHE_DIR . DIRECTORY_SEPARATOR . $translationFileName; |
|
419 | + $translationFileName = "translations".DIRECTORY_SEPARATOR."routes_translations.php"; |
|
420 | + $absoluteTranslationFileName = CACHE_DIR.DIRECTORY_SEPARATOR.$translationFileName; |
|
421 | 421 | $this->generateSlugs($absoluteTranslationFileName); |
422 | 422 | GeneratorHelper::createDir(CONFIG_DIR); |
423 | - Cache::getInstance()->storeData(CONFIG_DIR . DIRECTORY_SEPARATOR . "urls.json", array($this->routing, $this->slugs), Cache::JSON, TRUE); |
|
423 | + Cache::getInstance()->storeData(CONFIG_DIR.DIRECTORY_SEPARATOR."urls.json", array($this->routing, $this->slugs), Cache::JSON, TRUE); |
|
424 | 424 | |
425 | 425 | return $this; |
426 | 426 | } |
@@ -438,16 +438,16 @@ discard block |
||
438 | 438 | public function getRoute($slug = '', $absolute = FALSE, $params = []) |
439 | 439 | { |
440 | 440 | if (strlen($slug) === 0) { |
441 | - return ($absolute) ? Request::getInstance()->getRootUrl() . '/' : '/'; |
|
441 | + return ($absolute) ? Request::getInstance()->getRootUrl().'/' : '/'; |
|
442 | 442 | } |
443 | 443 | if (!is_array($this->slugs) || !array_key_exists($slug, $this->slugs)) { |
444 | 444 | throw new RouterException(_("No existe la ruta especificada")); |
445 | 445 | } |
446 | - $url = ($absolute) ? Request::getInstance()->getRootUrl() . $this->slugs[$slug] : $this->slugs[$slug]; |
|
446 | + $url = ($absolute) ? Request::getInstance()->getRootUrl().$this->slugs[$slug] : $this->slugs[$slug]; |
|
447 | 447 | if (!empty($params)) foreach ($params as $key => $value) { |
448 | - $url = str_replace("{" . $key . "}", $value, $url); |
|
448 | + $url = str_replace("{".$key."}", $value, $url); |
|
449 | 449 | } elseif (!empty($this->routing[$this->slugs[$slug]]["default"])) { |
450 | - $url = ($absolute) ? Request::getInstance()->getRootUrl() . $this->routing[$this->slugs[$slug]]["default"] : $this->routing[$this->slugs[$slug]]["default"]; |
|
450 | + $url = ($absolute) ? Request::getInstance()->getRootUrl().$this->routing[$this->slugs[$slug]]["default"] : $this->routing[$this->slugs[$slug]]["default"]; |
|
451 | 451 | } |
452 | 452 | |
453 | 453 | return preg_replace('/(GET|POST|PUT|DELETE|ALL)\#\|\#/', '', $url); |
@@ -492,17 +492,17 @@ discard block |
||
492 | 492 | */ |
493 | 493 | protected function executeCachedRoute($route, $action, $class, $params = NULL) |
494 | 494 | { |
495 | - Logger::log('Executing route ' . $route, LOG_INFO); |
|
495 | + Logger::log('Executing route '.$route, LOG_INFO); |
|
496 | 496 | $action['params'] = array_merge($action['params'], $params, Request::getInstance()->getQueryParams()); |
497 | 497 | Security::getInstance()->setSessionKey("__CACHE__", $action); |
498 | 498 | $cache = Cache::needCache(); |
499 | 499 | $execute = TRUE; |
500 | 500 | if (FALSE !== $cache && Config::getInstance()->getDebugMode() === FALSE && $action['http'] === 'GET') { |
501 | 501 | list($path, $cacheDataName) = $this->cache->getRequestCacheHash(); |
502 | - $cachedData = $this->cache->readFromCache("json" . DIRECTORY_SEPARATOR . $path . $cacheDataName, |
|
502 | + $cachedData = $this->cache->readFromCache("json".DIRECTORY_SEPARATOR.$path.$cacheDataName, |
|
503 | 503 | $cache, null); |
504 | 504 | if (NULL !== $cachedData) { |
505 | - $headers = $this->cache->readFromCache("json" . DIRECTORY_SEPARATOR . $path . $cacheDataName . ".headers", |
|
505 | + $headers = $this->cache->readFromCache("json".DIRECTORY_SEPARATOR.$path.$cacheDataName.".headers", |
|
506 | 506 | $cache, null, Cache::JSON); |
507 | 507 | Template::getInstance()->renderCache($cachedData, $headers); |
508 | 508 | $execute = FALSE; |
@@ -548,11 +548,11 @@ discard block |
||
548 | 548 | private function loadExternalAutoloader(bool $hydrateRoute, SplFileInfo $modulePath, $externalModulePath) |
549 | 549 | { |
550 | 550 | $extModule = $modulePath->getBasename(); |
551 | - $moduleAutoloader = realpath($externalModulePath . DIRECTORY_SEPARATOR . $extModule . DIRECTORY_SEPARATOR . 'autoload.php'); |
|
551 | + $moduleAutoloader = realpath($externalModulePath.DIRECTORY_SEPARATOR.$extModule.DIRECTORY_SEPARATOR.'autoload.php'); |
|
552 | 552 | if (file_exists($moduleAutoloader)) { |
553 | 553 | @include $moduleAutoloader; |
554 | 554 | if ($hydrateRoute) { |
555 | - $this->routing = $this->inspectDir($externalModulePath . DIRECTORY_SEPARATOR . $extModule, '\\' . $extModule, $this->routing); |
|
555 | + $this->routing = $this->inspectDir($externalModulePath.DIRECTORY_SEPARATOR.$extModule, '\\'.$extModule, $this->routing); |
|
556 | 556 | } |
557 | 557 | } |
558 | 558 | } |
@@ -565,7 +565,7 @@ discard block |
||
565 | 565 | private function loadExternalModule(bool $hydrateRoute, $module) |
566 | 566 | { |
567 | 567 | $module = preg_replace('/(\\\|\/)/', DIRECTORY_SEPARATOR, $module); |
568 | - $externalModulePath = VENDOR_DIR . DIRECTORY_SEPARATOR . $module . DIRECTORY_SEPARATOR . 'src'; |
|
568 | + $externalModulePath = VENDOR_DIR.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.'src'; |
|
569 | 569 | if (file_exists($externalModulePath)) { |
570 | 570 | $externalModule = $this->finder->directories()->in($externalModulePath)->depth(0); |
571 | 571 | if (!empty($externalModule)) { |