@@ -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"); |
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 | } |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | $class = $this->getClassToCall($action); |
196 | 196 | try { |
197 | 197 | return $this->executeCachedRoute($route, $action, $class, $get); |
198 | - } catch (\Exception $e) { |
|
198 | + }catch (\Exception $e) { |
|
199 | 199 | Logger::getInstance()->debugLog($e->getMessage(), array($e->getFile(), $e->getLine())); |
200 | 200 | throw new RouterException($e->getMessage(), 404, $e); |
201 | 201 | } |
@@ -283,13 +283,13 @@ discard block |
||
283 | 283 | if (file_exists($modules)) { |
284 | 284 | $this->routing = $this->inspectDir($modules, "", $this->routing); |
285 | 285 | } |
286 | - $this->cache->storeData(CONFIG_DIR . DIRECTORY_SEPARATOR . "domains.json", $this->domains, Cache::JSON, TRUE); |
|
286 | + $this->cache->storeData(CONFIG_DIR.DIRECTORY_SEPARATOR."domains.json", $this->domains, Cache::JSON, TRUE); |
|
287 | 287 | $home = Config::getInstance()->get('home_action'); |
288 | 288 | if (NULL !== $home || $home !== '') { |
289 | 289 | $home_params = NULL; |
290 | 290 | foreach ($this->routing as $pattern => $params) { |
291 | 291 | list($method, $route) = $this->extractHttpRoute($pattern); |
292 | - if (preg_match("/" . preg_quote($route, "/") . "$/i", "/" . $home)) { |
|
292 | + if (preg_match("/".preg_quote($route, "/")."$/i", "/".$home)) { |
|
293 | 293 | $home_params = $params; |
294 | 294 | } |
295 | 295 | } |
@@ -314,7 +314,7 @@ discard block |
||
314 | 314 | $files = $this->finder->files()->in($origen)->path('/(controller|api)/i')->name("*.php"); |
315 | 315 | foreach ($files as $file) { |
316 | 316 | $filename = str_replace("/", '\\', str_replace($origen, '', $file->getPathname())); |
317 | - $routing = $this->addRouting($namespace . str_replace('.php', '', $filename), $routing); |
|
317 | + $routing = $this->addRouting($namespace.str_replace('.php', '', $filename), $routing); |
|
318 | 318 | } |
319 | 319 | $this->finder = new Finder(); |
320 | 320 | |
@@ -355,7 +355,7 @@ discard block |
||
355 | 355 | $httpMethod = $this->extractReflectionHttpMethod($docComments); |
356 | 356 | $visible = $this->extractReflectionVisibility($docComments); |
357 | 357 | $expiration = $this->extractReflectionCacheability($docComments); |
358 | - $routing[$httpMethod . "#|#" . $regex] = array( |
|
358 | + $routing[$httpMethod."#|#".$regex] = array( |
|
359 | 359 | "class" => $namespace, |
360 | 360 | "method" => $method->getName(), |
361 | 361 | "params" => $params, |
@@ -385,9 +385,9 @@ discard block |
||
385 | 385 | { |
386 | 386 | //Calculamos los dominios para las plantillas |
387 | 387 | if ($class->hasConstant("DOMAIN")) { |
388 | - $domain = "@" . $class->getConstant("DOMAIN") . "/"; |
|
389 | - $path = dirname($class->getFileName()) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR; |
|
390 | - $path = realpath($path) . DIRECTORY_SEPARATOR; |
|
388 | + $domain = "@".$class->getConstant("DOMAIN")."/"; |
|
389 | + $path = dirname($class->getFileName()).DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR; |
|
390 | + $path = realpath($path).DIRECTORY_SEPARATOR; |
|
391 | 391 | $tpl_path = "templates"; |
392 | 392 | $public_path = "public"; |
393 | 393 | $model_path = "models"; |
@@ -397,12 +397,12 @@ discard block |
||
397 | 397 | $model_path = ucfirst($model_path); |
398 | 398 | } |
399 | 399 | if ($class->hasConstant("TPL")) { |
400 | - $tpl_path .= DIRECTORY_SEPARATOR . $class->getConstant("TPL"); |
|
400 | + $tpl_path .= DIRECTORY_SEPARATOR.$class->getConstant("TPL"); |
|
401 | 401 | } |
402 | 402 | $this->domains[$domain] = array( |
403 | - "template" => $path . $tpl_path, |
|
404 | - "model" => $path . $model_path, |
|
405 | - "public" => $path . $public_path, |
|
403 | + "template" => $path.$tpl_path, |
|
404 | + "model" => $path.$model_path, |
|
405 | + "public" => $path.$public_path, |
|
406 | 406 | ); |
407 | 407 | } |
408 | 408 | |
@@ -415,11 +415,11 @@ discard block |
||
415 | 415 | */ |
416 | 416 | private 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 | Config::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 | } |
@@ -470,16 +470,16 @@ discard block |
||
470 | 470 | public function getRoute($slug = '', $absolute = FALSE, $params = NULL) |
471 | 471 | { |
472 | 472 | if (strlen($slug) === 0) { |
473 | - return ($absolute) ? Request::getInstance()->getRootUrl() . '/' : '/'; |
|
473 | + return ($absolute) ? Request::getInstance()->getRootUrl().'/' : '/'; |
|
474 | 474 | } |
475 | 475 | if (NULL === $slug || !array_key_exists($slug, $this->slugs)) { |
476 | 476 | throw new RouterException(_("No existe la ruta especificada")); |
477 | 477 | } |
478 | - $url = ($absolute) ? Request::getInstance()->getRootUrl() . $this->slugs[$slug] : $this->slugs[$slug]; |
|
478 | + $url = ($absolute) ? Request::getInstance()->getRootUrl().$this->slugs[$slug] : $this->slugs[$slug]; |
|
479 | 479 | if (!empty($params)) foreach ($params as $key => $value) { |
480 | - $url = str_replace("{" . $key . "}", $value, $url); |
|
480 | + $url = str_replace("{".$key."}", $value, $url); |
|
481 | 481 | } elseif (!empty($this->routing[$this->slugs[$slug]]["default"])) { |
482 | - $url = ($absolute) ? Request::getInstance()->getRootUrl() . $this->routing[$this->slugs[$slug]]["default"] : $this->routing[$this->slugs[$slug]]["default"]; |
|
482 | + $url = ($absolute) ? Request::getInstance()->getRootUrl().$this->routing[$this->slugs[$slug]]["default"] : $this->routing[$this->slugs[$slug]]["default"]; |
|
483 | 483 | } |
484 | 484 | |
485 | 485 | return preg_replace('/(GET|POST|PUT|DELETE|ALL)\#\|\#/', '', $url); |
@@ -497,12 +497,12 @@ discard block |
||
497 | 497 | if (preg_match('/^\/admin(\/|$)/', $routePattern)) { |
498 | 498 | if (preg_match('/^PSFS/', $params["class"])) { |
499 | 499 | $profile = "superadmin"; |
500 | - } else { |
|
500 | + }else { |
|
501 | 501 | $profile = "admin"; |
502 | 502 | } |
503 | 503 | if (!empty($params["default"]) && preg_match('/(GET|ALL)/i', $httpMethod)) { |
504 | 504 | $_profile = ($params["visible"]) ? $profile : 'adminhidden'; |
505 | - if(!array_key_exists($_profile, $routes)) { |
|
505 | + if (!array_key_exists($_profile, $routes)) { |
|
506 | 506 | $routes[$_profile] = array(); |
507 | 507 | } |
508 | 508 | $routes[$_profile][] = $params["slug"]; |
@@ -571,7 +571,7 @@ discard block |
||
571 | 571 | $expr = preg_quote($expr, '/'); |
572 | 572 | $expr = str_replace('###', '(.*)', $expr); |
573 | 573 | $expr2 = preg_replace('/\(\.\*\)$/', '', $expr); |
574 | - $matched = preg_match('/^' . $expr . '\/?$/i', $path) || preg_match('/^' . $expr2 . '?$/i', $path); |
|
574 | + $matched = preg_match('/^'.$expr.'\/?$/i', $path) || preg_match('/^'.$expr2.'?$/i', $path); |
|
575 | 575 | |
576 | 576 | return $matched; |
577 | 577 | } |
@@ -609,9 +609,9 @@ discard block |
||
609 | 609 | if (count($parameters) > 0) foreach ($parameters as $param) { |
610 | 610 | if ($param->isOptional() && !is_array($param->getDefaultValue())) { |
611 | 611 | $params[$param->getName()] = $param->getDefaultValue(); |
612 | - $default = str_replace('{' . $param->getName() . '}', $param->getDefaultValue(), $regex); |
|
612 | + $default = str_replace('{'.$param->getName().'}', $param->getDefaultValue(), $regex); |
|
613 | 613 | } |
614 | - } else $default = $regex; |
|
614 | + }else $default = $regex; |
|
615 | 615 | |
616 | 616 | return array($regex, $default, $params); |
617 | 617 | } |
@@ -668,16 +668,16 @@ discard block |
||
668 | 668 | */ |
669 | 669 | protected function executeCachedRoute($route, $action, $class, $params = NULL) |
670 | 670 | { |
671 | - Logger::getInstance()->debugLog(_('Ruta resuelta para ') . $route); |
|
671 | + Logger::getInstance()->debugLog(_('Ruta resuelta para ').$route); |
|
672 | 672 | $this->session->setSessionKey("__CACHE__", $action); |
673 | 673 | $cache = Cache::needCache(); |
674 | 674 | $execute = TRUE; |
675 | 675 | if (FALSE !== $cache && Config::getInstance()->getDebugMode() === FALSE) { |
676 | 676 | $cacheDataName = $this->cache->getRequestCacheHash(); |
677 | - $cachedData = $this->cache->readFromCache("templates" . DIRECTORY_SEPARATOR . $cacheDataName, $cache, function () { |
|
677 | + $cachedData = $this->cache->readFromCache("templates".DIRECTORY_SEPARATOR.$cacheDataName, $cache, function() { |
|
678 | 678 | }); |
679 | 679 | if (NULL !== $cachedData) { |
680 | - $headers = $this->cache->readFromCache("templates" . DIRECTORY_SEPARATOR . $cacheDataName . ".headers", $cache, function () { |
|
680 | + $headers = $this->cache->readFromCache("templates".DIRECTORY_SEPARATOR.$cacheDataName.".headers", $cache, function() { |
|
681 | 681 | }, Cache::JSON); |
682 | 682 | Template::getInstance()->renderCache($cachedData, $headers); |
683 | 683 | $execute = FALSE; |
@@ -726,7 +726,7 @@ discard block |
||
726 | 726 | $translations = array(); |
727 | 727 | if (file_exists($absoluteTranslationFileName)) { |
728 | 728 | include($absoluteTranslationFileName); |
729 | - } else { |
|
729 | + }else { |
|
730 | 730 | Cache::getInstance()->storeData($absoluteTranslationFileName, "<?php \$translations = array();\n", Cache::TEXT, TRUE); |
731 | 731 | } |
732 | 732 |