@@ -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; |
@@ -245,7 +245,7 @@ discard block |
||
| 245 | 245 | */ |
| 246 | 246 | private function getExternalModules() { |
| 247 | 247 | $externalModules = Config::getParam('modules.extend', ''); |
| 248 | - if(Config::getParam('psfs.auth', false)) { |
|
| 248 | + if (Config::getParam('psfs.auth', false)) { |
|
| 249 | 249 | $externalModules .= ',psfs/auth'; |
| 250 | 250 | } |
| 251 | 251 | return $externalModules; |
@@ -279,10 +279,10 @@ discard block |
||
| 279 | 279 | $modules = $this->finder->directories()->in($modulesPath)->depth(0); |
| 280 | 280 | foreach ($modules as $modulePath) { |
| 281 | 281 | $module = $modulePath->getBasename(); |
| 282 | - $this->routing = $this->inspectDir($modulesPath . DIRECTORY_SEPARATOR . $module, $module, $this->routing); |
|
| 282 | + $this->routing = $this->inspectDir($modulesPath.DIRECTORY_SEPARATOR.$module, $module, $this->routing); |
|
| 283 | 283 | } |
| 284 | 284 | } |
| 285 | - $this->cache->storeData(CONFIG_DIR . DIRECTORY_SEPARATOR . "domains.json", $this->domains, Cache::JSON, TRUE); |
|
| 285 | + $this->cache->storeData(CONFIG_DIR.DIRECTORY_SEPARATOR."domains.json", $this->domains, Cache::JSON, TRUE); |
|
| 286 | 286 | } |
| 287 | 287 | |
| 288 | 288 | /** |
@@ -297,7 +297,7 @@ discard block |
||
| 297 | 297 | $home_params = NULL; |
| 298 | 298 | foreach ($this->routing as $pattern => $params) { |
| 299 | 299 | list($method, $route) = RouterHelper::extractHttpRoute($pattern); |
| 300 | - if (preg_match("/" . preg_quote($route, "/") . "$/i", "/" . $home)) { |
|
| 300 | + if (preg_match("/".preg_quote($route, "/")."$/i", "/".$home)) { |
|
| 301 | 301 | $home_params = $params; |
| 302 | 302 | } |
| 303 | 303 | } |
@@ -322,7 +322,7 @@ discard block |
||
| 322 | 322 | $files = $this->finder->files()->in($origen)->path('/(controller|api)/i')->depth(1)->name("*.php"); |
| 323 | 323 | foreach ($files as $file) { |
| 324 | 324 | $filename = str_replace("/", '\\', str_replace($origen, '', $file->getPathname())); |
| 325 | - $routing = $this->addRouting($namespace . str_replace('.php', '', $filename), $routing, $namespace); |
|
| 325 | + $routing = $this->addRouting($namespace.str_replace('.php', '', $filename), $routing, $namespace); |
|
| 326 | 326 | } |
| 327 | 327 | $this->finder = new Finder(); |
| 328 | 328 | |
@@ -352,7 +352,7 @@ discard block |
||
| 352 | 352 | private function addRouting($namespace, &$routing, $module = 'PSFS') |
| 353 | 353 | { |
| 354 | 354 | if (self::exists($namespace)) { |
| 355 | - if(I18nHelper::checkI18Class($namespace)) { |
|
| 355 | + if (I18nHelper::checkI18Class($namespace)) { |
|
| 356 | 356 | return $routing; |
| 357 | 357 | } |
| 358 | 358 | $reflection = new \ReflectionClass($namespace); |
@@ -395,7 +395,7 @@ discard block |
||
| 395 | 395 | if (!$this->domains) { |
| 396 | 396 | $this->domains = []; |
| 397 | 397 | } |
| 398 | - $domain = "@" . $class->getConstant("DOMAIN") . "/"; |
|
| 398 | + $domain = "@".$class->getConstant("DOMAIN")."/"; |
|
| 399 | 399 | if (!array_key_exists($domain, $this->domains)) { |
| 400 | 400 | $this->domains[$domain] = RouterHelper::extractDomainInfo($class, $domain); |
| 401 | 401 | } |
@@ -410,11 +410,11 @@ discard block |
||
| 410 | 410 | */ |
| 411 | 411 | public function simpatize() |
| 412 | 412 | { |
| 413 | - $translationFileName = "translations" . DIRECTORY_SEPARATOR . "routes_translations.php"; |
|
| 414 | - $absoluteTranslationFileName = CACHE_DIR . DIRECTORY_SEPARATOR . $translationFileName; |
|
| 413 | + $translationFileName = "translations".DIRECTORY_SEPARATOR."routes_translations.php"; |
|
| 414 | + $absoluteTranslationFileName = CACHE_DIR.DIRECTORY_SEPARATOR.$translationFileName; |
|
| 415 | 415 | $this->generateSlugs($absoluteTranslationFileName); |
| 416 | 416 | GeneratorHelper::createDir(CONFIG_DIR); |
| 417 | - Cache::getInstance()->storeData(CONFIG_DIR . DIRECTORY_SEPARATOR . "urls.json", array($this->routing, $this->slugs), Cache::JSON, TRUE); |
|
| 417 | + Cache::getInstance()->storeData(CONFIG_DIR.DIRECTORY_SEPARATOR."urls.json", array($this->routing, $this->slugs), Cache::JSON, TRUE); |
|
| 418 | 418 | |
| 419 | 419 | return $this; |
| 420 | 420 | } |
@@ -432,16 +432,16 @@ discard block |
||
| 432 | 432 | public function getRoute($slug = '', $absolute = FALSE, $params = []) |
| 433 | 433 | { |
| 434 | 434 | if (strlen($slug) === 0) { |
| 435 | - return ($absolute) ? Request::getInstance()->getRootUrl() . '/' : '/'; |
|
| 435 | + return ($absolute) ? Request::getInstance()->getRootUrl().'/' : '/'; |
|
| 436 | 436 | } |
| 437 | 437 | if (!is_array($this->slugs) || !array_key_exists($slug, $this->slugs)) { |
| 438 | 438 | throw new RouterException(_("No existe la ruta especificada")); |
| 439 | 439 | } |
| 440 | - $url = ($absolute) ? Request::getInstance()->getRootUrl() . $this->slugs[$slug] : $this->slugs[$slug]; |
|
| 440 | + $url = ($absolute) ? Request::getInstance()->getRootUrl().$this->slugs[$slug] : $this->slugs[$slug]; |
|
| 441 | 441 | if (!empty($params)) foreach ($params as $key => $value) { |
| 442 | - $url = str_replace("{" . $key . "}", $value, $url); |
|
| 442 | + $url = str_replace("{".$key."}", $value, $url); |
|
| 443 | 443 | } elseif (!empty($this->routing[$this->slugs[$slug]]["default"])) { |
| 444 | - $url = ($absolute) ? Request::getInstance()->getRootUrl() . $this->routing[$this->slugs[$slug]]["default"] : $this->routing[$this->slugs[$slug]]["default"]; |
|
| 444 | + $url = ($absolute) ? Request::getInstance()->getRootUrl().$this->routing[$this->slugs[$slug]]["default"] : $this->routing[$this->slugs[$slug]]["default"]; |
|
| 445 | 445 | } |
| 446 | 446 | |
| 447 | 447 | return preg_replace('/(GET|POST|PUT|DELETE|ALL)\#\|\#/', '', $url); |
@@ -486,17 +486,17 @@ discard block |
||
| 486 | 486 | */ |
| 487 | 487 | protected function executeCachedRoute($route, $action, $class, $params = NULL) |
| 488 | 488 | { |
| 489 | - Logger::log('Executing route ' . $route, LOG_INFO); |
|
| 489 | + Logger::log('Executing route '.$route, LOG_INFO); |
|
| 490 | 490 | $action['params'] = array_merge($action['params'], $params, Request::getInstance()->getQueryParams()); |
| 491 | 491 | Security::getInstance()->setSessionKey("__CACHE__", $action); |
| 492 | 492 | $cache = Cache::needCache(); |
| 493 | 493 | $execute = TRUE; |
| 494 | 494 | if (FALSE !== $cache && Config::getParam('debug') === FALSE && $action['http'] === 'GET') { |
| 495 | 495 | list($path, $cacheDataName) = $this->cache->getRequestCacheHash(); |
| 496 | - $cachedData = $this->cache->readFromCache("json" . DIRECTORY_SEPARATOR . $path . $cacheDataName, |
|
| 496 | + $cachedData = $this->cache->readFromCache("json".DIRECTORY_SEPARATOR.$path.$cacheDataName, |
|
| 497 | 497 | $cache, null); |
| 498 | 498 | if (NULL !== $cachedData) { |
| 499 | - $headers = $this->cache->readFromCache("json" . DIRECTORY_SEPARATOR . $path . $cacheDataName . ".headers", |
|
| 499 | + $headers = $this->cache->readFromCache("json".DIRECTORY_SEPARATOR.$path.$cacheDataName.".headers", |
|
| 500 | 500 | $cache, null, Cache::JSON); |
| 501 | 501 | Template::getInstance()->renderCache($cachedData, $headers); |
| 502 | 502 | $execute = FALSE; |
@@ -539,10 +539,10 @@ discard block |
||
| 539 | 539 | private function loadExternalAutoloader($hydrateRoute, SplFileInfo $modulePath, $externalModulePath) |
| 540 | 540 | { |
| 541 | 541 | $extModule = $modulePath->getBasename(); |
| 542 | - $moduleAutoloader = realpath($externalModulePath . DIRECTORY_SEPARATOR . $extModule . DIRECTORY_SEPARATOR . 'autoload.php'); |
|
| 542 | + $moduleAutoloader = realpath($externalModulePath.DIRECTORY_SEPARATOR.$extModule.DIRECTORY_SEPARATOR.'autoload.php'); |
|
| 543 | 543 | @include $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 | |
@@ -555,12 +555,12 @@ discard block |
||
| 555 | 555 | { |
| 556 | 556 | try { |
| 557 | 557 | $module = preg_replace('/(\\\|\/)/', DIRECTORY_SEPARATOR, $module); |
| 558 | - $externalModulePath = VENDOR_DIR . DIRECTORY_SEPARATOR . $module . DIRECTORY_SEPARATOR . 'src'; |
|
| 558 | + $externalModulePath = VENDOR_DIR.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.'src'; |
|
| 559 | 559 | $externalModule = $this->finder->directories()->in($externalModulePath)->depth(0); |
| 560 | 560 | foreach ($externalModule as $modulePath) { |
| 561 | 561 | $this->loadExternalAutoloader($hydrateRoute, $modulePath, $externalModulePath); |
| 562 | 562 | } |
| 563 | - } catch (\Exception $e) { |
|
| 563 | + }catch (\Exception $e) { |
|
| 564 | 564 | Logger::log($e->getMessage(), LOG_WARNING); |
| 565 | 565 | $module = null; |
| 566 | 566 | } |
@@ -30,21 +30,21 @@ discard block |
||
| 30 | 30 | list($BrowserLocales[$i]) = explode(";", $BrowserLocales[$i]); //trick for "en;q=0.8" |
| 31 | 31 | } |
| 32 | 32 | $locale = array_shift($BrowserLocales); |
| 33 | - } else { |
|
| 33 | + }else { |
|
| 34 | 34 | $locale = strtolower($locale); |
| 35 | 35 | } |
| 36 | 36 | if (false !== strpos($locale, '_')) { |
| 37 | 37 | $locale = explode('_', $locale); |
| 38 | 38 | if ($locale[0] == 'en') { |
| 39 | - $locale = $locale[0] . '_GB'; |
|
| 40 | - } else { |
|
| 41 | - $locale = $locale[0] . '_' . strtoupper($locale[1]); |
|
| 39 | + $locale = $locale[0].'_GB'; |
|
| 40 | + }else { |
|
| 41 | + $locale = $locale[0].'_'.strtoupper($locale[1]); |
|
| 42 | 42 | } |
| 43 | - } else { |
|
| 43 | + }else { |
|
| 44 | 44 | if (strtolower($locale) === 'en') { |
| 45 | 45 | $locale = 'en_GB'; |
| 46 | - } else { |
|
| 47 | - $locale = $locale . '_' . strtoupper($locale); |
|
| 46 | + }else { |
|
| 47 | + $locale = $locale.'_'.strtoupper($locale); |
|
| 48 | 48 | } |
| 49 | 49 | } |
| 50 | 50 | if (!in_array($locale, self::$langs)) { |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | $translations = array(); |
| 66 | 66 | if (file_exists($absoluteTranslationFileName)) { |
| 67 | 67 | @include($absoluteTranslationFileName); |
| 68 | - } else { |
|
| 68 | + }else { |
|
| 69 | 69 | Cache::getInstance()->storeData($absoluteTranslationFileName, "<?php \$translations = array();\n", Cache::TEXT, TRUE); |
| 70 | 70 | } |
| 71 | 71 | |
@@ -78,13 +78,13 @@ discard block |
||
| 78 | 78 | public static function setLocale() |
| 79 | 79 | { |
| 80 | 80 | $locale = self::extractLocale('es_ES'); |
| 81 | - Logger::log('Set locale to project [' . $locale . ']'); |
|
| 81 | + Logger::log('Set locale to project ['.$locale.']'); |
|
| 82 | 82 | // Load translations |
| 83 | - putenv("LC_ALL=" . $locale); |
|
| 83 | + putenv("LC_ALL=".$locale); |
|
| 84 | 84 | setlocale(LC_ALL, $locale); |
| 85 | 85 | // Load the locale path |
| 86 | - $locale_path = BASE_DIR . DIRECTORY_SEPARATOR . 'locale'; |
|
| 87 | - Logger::log('Set locale dir ' . $locale_path); |
|
| 86 | + $locale_path = BASE_DIR.DIRECTORY_SEPARATOR.'locale'; |
|
| 87 | + Logger::log('Set locale dir '.$locale_path); |
|
| 88 | 88 | GeneratorHelper::createDir($locale_path); |
| 89 | 89 | bindtextdomain('translations', $locale_path); |
| 90 | 90 | textdomain('translations'); |
@@ -119,9 +119,9 @@ discard block |
||
| 119 | 119 | */ |
| 120 | 120 | public static function checkI18Class($namespace) { |
| 121 | 121 | $isI18n = false; |
| 122 | - if(preg_match('/I18n$/i', $namespace)) { |
|
| 122 | + if (preg_match('/I18n$/i', $namespace)) { |
|
| 123 | 123 | $parentClass = preg_replace('/I18n$/i', '', $namespace); |
| 124 | - if(Router::exists($parentClass)) { |
|
| 124 | + if (Router::exists($parentClass)) { |
|
| 125 | 125 | $isI18n = true; |
| 126 | 126 | } |
| 127 | 127 | } |