@@ -71,11 +71,11 @@ discard block |
||
| 71 | 71 | */ |
| 72 | 72 | public function init() |
| 73 | 73 | { |
| 74 | - list($this->routing, $this->slugs) = $this->cache->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . "urls.json", $this->cacheType, TRUE); |
|
| 74 | + list($this->routing, $this->slugs) = $this->cache->getDataFromFile(CONFIG_DIR.DIRECTORY_SEPARATOR."urls.json", $this->cacheType, TRUE); |
|
| 75 | 75 | if (empty($this->routing) || Config::getInstance()->getDebugMode()) { |
| 76 | 76 | $this->debugLoad(); |
| 77 | - } else { |
|
| 78 | - $this->domains = $this->cache->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . "domains.json", $this->cacheType, TRUE); |
|
| 77 | + }else { |
|
| 78 | + $this->domains = $this->cache->getDataFromFile(CONFIG_DIR.DIRECTORY_SEPARATOR."domains.json", $this->cacheType, TRUE); |
|
| 79 | 79 | } |
| 80 | 80 | $this->checkExternalModules(false); |
| 81 | 81 | $this->setLoaded(); |
@@ -112,9 +112,9 @@ discard block |
||
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | $not_found_route = Config::getParam('route.404'); |
| 115 | - if(null !== $not_found_route) { |
|
| 115 | + if (null !== $not_found_route) { |
|
| 116 | 116 | Request::getInstance()->redirect($this->getRoute($not_found_route, true)); |
| 117 | - } else { |
|
| 117 | + }else { |
|
| 118 | 118 | return $template->render('error.html.twig', array( |
| 119 | 119 | 'exception' => $e, |
| 120 | 120 | 'trace' => $e->getTraceAsString(), |
@@ -165,12 +165,12 @@ discard block |
||
| 165 | 165 | try { |
| 166 | 166 | //Search action and execute |
| 167 | 167 | $this->searchAction($route); |
| 168 | - } catch (AccessDeniedException $e) { |
|
| 169 | - Logger::log(_('Solicitamos credenciales de acceso a zona restringida'), LOG_WARNING, ['file' => $e->getFile() . '[' . $e->getLine() . ']']); |
|
| 168 | + }catch (AccessDeniedException $e) { |
|
| 169 | + Logger::log(_('Solicitamos credenciales de acceso a zona restringida'), LOG_WARNING, ['file' => $e->getFile().'['.$e->getLine().']']); |
|
| 170 | 170 | return Admin::staticAdminLogon($route); |
| 171 | - } catch (RouterException $r) { |
|
| 171 | + }catch (RouterException $r) { |
|
| 172 | 172 | Logger::log($r->getMessage(), LOG_WARNING); |
| 173 | - } catch (\Exception $e) { |
|
| 173 | + }catch (\Exception $e) { |
|
| 174 | 174 | Logger::log($e->getMessage(), LOG_ERR); |
| 175 | 175 | throw $e; |
| 176 | 176 | } |
@@ -187,7 +187,7 @@ discard block |
||
| 187 | 187 | */ |
| 188 | 188 | protected function searchAction($route) |
| 189 | 189 | { |
| 190 | - Logger::log('Searching action to execute: ' . $route, LOG_INFO); |
|
| 190 | + Logger::log('Searching action to execute: '.$route, LOG_INFO); |
|
| 191 | 191 | //Revisamos si tenemos la ruta registrada |
| 192 | 192 | $parts = parse_url($route); |
| 193 | 193 | $path = array_key_exists('path', $parts) ? $parts['path'] : $route; |
@@ -202,12 +202,12 @@ discard block |
||
| 202 | 202 | /** @var $class \PSFS\base\types\Controller */ |
| 203 | 203 | $class = RouterHelper::getClassToCall($action); |
| 204 | 204 | try { |
| 205 | - if($this->checkRequirements($action, $get)) { |
|
| 205 | + if ($this->checkRequirements($action, $get)) { |
|
| 206 | 206 | $this->executeCachedRoute($route, $action, $class, $get); |
| 207 | - } else { |
|
| 207 | + }else { |
|
| 208 | 208 | throw new RouterException(_('La ruta no es válida'), 400); |
| 209 | 209 | } |
| 210 | - } catch (\Exception $e) { |
|
| 210 | + }catch (\Exception $e) { |
|
| 211 | 211 | Logger::log($e->getMessage(), LOG_ERR); |
| 212 | 212 | throw $e; |
| 213 | 213 | } |
@@ -222,15 +222,15 @@ discard block |
||
| 222 | 222 | * @return bool |
| 223 | 223 | */ |
| 224 | 224 | private function checkRequirements(array $action, $params = []) { |
| 225 | - if(!empty($params) && !empty($action['requirements'])) { |
|
| 225 | + if (!empty($params) && !empty($action['requirements'])) { |
|
| 226 | 226 | $checked = 0; |
| 227 | - foreach(array_keys($params) as $key) { |
|
| 228 | - if(in_array($key, $action['requirements'], true)) { |
|
| 227 | + foreach (array_keys($params) as $key) { |
|
| 228 | + if (in_array($key, $action['requirements'], true)) { |
|
| 229 | 229 | $checked++; |
| 230 | 230 | } |
| 231 | 231 | } |
| 232 | 232 | $valid = count($action['requirements']) === $checked; |
| 233 | - } else { |
|
| 233 | + }else { |
|
| 234 | 234 | $valid = true; |
| 235 | 235 | } |
| 236 | 236 | return $valid; |
@@ -280,14 +280,14 @@ discard block |
||
| 280 | 280 | $this->checkExternalModules(); |
| 281 | 281 | if (file_exists($modulesPath)) { |
| 282 | 282 | $modules = $this->finder->directories()->in($modulesPath)->depth(0); |
| 283 | - if(is_array($modules)) { |
|
| 283 | + if (is_array($modules)) { |
|
| 284 | 284 | foreach ($modules as $modulePath) { |
| 285 | 285 | $module = $modulePath->getBasename(); |
| 286 | - $this->routing = $this->inspectDir($modulesPath . DIRECTORY_SEPARATOR . $module, $module, $this->routing); |
|
| 286 | + $this->routing = $this->inspectDir($modulesPath.DIRECTORY_SEPARATOR.$module, $module, $this->routing); |
|
| 287 | 287 | } |
| 288 | 288 | } |
| 289 | 289 | } |
| 290 | - $this->cache->storeData(CONFIG_DIR . DIRECTORY_SEPARATOR . 'domains.json', $this->domains, Cache::JSON, TRUE); |
|
| 290 | + $this->cache->storeData(CONFIG_DIR.DIRECTORY_SEPARATOR.'domains.json', $this->domains, Cache::JSON, TRUE); |
|
| 291 | 291 | } |
| 292 | 292 | |
| 293 | 293 | /** |
@@ -303,7 +303,7 @@ discard block |
||
| 303 | 303 | $home_params = NULL; |
| 304 | 304 | foreach ($this->routing as $pattern => $params) { |
| 305 | 305 | list($method, $route) = RouterHelper::extractHttpRoute($pattern); |
| 306 | - if (preg_match('/' . preg_quote($route, '/') . '$/i', '/' . $home)) { |
|
| 306 | + if (preg_match('/'.preg_quote($route, '/').'$/i', '/'.$home)) { |
|
| 307 | 307 | $home_params = $params; |
| 308 | 308 | } |
| 309 | 309 | } |
@@ -324,10 +324,10 @@ discard block |
||
| 324 | 324 | private function inspectDir($origen, $namespace = 'PSFS', $routing = []) |
| 325 | 325 | { |
| 326 | 326 | $files = $this->finder->files()->in($origen)->path('/(controller|api)/i')->depth(1)->name('*.php'); |
| 327 | - if(is_array($files)) { |
|
| 327 | + if (is_array($files)) { |
|
| 328 | 328 | foreach ($files as $file) { |
| 329 | 329 | $filename = str_replace('/', '\\', str_replace($origen, '', $file->getPathname())); |
| 330 | - $routing = $this->addRouting($namespace . str_replace('.php', '', $filename), $routing, $namespace); |
|
| 330 | + $routing = $this->addRouting($namespace.str_replace('.php', '', $filename), $routing, $namespace); |
|
| 331 | 331 | } |
| 332 | 332 | } |
| 333 | 333 | $this->finder = new Finder(); |
@@ -356,7 +356,7 @@ discard block |
||
| 356 | 356 | private function addRouting($namespace, &$routing, $module = 'PSFS') |
| 357 | 357 | { |
| 358 | 358 | if (self::exists($namespace)) { |
| 359 | - if(I18nHelper::checkI18Class($namespace)) { |
|
| 359 | + if (I18nHelper::checkI18Class($namespace)) { |
|
| 360 | 360 | return $routing; |
| 361 | 361 | } |
| 362 | 362 | $reflection = new \ReflectionClass($namespace); |
@@ -398,7 +398,7 @@ discard block |
||
| 398 | 398 | if (!$this->domains) { |
| 399 | 399 | $this->domains = []; |
| 400 | 400 | } |
| 401 | - $domain = '@' . $class->getConstant('DOMAIN') . '/'; |
|
| 401 | + $domain = '@'.$class->getConstant('DOMAIN').'/'; |
|
| 402 | 402 | if (!array_key_exists($domain, $this->domains)) { |
| 403 | 403 | $this->domains[$domain] = RouterHelper::extractDomainInfo($class, $domain); |
| 404 | 404 | } |
@@ -414,11 +414,11 @@ discard block |
||
| 414 | 414 | */ |
| 415 | 415 | public function simpatize() |
| 416 | 416 | { |
| 417 | - $translationFileName = 'translations' . DIRECTORY_SEPARATOR . 'routes_translations.php'; |
|
| 418 | - $absoluteTranslationFileName = CACHE_DIR . DIRECTORY_SEPARATOR . $translationFileName; |
|
| 417 | + $translationFileName = 'translations'.DIRECTORY_SEPARATOR.'routes_translations.php'; |
|
| 418 | + $absoluteTranslationFileName = CACHE_DIR.DIRECTORY_SEPARATOR.$translationFileName; |
|
| 419 | 419 | $this->generateSlugs($absoluteTranslationFileName); |
| 420 | 420 | GeneratorHelper::createDir(CONFIG_DIR); |
| 421 | - Cache::getInstance()->storeData(CONFIG_DIR . DIRECTORY_SEPARATOR . 'urls.json', array($this->routing, $this->slugs), Cache::JSON, TRUE); |
|
| 421 | + Cache::getInstance()->storeData(CONFIG_DIR.DIRECTORY_SEPARATOR.'urls.json', array($this->routing, $this->slugs), Cache::JSON, TRUE); |
|
| 422 | 422 | |
| 423 | 423 | return $this; |
| 424 | 424 | } |
@@ -434,18 +434,18 @@ discard block |
||
| 434 | 434 | public function getRoute($slug = '', $absolute = FALSE, array $params = []) |
| 435 | 435 | { |
| 436 | 436 | if ('' === $slug) { |
| 437 | - return $absolute ? Request::getInstance()->getRootUrl() . '/' : '/'; |
|
| 437 | + return $absolute ? Request::getInstance()->getRootUrl().'/' : '/'; |
|
| 438 | 438 | } |
| 439 | 439 | if (!is_array($this->slugs) || !array_key_exists($slug, $this->slugs)) { |
| 440 | 440 | throw new RouterException(_('No existe la ruta especificada')); |
| 441 | 441 | } |
| 442 | - $url = $absolute ? Request::getInstance()->getRootUrl() . $this->slugs[$slug] : $this->slugs[$slug]; |
|
| 442 | + $url = $absolute ? Request::getInstance()->getRootUrl().$this->slugs[$slug] : $this->slugs[$slug]; |
|
| 443 | 443 | if (!empty($params)) { |
| 444 | 444 | foreach ($params as $key => $value) { |
| 445 | - $url = str_replace('{' . $key . '}', $value, $url); |
|
| 445 | + $url = str_replace('{'.$key.'}', $value, $url); |
|
| 446 | 446 | } |
| 447 | 447 | } elseif (!empty($this->routing[$this->slugs[$slug]]['default'])) { |
| 448 | - $url = $absolute ? Request::getInstance()->getRootUrl() . $this->routing[$this->slugs[$slug]]['default'] : $this->routing[$this->slugs[$slug]]['default']; |
|
| 448 | + $url = $absolute ? Request::getInstance()->getRootUrl().$this->routing[$this->slugs[$slug]]['default'] : $this->routing[$this->slugs[$slug]]['default']; |
|
| 449 | 449 | } |
| 450 | 450 | |
| 451 | 451 | return preg_replace('/(GET|POST|PUT|DELETE|ALL)\#\|\#/', '', $url); |
@@ -487,17 +487,17 @@ discard block |
||
| 487 | 487 | */ |
| 488 | 488 | protected function executeCachedRoute($route, $action, $class, $params = NULL) |
| 489 | 489 | { |
| 490 | - Logger::log('Executing route ' . $route, LOG_INFO); |
|
| 490 | + Logger::log('Executing route '.$route, LOG_INFO); |
|
| 491 | 491 | $action['params'] = array_merge($action['params'], $params, Request::getInstance()->getQueryParams()); |
| 492 | 492 | Security::getInstance()->setSessionKey(Cache::CACHE_SESSION_VAR, $action); |
| 493 | 493 | $cache = Cache::needCache(); |
| 494 | 494 | $execute = TRUE; |
| 495 | 495 | if (FALSE !== $cache && $action['http'] === 'GET' && Config::getParam('debug') === FALSE) { |
| 496 | 496 | list($path, $cacheDataName) = $this->cache->getRequestCacheHash(); |
| 497 | - $cachedData = $this->cache->readFromCache('json' . DIRECTORY_SEPARATOR . $path . $cacheDataName, |
|
| 497 | + $cachedData = $this->cache->readFromCache('json'.DIRECTORY_SEPARATOR.$path.$cacheDataName, |
|
| 498 | 498 | $cache); |
| 499 | 499 | if (NULL !== $cachedData) { |
| 500 | - $headers = $this->cache->readFromCache('json' . DIRECTORY_SEPARATOR . $path . $cacheDataName . '.headers', |
|
| 500 | + $headers = $this->cache->readFromCache('json'.DIRECTORY_SEPARATOR.$path.$cacheDataName.'.headers', |
|
| 501 | 501 | $cache, null, Cache::JSON); |
| 502 | 502 | Template::getInstance()->renderCache($cachedData, $headers); |
| 503 | 503 | $execute = FALSE; |
@@ -540,11 +540,11 @@ discard block |
||
| 540 | 540 | private function loadExternalAutoloader($hydrateRoute, SplFileInfo $modulePath, $externalModulePath) |
| 541 | 541 | { |
| 542 | 542 | $extModule = $modulePath->getBasename(); |
| 543 | - $moduleAutoloader = realpath($externalModulePath . DIRECTORY_SEPARATOR . $extModule . DIRECTORY_SEPARATOR . 'autoload.php'); |
|
| 544 | - if(file_exists($moduleAutoloader)) { |
|
| 543 | + $moduleAutoloader = realpath($externalModulePath.DIRECTORY_SEPARATOR.$extModule.DIRECTORY_SEPARATOR.'autoload.php'); |
|
| 544 | + if (file_exists($moduleAutoloader)) { |
|
| 545 | 545 | include_once $moduleAutoloader; |
| 546 | 546 | if ($hydrateRoute) { |
| 547 | - $this->routing = $this->inspectDir($externalModulePath . DIRECTORY_SEPARATOR . $extModule, '\\' . $extModule, $this->routing); |
|
| 547 | + $this->routing = $this->inspectDir($externalModulePath.DIRECTORY_SEPARATOR.$extModule, '\\'.$extModule, $this->routing); |
|
| 548 | 548 | } |
| 549 | 549 | } |
| 550 | 550 | } |
@@ -558,14 +558,14 @@ discard block |
||
| 558 | 558 | { |
| 559 | 559 | try { |
| 560 | 560 | $module = preg_replace('/(\\\|\/)/', DIRECTORY_SEPARATOR, $module); |
| 561 | - $externalModulePath = VENDOR_DIR . DIRECTORY_SEPARATOR . $module . DIRECTORY_SEPARATOR . 'src'; |
|
| 561 | + $externalModulePath = VENDOR_DIR.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.'src'; |
|
| 562 | 562 | $externalModule = $this->finder->directories()->in($externalModulePath)->depth(0); |
| 563 | - if(is_array($externalModule)) { |
|
| 563 | + if (is_array($externalModule)) { |
|
| 564 | 564 | foreach ($externalModule as $modulePath) { |
| 565 | 565 | $this->loadExternalAutoloader($hydrateRoute, $modulePath, $externalModulePath); |
| 566 | 566 | } |
| 567 | 567 | } |
| 568 | - } catch (\Exception $e) { |
|
| 568 | + }catch (\Exception $e) { |
|
| 569 | 569 | Logger::log($e->getMessage(), LOG_WARNING); |
| 570 | 570 | $module = null; |
| 571 | 571 | } |