@@ -63,11 +63,11 @@ discard block |
||
| 63 | 63 | */ |
| 64 | 64 | public function init() |
| 65 | 65 | { |
| 66 | - list($this->routing, $this->slugs) = $this->cache->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . "urls.json", $this->cacheType, TRUE); |
|
| 66 | + list($this->routing, $this->slugs) = $this->cache->getDataFromFile(CONFIG_DIR.DIRECTORY_SEPARATOR."urls.json", $this->cacheType, TRUE); |
|
| 67 | 67 | if (empty($this->routing) || Config::getInstance()->getDebugMode()) { |
| 68 | 68 | $this->debugLoad(); |
| 69 | - } else { |
|
| 70 | - $this->domains = $this->cache->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . "domains.json", $this->cacheType, TRUE); |
|
| 69 | + }else { |
|
| 70 | + $this->domains = $this->cache->getDataFromFile(CONFIG_DIR.DIRECTORY_SEPARATOR."domains.json", $this->cacheType, TRUE); |
|
| 71 | 71 | } |
| 72 | 72 | $this->checkExternalModules(false); |
| 73 | 73 | $this->setLoaded(true); |
@@ -102,11 +102,11 @@ discard block |
||
| 102 | 102 | if (preg_match('/json/i', Request::getInstance()->getServer('CONTENT_TYPE')) || $isJson) { |
| 103 | 103 | $response = new JsonResponse(null, false, 0, 0, $e->getMessage()); |
| 104 | 104 | return $template->output(json_encode($response), 'application/json'); |
| 105 | - } else { |
|
| 105 | + }else { |
|
| 106 | 106 | $not_found_route = Config::getParam('route.404'); |
| 107 | - if(null !== $not_found_route) { |
|
| 107 | + if (null !== $not_found_route) { |
|
| 108 | 108 | Request::getInstance()->redirect($this->getRoute($not_found_route, true)); |
| 109 | - } else { |
|
| 109 | + }else { |
|
| 110 | 110 | return $template->render('error.html.twig', array( |
| 111 | 111 | 'exception' => $e, |
| 112 | 112 | 'trace' => $e->getTraceAsString(), |
@@ -161,12 +161,12 @@ discard block |
||
| 161 | 161 | try { |
| 162 | 162 | //Search action and execute |
| 163 | 163 | $this->searchAction($route); |
| 164 | - } catch (AccessDeniedException $e) { |
|
| 165 | - Logger::log(_('Solicitamos credenciales de acceso a zona restringida'), LOG_WARNING, ['file' => $e->getFile() . '[' . $e->getLine() . ']']); |
|
| 164 | + }catch (AccessDeniedException $e) { |
|
| 165 | + Logger::log(_('Solicitamos credenciales de acceso a zona restringida'), LOG_WARNING, ['file' => $e->getFile().'['.$e->getLine().']']); |
|
| 166 | 166 | return Admin::staticAdminLogon($route); |
| 167 | - } catch (RouterException $r) { |
|
| 167 | + }catch (RouterException $r) { |
|
| 168 | 168 | Logger::log($r->getMessage(), LOG_WARNING); |
| 169 | - } catch (\Exception $e) { |
|
| 169 | + }catch (\Exception $e) { |
|
| 170 | 170 | Logger::log($e->getMessage(), LOG_ERR); |
| 171 | 171 | throw $e; |
| 172 | 172 | } |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | */ |
| 184 | 184 | protected function searchAction($route) |
| 185 | 185 | { |
| 186 | - Logger::log('Searching action to execute: ' . $route, LOG_INFO); |
|
| 186 | + Logger::log('Searching action to execute: '.$route, LOG_INFO); |
|
| 187 | 187 | //Revisamos si tenemos la ruta registrada |
| 188 | 188 | $parts = parse_url($route); |
| 189 | 189 | $path = (array_key_exists('path', $parts)) ? $parts['path'] : $route; |
@@ -198,12 +198,12 @@ discard block |
||
| 198 | 198 | /** @var $class \PSFS\base\types\Controller */ |
| 199 | 199 | $class = RouterHelper::getClassToCall($action); |
| 200 | 200 | try { |
| 201 | - if($this->checkRequirements($action, $get)) { |
|
| 201 | + if ($this->checkRequirements($action, $get)) { |
|
| 202 | 202 | $this->executeCachedRoute($route, $action, $class, $get); |
| 203 | - } else { |
|
| 203 | + }else { |
|
| 204 | 204 | throw new RouterException(_('La ruta no es válida'), 400); |
| 205 | 205 | } |
| 206 | - } catch (\Exception $e) { |
|
| 206 | + }catch (\Exception $e) { |
|
| 207 | 207 | Logger::log($e->getMessage(), LOG_ERR); |
| 208 | 208 | throw $e; |
| 209 | 209 | } |
@@ -218,15 +218,15 @@ discard block |
||
| 218 | 218 | * @return bool |
| 219 | 219 | */ |
| 220 | 220 | private function checkRequirements(array $action, array $params = []) { |
| 221 | - if(!empty($action['requirements']) && !empty($params)) { |
|
| 221 | + if (!empty($action['requirements']) && !empty($params)) { |
|
| 222 | 222 | $checked = 0; |
| 223 | - foreach(array_keys($params) as $key) { |
|
| 224 | - if(in_array($key, $action['requirements'])) { |
|
| 223 | + foreach (array_keys($params) as $key) { |
|
| 224 | + if (in_array($key, $action['requirements'])) { |
|
| 225 | 225 | $checked++; |
| 226 | 226 | } |
| 227 | 227 | } |
| 228 | 228 | $valid = count($action['requirements']) == $checked; |
| 229 | - } else { |
|
| 229 | + }else { |
|
| 230 | 230 | $valid = true; |
| 231 | 231 | } |
| 232 | 232 | return $valid; |
@@ -278,10 +278,10 @@ discard block |
||
| 278 | 278 | $modules = $this->finder->directories()->in($modulesPath)->depth(0); |
| 279 | 279 | foreach ($modules as $modulePath) { |
| 280 | 280 | $module = $modulePath->getBasename(); |
| 281 | - $this->routing = $this->inspectDir($modulesPath . DIRECTORY_SEPARATOR . $module, $module, $this->routing); |
|
| 281 | + $this->routing = $this->inspectDir($modulesPath.DIRECTORY_SEPARATOR.$module, $module, $this->routing); |
|
| 282 | 282 | } |
| 283 | 283 | } |
| 284 | - $this->cache->storeData(CONFIG_DIR . DIRECTORY_SEPARATOR . "domains.json", $this->domains, Cache::JSON, TRUE); |
|
| 284 | + $this->cache->storeData(CONFIG_DIR.DIRECTORY_SEPARATOR."domains.json", $this->domains, Cache::JSON, TRUE); |
|
| 285 | 285 | } |
| 286 | 286 | |
| 287 | 287 | /** |
@@ -296,7 +296,7 @@ discard block |
||
| 296 | 296 | $home_params = NULL; |
| 297 | 297 | foreach ($this->routing as $pattern => $params) { |
| 298 | 298 | list($method, $route) = RouterHelper::extractHttpRoute($pattern); |
| 299 | - if (preg_match("/" . preg_quote($route, "/") . "$/i", "/" . $home)) { |
|
| 299 | + if (preg_match("/".preg_quote($route, "/")."$/i", "/".$home)) { |
|
| 300 | 300 | $home_params = $params; |
| 301 | 301 | } |
| 302 | 302 | } |
@@ -321,7 +321,7 @@ discard block |
||
| 321 | 321 | $files = $this->finder->files()->in($origen)->path('/(controller|api)/i')->depth(1)->name("*.php"); |
| 322 | 322 | foreach ($files as $file) { |
| 323 | 323 | $filename = str_replace("/", '\\', str_replace($origen, '', $file->getPathname())); |
| 324 | - $routing = $this->addRouting($namespace . str_replace('.php', '', $filename), $routing, $namespace); |
|
| 324 | + $routing = $this->addRouting($namespace.str_replace('.php', '', $filename), $routing, $namespace); |
|
| 325 | 325 | } |
| 326 | 326 | $this->finder = new Finder(); |
| 327 | 327 | |
@@ -351,7 +351,7 @@ discard block |
||
| 351 | 351 | private function addRouting($namespace, &$routing, $module = 'PSFS') |
| 352 | 352 | { |
| 353 | 353 | if (self::exists($namespace)) { |
| 354 | - if(I18nHelper::checkI18Class($namespace)) { |
|
| 354 | + if (I18nHelper::checkI18Class($namespace)) { |
|
| 355 | 355 | return $routing; |
| 356 | 356 | } |
| 357 | 357 | $reflection = new \ReflectionClass($namespace); |
@@ -394,7 +394,7 @@ discard block |
||
| 394 | 394 | if (!$this->domains) { |
| 395 | 395 | $this->domains = []; |
| 396 | 396 | } |
| 397 | - $domain = "@" . $class->getConstant("DOMAIN") . "/"; |
|
| 397 | + $domain = "@".$class->getConstant("DOMAIN")."/"; |
|
| 398 | 398 | if (!array_key_exists($domain, $this->domains)) { |
| 399 | 399 | $this->domains[$domain] = RouterHelper::extractDomainInfo($class, $domain); |
| 400 | 400 | } |
@@ -409,11 +409,11 @@ discard block |
||
| 409 | 409 | */ |
| 410 | 410 | public function simpatize() |
| 411 | 411 | { |
| 412 | - $translationFileName = "translations" . DIRECTORY_SEPARATOR . "routes_translations.php"; |
|
| 413 | - $absoluteTranslationFileName = CACHE_DIR . DIRECTORY_SEPARATOR . $translationFileName; |
|
| 412 | + $translationFileName = "translations".DIRECTORY_SEPARATOR."routes_translations.php"; |
|
| 413 | + $absoluteTranslationFileName = CACHE_DIR.DIRECTORY_SEPARATOR.$translationFileName; |
|
| 414 | 414 | $this->generateSlugs($absoluteTranslationFileName); |
| 415 | 415 | GeneratorHelper::createDir(CONFIG_DIR); |
| 416 | - Cache::getInstance()->storeData(CONFIG_DIR . DIRECTORY_SEPARATOR . "urls.json", array($this->routing, $this->slugs), Cache::JSON, TRUE); |
|
| 416 | + Cache::getInstance()->storeData(CONFIG_DIR.DIRECTORY_SEPARATOR."urls.json", array($this->routing, $this->slugs), Cache::JSON, TRUE); |
|
| 417 | 417 | |
| 418 | 418 | return $this; |
| 419 | 419 | } |
@@ -431,16 +431,16 @@ discard block |
||
| 431 | 431 | public function getRoute($slug = '', $absolute = FALSE, $params = []) |
| 432 | 432 | { |
| 433 | 433 | if (strlen($slug) === 0) { |
| 434 | - return ($absolute) ? Request::getInstance()->getRootUrl() . '/' : '/'; |
|
| 434 | + return ($absolute) ? Request::getInstance()->getRootUrl().'/' : '/'; |
|
| 435 | 435 | } |
| 436 | 436 | if (!is_array($this->slugs) || !array_key_exists($slug, $this->slugs)) { |
| 437 | 437 | throw new RouterException(_("No existe la ruta especificada")); |
| 438 | 438 | } |
| 439 | - $url = ($absolute) ? Request::getInstance()->getRootUrl() . $this->slugs[$slug] : $this->slugs[$slug]; |
|
| 439 | + $url = ($absolute) ? Request::getInstance()->getRootUrl().$this->slugs[$slug] : $this->slugs[$slug]; |
|
| 440 | 440 | if (!empty($params)) foreach ($params as $key => $value) { |
| 441 | - $url = str_replace("{" . $key . "}", $value, $url); |
|
| 441 | + $url = str_replace("{".$key."}", $value, $url); |
|
| 442 | 442 | } elseif (!empty($this->routing[$this->slugs[$slug]]["default"])) { |
| 443 | - $url = ($absolute) ? Request::getInstance()->getRootUrl() . $this->routing[$this->slugs[$slug]]["default"] : $this->routing[$this->slugs[$slug]]["default"]; |
|
| 443 | + $url = ($absolute) ? Request::getInstance()->getRootUrl().$this->routing[$this->slugs[$slug]]["default"] : $this->routing[$this->slugs[$slug]]["default"]; |
|
| 444 | 444 | } |
| 445 | 445 | |
| 446 | 446 | return preg_replace('/(GET|POST|PUT|DELETE|ALL)\#\|\#/', '', $url); |
@@ -485,17 +485,17 @@ discard block |
||
| 485 | 485 | */ |
| 486 | 486 | protected function executeCachedRoute($route, $action, $class, $params = NULL) |
| 487 | 487 | { |
| 488 | - Logger::log('Executing route ' . $route, LOG_INFO); |
|
| 488 | + Logger::log('Executing route '.$route, LOG_INFO); |
|
| 489 | 489 | $action['params'] = array_merge($action['params'], $params, Request::getInstance()->getQueryParams()); |
| 490 | 490 | Security::getInstance()->setSessionKey("__CACHE__", $action); |
| 491 | 491 | $cache = Cache::needCache(); |
| 492 | 492 | $execute = TRUE; |
| 493 | 493 | if (FALSE !== $cache && Config::getParam('debug') === FALSE && $action['http'] === 'GET') { |
| 494 | 494 | list($path, $cacheDataName) = $this->cache->getRequestCacheHash(); |
| 495 | - $cachedData = $this->cache->readFromCache("json" . DIRECTORY_SEPARATOR . $path . $cacheDataName, |
|
| 495 | + $cachedData = $this->cache->readFromCache("json".DIRECTORY_SEPARATOR.$path.$cacheDataName, |
|
| 496 | 496 | $cache, null); |
| 497 | 497 | if (NULL !== $cachedData) { |
| 498 | - $headers = $this->cache->readFromCache("json" . DIRECTORY_SEPARATOR . $path . $cacheDataName . ".headers", |
|
| 498 | + $headers = $this->cache->readFromCache("json".DIRECTORY_SEPARATOR.$path.$cacheDataName.".headers", |
|
| 499 | 499 | $cache, null, Cache::JSON); |
| 500 | 500 | Template::getInstance()->renderCache($cachedData, $headers); |
| 501 | 501 | $execute = FALSE; |
@@ -538,11 +538,11 @@ discard block |
||
| 538 | 538 | private function loadExternalAutoloader($hydrateRoute, SplFileInfo $modulePath, $externalModulePath) |
| 539 | 539 | { |
| 540 | 540 | $extModule = $modulePath->getBasename(); |
| 541 | - $moduleAutoloader = realpath($externalModulePath . DIRECTORY_SEPARATOR . $extModule . DIRECTORY_SEPARATOR . 'autoload.php'); |
|
| 542 | - if(file_exists($moduleAutoloader)) { |
|
| 541 | + $moduleAutoloader = realpath($externalModulePath.DIRECTORY_SEPARATOR.$extModule.DIRECTORY_SEPARATOR.'autoload.php'); |
|
| 542 | + if (file_exists($moduleAutoloader)) { |
|
| 543 | 543 | include_once $moduleAutoloader; |
| 544 | 544 | if ($hydrateRoute) { |
| 545 | - $this->routing = $this->inspectDir($externalModulePath . DIRECTORY_SEPARATOR . $extModule, '\\' . $extModule, $this->routing); |
|
| 545 | + $this->routing = $this->inspectDir($externalModulePath.DIRECTORY_SEPARATOR.$extModule, '\\'.$extModule, $this->routing); |
|
| 546 | 546 | } |
| 547 | 547 | } |
| 548 | 548 | } |
@@ -556,12 +556,12 @@ discard block |
||
| 556 | 556 | { |
| 557 | 557 | try { |
| 558 | 558 | $module = preg_replace('/(\\\|\/)/', DIRECTORY_SEPARATOR, $module); |
| 559 | - $externalModulePath = VENDOR_DIR . DIRECTORY_SEPARATOR . $module . DIRECTORY_SEPARATOR . 'src'; |
|
| 559 | + $externalModulePath = VENDOR_DIR.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.'src'; |
|
| 560 | 560 | $externalModule = $this->finder->directories()->in($externalModulePath)->depth(0); |
| 561 | 561 | foreach ($externalModule as $modulePath) { |
| 562 | 562 | $this->loadExternalAutoloader($hydrateRoute, $modulePath, $externalModulePath); |
| 563 | 563 | } |
| 564 | - } catch (\Exception $e) { |
|
| 564 | + }catch (\Exception $e) { |
|
| 565 | 565 | Logger::log($e->getMessage(), LOG_WARNING); |
| 566 | 566 | $module = null; |
| 567 | 567 | } |