@@ -59,12 +59,12 @@ discard block |
||
| 59 | 59 | */ |
| 60 | 60 | public function init() |
| 61 | 61 | { |
| 62 | - if (!file_exists(CONFIG_DIR . DIRECTORY_SEPARATOR . "urls.json") || Config::getInstance()->getDebugMode()) { |
|
| 62 | + if (!file_exists(CONFIG_DIR.DIRECTORY_SEPARATOR."urls.json") || Config::getInstance()->getDebugMode()) { |
|
| 63 | 63 | $this->hydrateRouting(); |
| 64 | 64 | $this->simpatize(); |
| 65 | - } else { |
|
| 66 | - list($this->routing, $this->slugs) = $this->cache->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . "urls.json", Cache::JSON, TRUE); |
|
| 67 | - $this->domains = $this->cache->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . "domains.json", Cache::JSON, TRUE); |
|
| 65 | + }else { |
|
| 66 | + list($this->routing, $this->slugs) = $this->cache->getDataFromFile(CONFIG_DIR.DIRECTORY_SEPARATOR."urls.json", Cache::JSON, TRUE); |
|
| 67 | + $this->domains = $this->cache->getDataFromFile(CONFIG_DIR.DIRECTORY_SEPARATOR."domains.json", Cache::JSON, TRUE); |
|
| 68 | 68 | } |
| 69 | 69 | } |
| 70 | 70 | |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | "success" => FALSE, |
| 85 | 85 | "error" => $e->getMessage(), |
| 86 | 86 | )), 'application/json'); |
| 87 | - } else { |
|
| 87 | + }else { |
|
| 88 | 88 | if (NULL === $e) { |
| 89 | 89 | $e = new \Exception(_('Página no encontrada'), 404); |
| 90 | 90 | } |
@@ -124,24 +124,24 @@ discard block |
||
| 124 | 124 | |
| 125 | 125 | //Search action and execute |
| 126 | 126 | return $this->searchAction($route); |
| 127 | - } catch (AccessDeniedException $e) { |
|
| 127 | + }catch (AccessDeniedException $e) { |
|
| 128 | 128 | Logger::getInstance()->debugLog(_('Solicitamos credenciales de acceso a zona restringida')); |
| 129 | 129 | if ('login' === Config::getInstance()->get('admin_login')) { |
| 130 | 130 | return $this->redirectLogin($route); |
| 131 | - } else { |
|
| 131 | + }else { |
|
| 132 | 132 | return $this->sentAuthHeader(); |
| 133 | 133 | } |
| 134 | - } catch (RouterException $r) { |
|
| 134 | + }catch (RouterException $r) { |
|
| 135 | 135 | if (FALSE !== preg_match('/\/$/', $route)) { |
| 136 | 136 | if (preg_match('/admin/', $route)) { |
| 137 | 137 | $default = Config::getInstance()->get('admin_action'); |
| 138 | - } else { |
|
| 138 | + }else { |
|
| 139 | 139 | $default = Config::getInstance()->get('home_action'); |
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | return $this->execute($this->getRoute($default)); |
| 143 | 143 | } |
| 144 | - } catch (\Exception $e) { |
|
| 144 | + }catch (\Exception $e) { |
|
| 145 | 145 | Logger::getInstance()->errorLog($e->getMessage()); |
| 146 | 146 | throw $e; |
| 147 | 147 | } |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | $corsEnabled = Config::getInstance()->get('cors.enabled'); |
| 158 | 158 | $request = Request::getInstance(); |
| 159 | 159 | if (NULL !== $corsEnabled && null !== $request->getServer('HTTP_REFERER')) { |
| 160 | - if($corsEnabled == '*' || preg_match($corsEnabled, $request->getServer('HTTP_REFERER'))) { |
|
| 160 | + if ($corsEnabled == '*' || preg_match($corsEnabled, $request->getServer('HTTP_REFERER'))) { |
|
| 161 | 161 | if (!$this->headersSent) { |
| 162 | 162 | header("Access-Control-Allow-Credentials: true"); |
| 163 | 163 | header("Access-Control-Allow-Origin: *"); |
@@ -165,8 +165,8 @@ discard block |
||
| 165 | 165 | header("Access-Control-Allow-Headers: Access-Control-Allow-Methods, Access-Control-Allow-Headers, Access-Control-Allow-Origin, Origin, X-Requested-With, Content-Type, Accept, Authorization, X-API-SEC-TOKEN, X-API-USER-TOKEN"); |
| 166 | 166 | $this->headersSent = true; |
| 167 | 167 | } |
| 168 | - if(Request::getInstance()->getMethod() == 'OPTIONS') { |
|
| 169 | - header( "HTTP/1.1 200 OK" ); |
|
| 168 | + if (Request::getInstance()->getMethod() == 'OPTIONS') { |
|
| 169 | + header("HTTP/1.1 200 OK"); |
|
| 170 | 170 | exit(); |
| 171 | 171 | } |
| 172 | 172 | } |
@@ -181,11 +181,11 @@ discard block |
||
| 181 | 181 | */ |
| 182 | 182 | private function compareSlashes($routePattern, $path) { |
| 183 | 183 | $pattern_sep = count(explode('/', $routePattern)); |
| 184 | - if(preg_match('/\/$/', $routePattern)) { |
|
| 184 | + if (preg_match('/\/$/', $routePattern)) { |
|
| 185 | 185 | $pattern_sep--; |
| 186 | 186 | } |
| 187 | 187 | $path_sep = count(explode('/', $path)); |
| 188 | - if(preg_match('/\/$/', $path)) { |
|
| 188 | + if (preg_match('/\/$/', $path)) { |
|
| 189 | 189 | $path_sep--; |
| 190 | 190 | } |
| 191 | 191 | return abs($pattern_sep - $path_sep) < 1; |
@@ -213,7 +213,7 @@ discard block |
||
| 213 | 213 | $class = $this->getClassToCall($action); |
| 214 | 214 | try { |
| 215 | 215 | return $this->executeCachedRoute($route, $action, $class, $get); |
| 216 | - } catch (\Exception $e) { |
|
| 216 | + }catch (\Exception $e) { |
|
| 217 | 217 | Logger::getInstance()->debugLog($e->getMessage(), array($e->getFile(), $e->getLine())); |
| 218 | 218 | throw new RouterException($e->getMessage(), 404, $e); |
| 219 | 219 | } |
@@ -301,13 +301,13 @@ discard block |
||
| 301 | 301 | if (file_exists($modules)) { |
| 302 | 302 | $this->routing = $this->inspectDir($modules, "", $this->routing); |
| 303 | 303 | } |
| 304 | - $this->cache->storeData(CONFIG_DIR . DIRECTORY_SEPARATOR . "domains.json", $this->domains, Cache::JSON, TRUE); |
|
| 304 | + $this->cache->storeData(CONFIG_DIR.DIRECTORY_SEPARATOR."domains.json", $this->domains, Cache::JSON, TRUE); |
|
| 305 | 305 | $home = Config::getInstance()->get('home_action'); |
| 306 | 306 | if (NULL !== $home || $home !== '') { |
| 307 | 307 | $home_params = NULL; |
| 308 | 308 | foreach ($this->routing as $pattern => $params) { |
| 309 | 309 | list($method, $route) = $this->extractHttpRoute($pattern); |
| 310 | - if (preg_match("/" . preg_quote($route, "/") . "$/i", "/" . $home)) { |
|
| 310 | + if (preg_match("/".preg_quote($route, "/")."$/i", "/".$home)) { |
|
| 311 | 311 | $home_params = $params; |
| 312 | 312 | } |
| 313 | 313 | } |
@@ -332,7 +332,7 @@ discard block |
||
| 332 | 332 | $files = $this->finder->files()->in($origen)->path('/(controller|api)/i')->name("*.php"); |
| 333 | 333 | foreach ($files as $file) { |
| 334 | 334 | $filename = str_replace("/", '\\', str_replace($origen, '', $file->getPathname())); |
| 335 | - $routing = $this->addRouting($namespace . str_replace('.php', '', $filename), $routing); |
|
| 335 | + $routing = $this->addRouting($namespace.str_replace('.php', '', $filename), $routing); |
|
| 336 | 336 | } |
| 337 | 337 | $this->finder = new Finder(); |
| 338 | 338 | |
@@ -373,7 +373,7 @@ discard block |
||
| 373 | 373 | $httpMethod = $this->extractReflectionHttpMethod($docComments); |
| 374 | 374 | $visible = $this->extractReflectionVisibility($docComments); |
| 375 | 375 | $expiration = $this->extractReflectionCacheability($docComments); |
| 376 | - $routing[$httpMethod . "#|#" . $regex] = array( |
|
| 376 | + $routing[$httpMethod."#|#".$regex] = array( |
|
| 377 | 377 | "class" => $namespace, |
| 378 | 378 | "method" => $method->getName(), |
| 379 | 379 | "params" => $params, |
@@ -403,9 +403,9 @@ discard block |
||
| 403 | 403 | { |
| 404 | 404 | //Calculamos los dominios para las plantillas |
| 405 | 405 | if ($class->hasConstant("DOMAIN")) { |
| 406 | - $domain = "@" . $class->getConstant("DOMAIN") . "/"; |
|
| 407 | - $path = dirname($class->getFileName()) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR; |
|
| 408 | - $path = realpath($path) . DIRECTORY_SEPARATOR; |
|
| 406 | + $domain = "@".$class->getConstant("DOMAIN")."/"; |
|
| 407 | + $path = dirname($class->getFileName()).DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR; |
|
| 408 | + $path = realpath($path).DIRECTORY_SEPARATOR; |
|
| 409 | 409 | $tpl_path = "templates"; |
| 410 | 410 | $public_path = "public"; |
| 411 | 411 | $model_path = "models"; |
@@ -415,12 +415,12 @@ discard block |
||
| 415 | 415 | $model_path = ucfirst($model_path); |
| 416 | 416 | } |
| 417 | 417 | if ($class->hasConstant("TPL")) { |
| 418 | - $tpl_path .= DIRECTORY_SEPARATOR . $class->getConstant("TPL"); |
|
| 418 | + $tpl_path .= DIRECTORY_SEPARATOR.$class->getConstant("TPL"); |
|
| 419 | 419 | } |
| 420 | 420 | $this->domains[$domain] = array( |
| 421 | - "template" => $path . $tpl_path, |
|
| 422 | - "model" => $path . $model_path, |
|
| 423 | - "public" => $path . $public_path, |
|
| 421 | + "template" => $path.$tpl_path, |
|
| 422 | + "model" => $path.$model_path, |
|
| 423 | + "public" => $path.$public_path, |
|
| 424 | 424 | ); |
| 425 | 425 | } |
| 426 | 426 | |
@@ -433,11 +433,11 @@ discard block |
||
| 433 | 433 | */ |
| 434 | 434 | public function simpatize() |
| 435 | 435 | { |
| 436 | - $translationFileName = "translations" . DIRECTORY_SEPARATOR . "routes_translations.php"; |
|
| 437 | - $absoluteTranslationFileName = CACHE_DIR . DIRECTORY_SEPARATOR . $translationFileName; |
|
| 436 | + $translationFileName = "translations".DIRECTORY_SEPARATOR."routes_translations.php"; |
|
| 437 | + $absoluteTranslationFileName = CACHE_DIR.DIRECTORY_SEPARATOR.$translationFileName; |
|
| 438 | 438 | $this->generateSlugs($absoluteTranslationFileName); |
| 439 | 439 | Config::createDir(CONFIG_DIR); |
| 440 | - Cache::getInstance()->storeData(CONFIG_DIR . DIRECTORY_SEPARATOR . "urls.json", array($this->routing, $this->slugs), Cache::JSON, TRUE); |
|
| 440 | + Cache::getInstance()->storeData(CONFIG_DIR.DIRECTORY_SEPARATOR."urls.json", array($this->routing, $this->slugs), Cache::JSON, TRUE); |
|
| 441 | 441 | |
| 442 | 442 | return $this; |
| 443 | 443 | } |
@@ -488,16 +488,16 @@ discard block |
||
| 488 | 488 | public function getRoute($slug = '', $absolute = FALSE, $params = NULL) |
| 489 | 489 | { |
| 490 | 490 | if (strlen($slug) === 0) { |
| 491 | - return ($absolute) ? Request::getInstance()->getRootUrl() . '/' : '/'; |
|
| 491 | + return ($absolute) ? Request::getInstance()->getRootUrl().'/' : '/'; |
|
| 492 | 492 | } |
| 493 | 493 | if (NULL === $slug || !array_key_exists($slug, $this->slugs)) { |
| 494 | 494 | throw new RouterException(_("No existe la ruta especificada")); |
| 495 | 495 | } |
| 496 | - $url = ($absolute) ? Request::getInstance()->getRootUrl() . $this->slugs[$slug] : $this->slugs[$slug]; |
|
| 496 | + $url = ($absolute) ? Request::getInstance()->getRootUrl().$this->slugs[$slug] : $this->slugs[$slug]; |
|
| 497 | 497 | if (!empty($params)) foreach ($params as $key => $value) { |
| 498 | - $url = str_replace("{" . $key . "}", $value, $url); |
|
| 498 | + $url = str_replace("{".$key."}", $value, $url); |
|
| 499 | 499 | } elseif (!empty($this->routing[$this->slugs[$slug]]["default"])) { |
| 500 | - $url = ($absolute) ? Request::getInstance()->getRootUrl() . $this->routing[$this->slugs[$slug]]["default"] : $this->routing[$this->slugs[$slug]]["default"]; |
|
| 500 | + $url = ($absolute) ? Request::getInstance()->getRootUrl().$this->routing[$this->slugs[$slug]]["default"] : $this->routing[$this->slugs[$slug]]["default"]; |
|
| 501 | 501 | } |
| 502 | 502 | |
| 503 | 503 | return preg_replace('/(GET|POST|PUT|DELETE|ALL)\#\|\#/', '', $url); |
@@ -515,12 +515,12 @@ discard block |
||
| 515 | 515 | if (preg_match('/^\/admin(\/|$)/', $routePattern)) { |
| 516 | 516 | if (preg_match('/^PSFS/', $params["class"])) { |
| 517 | 517 | $profile = "superadmin"; |
| 518 | - } else { |
|
| 518 | + }else { |
|
| 519 | 519 | $profile = "admin"; |
| 520 | 520 | } |
| 521 | 521 | if (!empty($params["default"]) && preg_match('/(GET|ALL)/i', $httpMethod)) { |
| 522 | 522 | $_profile = ($params["visible"]) ? $profile : 'adminhidden'; |
| 523 | - if(!array_key_exists($_profile, $routes)) { |
|
| 523 | + if (!array_key_exists($_profile, $routes)) { |
|
| 524 | 524 | $routes[$_profile] = array(); |
| 525 | 525 | } |
| 526 | 526 | $routes[$_profile][] = $params["slug"]; |
@@ -589,7 +589,7 @@ discard block |
||
| 589 | 589 | $expr = preg_quote($expr, '/'); |
| 590 | 590 | $expr = str_replace('###', '(.*)', $expr); |
| 591 | 591 | $expr2 = preg_replace('/\(\.\*\)$/', '', $expr); |
| 592 | - $matched = preg_match('/^' . $expr . '\/?$/i', $path) || preg_match('/^' . $expr2 . '?$/i', $path); |
|
| 592 | + $matched = preg_match('/^'.$expr.'\/?$/i', $path) || preg_match('/^'.$expr2.'?$/i', $path); |
|
| 593 | 593 | return $matched; |
| 594 | 594 | } |
| 595 | 595 | |
@@ -626,9 +626,9 @@ discard block |
||
| 626 | 626 | if (count($parameters) > 0) foreach ($parameters as $param) { |
| 627 | 627 | if ($param->isOptional() && !is_array($param->getDefaultValue())) { |
| 628 | 628 | $params[$param->getName()] = $param->getDefaultValue(); |
| 629 | - $default = str_replace('{' . $param->getName() . '}', $param->getDefaultValue(), $regex); |
|
| 629 | + $default = str_replace('{'.$param->getName().'}', $param->getDefaultValue(), $regex); |
|
| 630 | 630 | } |
| 631 | - } else $default = $regex; |
|
| 631 | + }else $default = $regex; |
|
| 632 | 632 | |
| 633 | 633 | return array($regex, $default, $params); |
| 634 | 634 | } |
@@ -685,16 +685,16 @@ discard block |
||
| 685 | 685 | */ |
| 686 | 686 | protected function executeCachedRoute($route, $action, $class, $params = NULL) |
| 687 | 687 | { |
| 688 | - Logger::getInstance()->debugLog(_('Ruta resuelta para ') . $route); |
|
| 688 | + Logger::getInstance()->debugLog(_('Ruta resuelta para ').$route); |
|
| 689 | 689 | $this->session->setSessionKey("__CACHE__", $action); |
| 690 | 690 | $cache = Cache::needCache(); |
| 691 | 691 | $execute = TRUE; |
| 692 | 692 | if (FALSE !== $cache && Config::getInstance()->getDebugMode() === FALSE) { |
| 693 | 693 | $cacheDataName = $this->cache->getRequestCacheHash(); |
| 694 | - $cachedData = $this->cache->readFromCache("templates" . DIRECTORY_SEPARATOR . $cacheDataName, $cache, function () { |
|
| 694 | + $cachedData = $this->cache->readFromCache("templates".DIRECTORY_SEPARATOR.$cacheDataName, $cache, function() { |
|
| 695 | 695 | }); |
| 696 | 696 | if (NULL !== $cachedData) { |
| 697 | - $headers = $this->cache->readFromCache("templates" . DIRECTORY_SEPARATOR . $cacheDataName . ".headers", $cache, function () { |
|
| 697 | + $headers = $this->cache->readFromCache("templates".DIRECTORY_SEPARATOR.$cacheDataName.".headers", $cache, function() { |
|
| 698 | 698 | }, Cache::JSON); |
| 699 | 699 | Template::getInstance()->renderCache($cachedData, $headers); |
| 700 | 700 | $execute = FALSE; |
@@ -743,7 +743,7 @@ discard block |
||
| 743 | 743 | $translations = array(); |
| 744 | 744 | if (file_exists($absoluteTranslationFileName)) { |
| 745 | 745 | include($absoluteTranslationFileName); |
| 746 | - } else { |
|
| 746 | + }else { |
|
| 747 | 747 | Cache::getInstance()->storeData($absoluteTranslationFileName, "<?php \$translations = array();\n", Cache::TEXT, TRUE); |
| 748 | 748 | } |
| 749 | 749 | |