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