@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | ResponseHelper::setStatusHeader($this->status_code); |
131 | 131 | ResponseHelper::setAuthHeaders($this->public_zone); |
132 | 132 | ResponseHelper::setCookieHeaders($cookies); |
133 | - header('Content-type: ' . $contentType); |
|
133 | + header('Content-type: '.$contentType); |
|
134 | 134 | |
135 | 135 | } |
136 | 136 | |
@@ -146,14 +146,14 @@ discard block |
||
146 | 146 | Logger::log('Start output response'); |
147 | 147 | ob_start(); |
148 | 148 | $this->setReponseHeaders($contentType, $cookies); |
149 | - header('Content-length: ' . strlen($output)); |
|
149 | + header('Content-length: '.strlen($output)); |
|
150 | 150 | |
151 | 151 | $cache = Cache::needCache(); |
152 | 152 | if (false !== $cache && $this->status_code === Template::STATUS_OK && $this->debug === false) { |
153 | 153 | Logger::log('Saving output response into cache'); |
154 | 154 | $cacheName = $this->cache->getRequestCacheHash(); |
155 | - $this->cache->storeData("json" . DIRECTORY_SEPARATOR . $cacheName, $output); |
|
156 | - $this->cache->storeData("json" . DIRECTORY_SEPARATOR . $cacheName . ".headers", headers_list(), Cache::JSON); |
|
155 | + $this->cache->storeData("json".DIRECTORY_SEPARATOR.$cacheName, $output); |
|
156 | + $this->cache->storeData("json".DIRECTORY_SEPARATOR.$cacheName.".headers", headers_list(), Cache::JSON); |
|
157 | 157 | } |
158 | 158 | echo $output; |
159 | 159 | |
@@ -170,11 +170,11 @@ discard block |
||
170 | 170 | { |
171 | 171 | Logger::log('Close template render'); |
172 | 172 | Security::getInstance()->setSessionKey("lastRequest", array( |
173 | - "url" => Request::getInstance()->getRootUrl() . Request::requestUri(), |
|
173 | + "url" => Request::getInstance()->getRootUrl().Request::requestUri(), |
|
174 | 174 | "ts" => microtime(true), |
175 | 175 | )); |
176 | 176 | Security::getInstance()->updateSession(); |
177 | - Logger::log('End request: ' . Request::requestUri(), LOG_INFO); |
|
177 | + Logger::log('End request: '.Request::requestUri(), LOG_INFO); |
|
178 | 178 | exit; |
179 | 179 | } |
180 | 180 | |
@@ -223,7 +223,7 @@ discard block |
||
223 | 223 | $dump = ''; |
224 | 224 | try { |
225 | 225 | $dump = $this->tpl->render($tpl, $vars); |
226 | - } catch (\Exception $e) { |
|
226 | + }catch (\Exception $e) { |
|
227 | 227 | Logger::log($e->getMessage(), LOG_ERR); |
228 | 228 | } |
229 | 229 | return $dump; |
@@ -337,7 +337,7 @@ discard block |
||
337 | 337 | public function regenerateTemplates() |
338 | 338 | { |
339 | 339 | $this->generateTemplatesCache(); |
340 | - $domains = Cache::getInstance()->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . "domains.json", Cache::JSON, true); |
|
340 | + $domains = Cache::getInstance()->getDataFromFile(CONFIG_DIR.DIRECTORY_SEPARATOR."domains.json", Cache::JSON, true); |
|
341 | 341 | $translations = []; |
342 | 342 | if (is_array($domains)) { |
343 | 343 | $translations = $this->parsePathTranslations($domains); |
@@ -359,8 +359,8 @@ discard block |
||
359 | 359 | // force compilation |
360 | 360 | if ($file->isFile()) { |
361 | 361 | try { |
362 | - $this->tpl->load(str_replace($tplDir . '/', '', $file)); |
|
363 | - } catch (\Exception $e) { |
|
362 | + $this->tpl->load(str_replace($tplDir.'/', '', $file)); |
|
363 | + }catch (\Exception $e) { |
|
364 | 364 | Logger::log($e->getMessage(), LOG_ERR, ['file' => $e->getFile(), 'line' => $e->getLine()]); |
365 | 365 | } |
366 | 366 | } |
@@ -434,9 +434,9 @@ discard block |
||
434 | 434 | */ |
435 | 435 | private function loadDomains() |
436 | 436 | { |
437 | - $domains = Cache::getInstance()->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . 'domains.json', Cache::JSON, true); |
|
438 | - if(null !== $domains) { |
|
439 | - foreach($domains as $domain => $paths) { |
|
437 | + $domains = Cache::getInstance()->getDataFromFile(CONFIG_DIR.DIRECTORY_SEPARATOR.'domains.json', Cache::JSON, true); |
|
438 | + if (null !== $domains) { |
|
439 | + foreach ($domains as $domain => $paths) { |
|
440 | 440 | $this->addPath($paths['template'], preg_replace('/(@|\/)/', '', $domain)); |
441 | 441 | } |
442 | 442 | } |
@@ -451,7 +451,7 @@ discard block |
||
451 | 451 | $this->cache = Cache::getInstance(); |
452 | 452 | $loader = new \Twig_Loader_Filesystem(Config::getInstance()->getTemplatePath()); |
453 | 453 | $this->tpl = new \Twig_Environment($loader, array( |
454 | - 'cache' => Config::getInstance()->getCachePath() . DIRECTORY_SEPARATOR . 'twig', |
|
454 | + 'cache' => Config::getInstance()->getCachePath().DIRECTORY_SEPARATOR.'twig', |
|
455 | 455 | 'debug' => (bool)$this->debug, |
456 | 456 | 'auto_reload' => Config::getParam('twig.auto_reload', TRUE), |
457 | 457 | )); |
@@ -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 | Logger::log('Not found page throwed without previous exception', LOG_WARNING); |
90 | 90 | $e = new \Exception(_('Page not found'), 404); |
@@ -113,8 +113,8 @@ discard block |
||
113 | 113 | */ |
114 | 114 | public function getAllRoutes() { |
115 | 115 | $routes = []; |
116 | - foreach($this->routing as $path => $route) { |
|
117 | - if(array_key_exists('slug', $route)) { |
|
116 | + foreach ($this->routing as $path => $route) { |
|
117 | + if (array_key_exists('slug', $route)) { |
|
118 | 118 | $routes[$route['slug']] = $path; |
119 | 119 | } |
120 | 120 | } |
@@ -139,15 +139,15 @@ discard block |
||
139 | 139 | SecurityHelper::checkRestrictedAccess($route); |
140 | 140 | //Search action and execute |
141 | 141 | $this->searchAction($route); |
142 | - } catch (AccessDeniedException $e) { |
|
142 | + }catch (AccessDeniedException $e) { |
|
143 | 143 | Logger::log(_('Solicitamos credenciales de acceso a zona restringida')); |
144 | 144 | return Admin::staticAdminLogon($route); |
145 | - } catch (RouterException $r) { |
|
146 | - if(null === RouterHelper::checkDefaultRoute($route)) { |
|
145 | + }catch (RouterException $r) { |
|
146 | + if (null === RouterHelper::checkDefaultRoute($route)) { |
|
147 | 147 | Logger::log($r->getMessage(), LOG_WARNING); |
148 | 148 | throw $r; |
149 | 149 | } |
150 | - } catch (\Exception $e) { |
|
150 | + }catch (\Exception $e) { |
|
151 | 151 | Logger::log($e->getMessage(), LOG_ERR); |
152 | 152 | throw $e; |
153 | 153 | } |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | */ |
165 | 165 | protected function searchAction($route) |
166 | 166 | { |
167 | - Logger::log('Searching action to execute: ' . $route, LOG_INFO); |
|
167 | + Logger::log('Searching action to execute: '.$route, LOG_INFO); |
|
168 | 168 | //Revisamos si tenemos la ruta registrada |
169 | 169 | $parts = parse_url($route); |
170 | 170 | $path = (array_key_exists('path', $parts)) ? $parts['path'] : $route; |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | $class = RouterHelper::getClassToCall($action); |
179 | 179 | try { |
180 | 180 | $this->executeCachedRoute($route, $action, $class, $get); |
181 | - } catch (\Exception $e) { |
|
181 | + }catch (\Exception $e) { |
|
182 | 182 | Logger::log($e->getMessage(), LOG_ERR); |
183 | 183 | throw new RouterException($e->getMessage(), 404, $e); |
184 | 184 | } |
@@ -206,13 +206,13 @@ discard block |
||
206 | 206 | $this->routing = $this->inspectDir($base, "PSFS", array()); |
207 | 207 | if (file_exists($modules)) { |
208 | 208 | $module = ""; |
209 | - if(file_exists($modules . DIRECTORY_SEPARATOR . 'module.json')) { |
|
210 | - $mod_cfg = json_decode(file_get_contents($modules . DIRECTORY_SEPARATOR . 'module.json'), true); |
|
209 | + if (file_exists($modules.DIRECTORY_SEPARATOR.'module.json')) { |
|
210 | + $mod_cfg = json_decode(file_get_contents($modules.DIRECTORY_SEPARATOR.'module.json'), true); |
|
211 | 211 | $module = $mod_cfg['module']; |
212 | 212 | } |
213 | 213 | $this->routing = $this->inspectDir($modules, $module, $this->routing); |
214 | 214 | } |
215 | - $this->cache->storeData(CONFIG_DIR . DIRECTORY_SEPARATOR . "domains.json", $this->domains, Cache::JSON, TRUE); |
|
215 | + $this->cache->storeData(CONFIG_DIR.DIRECTORY_SEPARATOR."domains.json", $this->domains, Cache::JSON, TRUE); |
|
216 | 216 | } |
217 | 217 | |
218 | 218 | /** |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | $home_params = NULL; |
228 | 228 | foreach ($this->routing as $pattern => $params) { |
229 | 229 | list($method, $route) = RouterHelper::extractHttpRoute($pattern); |
230 | - if (preg_match("/" . preg_quote($route, "/") . "$/i", "/" . $home)) { |
|
230 | + if (preg_match("/".preg_quote($route, "/")."$/i", "/".$home)) { |
|
231 | 231 | $home_params = $params; |
232 | 232 | } |
233 | 233 | } |
@@ -252,7 +252,7 @@ discard block |
||
252 | 252 | $files = $this->finder->files()->in($origen)->path('/(controller|api)/i')->name("*.php"); |
253 | 253 | foreach ($files as $file) { |
254 | 254 | $filename = str_replace("/", '\\', str_replace($origen, '', $file->getPathname())); |
255 | - $routing = $this->addRouting($namespace . str_replace('.php', '', $filename), $routing); |
|
255 | + $routing = $this->addRouting($namespace.str_replace('.php', '', $filename), $routing); |
|
256 | 256 | } |
257 | 257 | $this->finder = new Finder(); |
258 | 258 | |
@@ -291,7 +291,7 @@ discard block |
||
291 | 291 | } |
292 | 292 | foreach ($reflection->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) { |
293 | 293 | list($route, $info) = RouterHelper::extractRouteInfo($method, $api); |
294 | - if(null !== $route && null !== $info) { |
|
294 | + if (null !== $route && null !== $info) { |
|
295 | 295 | $info['class'] = $namespace; |
296 | 296 | $routing[$route] = $info; |
297 | 297 | } |
@@ -314,11 +314,11 @@ discard block |
||
314 | 314 | { |
315 | 315 | //Calculamos los dominios para las plantillas |
316 | 316 | if ($class->hasConstant("DOMAIN") && !$class->isAbstract()) { |
317 | - if(!$this->domains) { |
|
317 | + if (!$this->domains) { |
|
318 | 318 | $this->domains = []; |
319 | 319 | } |
320 | - $domain = "@" . $class->getConstant("DOMAIN") . "/"; |
|
321 | - if(!array_key_exists($domain, $this->domains)) { |
|
320 | + $domain = "@".$class->getConstant("DOMAIN")."/"; |
|
321 | + if (!array_key_exists($domain, $this->domains)) { |
|
322 | 322 | $this->domains[$domain] = RouterHelper::extractDomainInfo($class, $domain); |
323 | 323 | } |
324 | 324 | } |
@@ -332,11 +332,11 @@ discard block |
||
332 | 332 | */ |
333 | 333 | public function simpatize() |
334 | 334 | { |
335 | - $translationFileName = "translations" . DIRECTORY_SEPARATOR . "routes_translations.php"; |
|
336 | - $absoluteTranslationFileName = CACHE_DIR . DIRECTORY_SEPARATOR . $translationFileName; |
|
335 | + $translationFileName = "translations".DIRECTORY_SEPARATOR."routes_translations.php"; |
|
336 | + $absoluteTranslationFileName = CACHE_DIR.DIRECTORY_SEPARATOR.$translationFileName; |
|
337 | 337 | $this->generateSlugs($absoluteTranslationFileName); |
338 | 338 | Config::createDir(CONFIG_DIR); |
339 | - Cache::getInstance()->storeData(CONFIG_DIR . DIRECTORY_SEPARATOR . "urls.json", array($this->routing, $this->slugs), Cache::JSON, TRUE); |
|
339 | + Cache::getInstance()->storeData(CONFIG_DIR.DIRECTORY_SEPARATOR."urls.json", array($this->routing, $this->slugs), Cache::JSON, TRUE); |
|
340 | 340 | |
341 | 341 | return $this; |
342 | 342 | } |
@@ -354,16 +354,16 @@ discard block |
||
354 | 354 | public function getRoute($slug = '', $absolute = FALSE, $params = []) |
355 | 355 | { |
356 | 356 | if (strlen($slug) === 0) { |
357 | - return ($absolute) ? Request::getInstance()->getRootUrl() . '/' : '/'; |
|
357 | + return ($absolute) ? Request::getInstance()->getRootUrl().'/' : '/'; |
|
358 | 358 | } |
359 | 359 | if (NULL === $slug || !array_key_exists($slug, $this->slugs)) { |
360 | 360 | throw new RouterException(_("No existe la ruta especificada")); |
361 | 361 | } |
362 | - $url = ($absolute) ? Request::getInstance()->getRootUrl() . $this->slugs[$slug] : $this->slugs[$slug]; |
|
362 | + $url = ($absolute) ? Request::getInstance()->getRootUrl().$this->slugs[$slug] : $this->slugs[$slug]; |
|
363 | 363 | if (!empty($params)) foreach ($params as $key => $value) { |
364 | - $url = str_replace("{" . $key . "}", $value, $url); |
|
364 | + $url = str_replace("{".$key."}", $value, $url); |
|
365 | 365 | } elseif (!empty($this->routing[$this->slugs[$slug]]["default"])) { |
366 | - $url = ($absolute) ? Request::getInstance()->getRootUrl() . $this->routing[$this->slugs[$slug]]["default"] : $this->routing[$this->slugs[$slug]]["default"]; |
|
366 | + $url = ($absolute) ? Request::getInstance()->getRootUrl().$this->routing[$this->slugs[$slug]]["default"] : $this->routing[$this->slugs[$slug]]["default"]; |
|
367 | 367 | } |
368 | 368 | |
369 | 369 | return preg_replace('/(GET|POST|PUT|DELETE|ALL)\#\|\#/', '', $url); |
@@ -406,17 +406,17 @@ discard block |
||
406 | 406 | */ |
407 | 407 | protected function executeCachedRoute($route, $action, $class, $params = NULL) |
408 | 408 | { |
409 | - Logger::log('Executing route ' . $route, LOG_INFO); |
|
409 | + Logger::log('Executing route '.$route, LOG_INFO); |
|
410 | 410 | Security::getInstance()->setSessionKey("__CACHE__", $action); |
411 | 411 | $cache = Cache::needCache(); |
412 | 412 | $execute = TRUE; |
413 | 413 | if (FALSE !== $cache && Config::getInstance()->getDebugMode() === FALSE) { |
414 | 414 | $cacheDataName = $this->cache->getRequestCacheHash(); |
415 | - $cachedData = $this->cache->readFromCache("templates" . DIRECTORY_SEPARATOR . $cacheDataName, |
|
416 | - $cache, function () {}); |
|
415 | + $cachedData = $this->cache->readFromCache("templates".DIRECTORY_SEPARATOR.$cacheDataName, |
|
416 | + $cache, function() {}); |
|
417 | 417 | if (NULL !== $cachedData) { |
418 | - $headers = $this->cache->readFromCache("templates" . DIRECTORY_SEPARATOR . $cacheDataName . ".headers", |
|
419 | - $cache, function () {}, Cache::JSON); |
|
418 | + $headers = $this->cache->readFromCache("templates".DIRECTORY_SEPARATOR.$cacheDataName.".headers", |
|
419 | + $cache, function() {}, Cache::JSON); |
|
420 | 420 | Template::getInstance()->renderCache($cachedData, $headers); |
421 | 421 | $execute = FALSE; |
422 | 422 | } |