@@ -542,7 +542,7 @@ |
||
| 542 | 542 | /** |
| 543 | 543 | * @param $hydrateRoute |
| 544 | 544 | * @param $modulePath |
| 545 | - * @param $externalModulePath |
|
| 545 | + * @param string $externalModulePath |
|
| 546 | 546 | */ |
| 547 | 547 | private function loadExternalAutoloader(bool $hydrateRoute, \DirectoryIterator $modulePath, $externalModulePath) |
| 548 | 548 | { |
@@ -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; |
@@ -287,10 +287,10 @@ discard block |
||
| 287 | 287 | $modules = $this->finder->directories()->in($modulesPath)->depth(0); |
| 288 | 288 | foreach ($modules as $modulePath) { |
| 289 | 289 | $module = $modulePath->getBasename(); |
| 290 | - $this->routing = $this->inspectDir($modulesPath . DIRECTORY_SEPARATOR . $module, $module, $this->routing); |
|
| 290 | + $this->routing = $this->inspectDir($modulesPath.DIRECTORY_SEPARATOR.$module, $module, $this->routing); |
|
| 291 | 291 | } |
| 292 | 292 | } |
| 293 | - $this->cache->storeData(CONFIG_DIR . DIRECTORY_SEPARATOR . "domains.json", $this->domains, Cache::JSON, TRUE); |
|
| 293 | + $this->cache->storeData(CONFIG_DIR.DIRECTORY_SEPARATOR."domains.json", $this->domains, Cache::JSON, TRUE); |
|
| 294 | 294 | } |
| 295 | 295 | |
| 296 | 296 | /** |
@@ -305,7 +305,7 @@ discard block |
||
| 305 | 305 | $home_params = NULL; |
| 306 | 306 | foreach ($this->routing as $pattern => $params) { |
| 307 | 307 | list($method, $route) = RouterHelper::extractHttpRoute($pattern); |
| 308 | - if (preg_match("/" . preg_quote($route, "/") . "$/i", "/" . $home)) { |
|
| 308 | + if (preg_match("/".preg_quote($route, "/")."$/i", "/".$home)) { |
|
| 309 | 309 | $home_params = $params; |
| 310 | 310 | } |
| 311 | 311 | } |
@@ -330,7 +330,7 @@ discard block |
||
| 330 | 330 | $files = $this->finder->files()->in($origen)->path('/(controller|api)/i')->depth(1)->name("*.php"); |
| 331 | 331 | foreach ($files as $file) { |
| 332 | 332 | $filename = str_replace("/", '\\', str_replace($origen, '', $file->getPathname())); |
| 333 | - $routing = $this->addRouting($namespace . str_replace('.php', '', $filename), $routing, $namespace); |
|
| 333 | + $routing = $this->addRouting($namespace.str_replace('.php', '', $filename), $routing, $namespace); |
|
| 334 | 334 | } |
| 335 | 335 | $this->finder = new Finder(); |
| 336 | 336 | |
@@ -400,7 +400,7 @@ discard block |
||
| 400 | 400 | if (!$this->domains) { |
| 401 | 401 | $this->domains = []; |
| 402 | 402 | } |
| 403 | - $domain = "@" . $class->getConstant("DOMAIN") . "/"; |
|
| 403 | + $domain = "@".$class->getConstant("DOMAIN")."/"; |
|
| 404 | 404 | if (!array_key_exists($domain, $this->domains)) { |
| 405 | 405 | $this->domains[$domain] = RouterHelper::extractDomainInfo($class, $domain); |
| 406 | 406 | } |
@@ -415,11 +415,11 @@ discard block |
||
| 415 | 415 | */ |
| 416 | 416 | public function simpatize() |
| 417 | 417 | { |
| 418 | - $translationFileName = "translations" . DIRECTORY_SEPARATOR . "routes_translations.php"; |
|
| 419 | - $absoluteTranslationFileName = CACHE_DIR . DIRECTORY_SEPARATOR . $translationFileName; |
|
| 418 | + $translationFileName = "translations".DIRECTORY_SEPARATOR."routes_translations.php"; |
|
| 419 | + $absoluteTranslationFileName = CACHE_DIR.DIRECTORY_SEPARATOR.$translationFileName; |
|
| 420 | 420 | $this->generateSlugs($absoluteTranslationFileName); |
| 421 | 421 | GeneratorHelper::createDir(CONFIG_DIR); |
| 422 | - Cache::getInstance()->storeData(CONFIG_DIR . DIRECTORY_SEPARATOR . "urls.json", array($this->routing, $this->slugs), Cache::JSON, TRUE); |
|
| 422 | + Cache::getInstance()->storeData(CONFIG_DIR.DIRECTORY_SEPARATOR."urls.json", array($this->routing, $this->slugs), Cache::JSON, TRUE); |
|
| 423 | 423 | |
| 424 | 424 | return $this; |
| 425 | 425 | } |
@@ -437,16 +437,16 @@ discard block |
||
| 437 | 437 | public function getRoute($slug = '', $absolute = FALSE, $params = []) |
| 438 | 438 | { |
| 439 | 439 | if (strlen($slug) === 0) { |
| 440 | - return ($absolute) ? Request::getInstance()->getRootUrl() . '/' : '/'; |
|
| 440 | + return ($absolute) ? Request::getInstance()->getRootUrl().'/' : '/'; |
|
| 441 | 441 | } |
| 442 | 442 | if (!is_array($this->slugs) || !array_key_exists($slug, $this->slugs)) { |
| 443 | 443 | throw new RouterException(_("No existe la ruta especificada")); |
| 444 | 444 | } |
| 445 | - $url = ($absolute) ? Request::getInstance()->getRootUrl() . $this->slugs[$slug] : $this->slugs[$slug]; |
|
| 445 | + $url = ($absolute) ? Request::getInstance()->getRootUrl().$this->slugs[$slug] : $this->slugs[$slug]; |
|
| 446 | 446 | if (!empty($params)) foreach ($params as $key => $value) { |
| 447 | - $url = str_replace("{" . $key . "}", $value, $url); |
|
| 447 | + $url = str_replace("{".$key."}", $value, $url); |
|
| 448 | 448 | } elseif (!empty($this->routing[$this->slugs[$slug]]["default"])) { |
| 449 | - $url = ($absolute) ? Request::getInstance()->getRootUrl() . $this->routing[$this->slugs[$slug]]["default"] : $this->routing[$this->slugs[$slug]]["default"]; |
|
| 449 | + $url = ($absolute) ? Request::getInstance()->getRootUrl().$this->routing[$this->slugs[$slug]]["default"] : $this->routing[$this->slugs[$slug]]["default"]; |
|
| 450 | 450 | } |
| 451 | 451 | |
| 452 | 452 | return preg_replace('/(GET|POST|PUT|DELETE|ALL)\#\|\#/', '', $url); |
@@ -491,17 +491,17 @@ discard block |
||
| 491 | 491 | */ |
| 492 | 492 | protected function executeCachedRoute($route, $action, $class, $params = NULL) |
| 493 | 493 | { |
| 494 | - Logger::log('Executing route ' . $route, LOG_INFO); |
|
| 494 | + Logger::log('Executing route '.$route, LOG_INFO); |
|
| 495 | 495 | $action['params'] = array_merge($action['params'], $params, Request::getInstance()->getQueryParams()); |
| 496 | 496 | Security::getInstance()->setSessionKey("__CACHE__", $action); |
| 497 | 497 | $cache = Cache::needCache(); |
| 498 | 498 | $execute = TRUE; |
| 499 | 499 | if (FALSE !== $cache && Config::getInstance()->getDebugMode() === FALSE && $action['http'] === 'GET') { |
| 500 | 500 | list($path, $cacheDataName) = $this->cache->getRequestCacheHash(); |
| 501 | - $cachedData = $this->cache->readFromCache("json" . DIRECTORY_SEPARATOR . $path . $cacheDataName, |
|
| 501 | + $cachedData = $this->cache->readFromCache("json".DIRECTORY_SEPARATOR.$path.$cacheDataName, |
|
| 502 | 502 | $cache, null); |
| 503 | 503 | if (NULL !== $cachedData) { |
| 504 | - $headers = $this->cache->readFromCache("json" . DIRECTORY_SEPARATOR . $path . $cacheDataName . ".headers", |
|
| 504 | + $headers = $this->cache->readFromCache("json".DIRECTORY_SEPARATOR.$path.$cacheDataName.".headers", |
|
| 505 | 505 | $cache, null, Cache::JSON); |
| 506 | 506 | Template::getInstance()->renderCache($cachedData, $headers); |
| 507 | 507 | $execute = FALSE; |
@@ -547,11 +547,11 @@ discard block |
||
| 547 | 547 | private function loadExternalAutoloader(bool $hydrateRoute, \DirectoryIterator $modulePath, $externalModulePath) |
| 548 | 548 | { |
| 549 | 549 | $extModule = $modulePath->getBasename(); |
| 550 | - $moduleAutoloader = realpath($externalModulePath . DIRECTORY_SEPARATOR . $extModule . DIRECTORY_SEPARATOR . 'autoload.php'); |
|
| 550 | + $moduleAutoloader = realpath($externalModulePath.DIRECTORY_SEPARATOR.$extModule.DIRECTORY_SEPARATOR.'autoload.php'); |
|
| 551 | 551 | if (file_exists($moduleAutoloader)) { |
| 552 | 552 | @include $moduleAutoloader; |
| 553 | 553 | if ($hydrateRoute) { |
| 554 | - $this->routing = $this->inspectDir($externalModulePath . DIRECTORY_SEPARATOR . $extModule, '\\' . $extModule, $this->routing); |
|
| 554 | + $this->routing = $this->inspectDir($externalModulePath.DIRECTORY_SEPARATOR.$extModule, '\\'.$extModule, $this->routing); |
|
| 555 | 555 | } |
| 556 | 556 | } |
| 557 | 557 | } |
@@ -564,7 +564,7 @@ discard block |
||
| 564 | 564 | private function loadExternalModule(bool $hydrateRoute, $module) |
| 565 | 565 | { |
| 566 | 566 | $module = preg_replace('/(\\\|\/)/', DIRECTORY_SEPARATOR, $module); |
| 567 | - $externalModulePath = VENDOR_DIR . DIRECTORY_SEPARATOR . $module . DIRECTORY_SEPARATOR . 'src'; |
|
| 567 | + $externalModulePath = VENDOR_DIR.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.'src'; |
|
| 568 | 568 | if (file_exists($externalModulePath)) { |
| 569 | 569 | $externalModule = $this->finder->directories()->in($externalModulePath)->depth(0); |
| 570 | 570 | if (!empty($externalModule)) { |