@@ -75,11 +75,11 @@ discard block |
||
| 75 | 75 | */ |
| 76 | 76 | public function init() |
| 77 | 77 | { |
| 78 | - list($this->routing, $this->slugs) = $this->cache->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . 'urls.json', $this->cacheType, TRUE); |
|
| 78 | + list($this->routing, $this->slugs) = $this->cache->getDataFromFile(CONFIG_DIR.DIRECTORY_SEPARATOR.'urls.json', $this->cacheType, TRUE); |
|
| 79 | 79 | if (empty($this->routing) || Config::getInstance()->getDebugMode()) { |
| 80 | 80 | $this->debugLoad(); |
| 81 | - } else { |
|
| 82 | - $this->domains = $this->cache->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . 'domains.json', $this->cacheType, TRUE); |
|
| 81 | + }else { |
|
| 82 | + $this->domains = $this->cache->getDataFromFile(CONFIG_DIR.DIRECTORY_SEPARATOR.'domains.json', $this->cacheType, TRUE); |
|
| 83 | 83 | } |
| 84 | 84 | $this->checkExternalModules(false); |
| 85 | 85 | $this->setLoaded(); |
@@ -117,9 +117,9 @@ discard block |
||
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | $not_found_route = Config::getParam('route.404'); |
| 120 | - if(null !== $not_found_route) { |
|
| 120 | + if (null !== $not_found_route) { |
|
| 121 | 121 | Request::getInstance()->redirect($this->getRoute($not_found_route, true)); |
| 122 | - } else { |
|
| 122 | + }else { |
|
| 123 | 123 | return $template->render('error.html.twig', array( |
| 124 | 124 | 'exception' => $e, |
| 125 | 125 | 'trace' => $e->getTraceAsString(), |
@@ -170,12 +170,12 @@ discard block |
||
| 170 | 170 | try { |
| 171 | 171 | //Search action and execute |
| 172 | 172 | $this->searchAction($route); |
| 173 | - } catch (AccessDeniedException $e) { |
|
| 174 | - Logger::log(_('Solicitamos credenciales de acceso a zona restringida'), LOG_WARNING, ['file' => $e->getFile() . '[' . $e->getLine() . ']']); |
|
| 173 | + }catch (AccessDeniedException $e) { |
|
| 174 | + Logger::log(_('Solicitamos credenciales de acceso a zona restringida'), LOG_WARNING, ['file' => $e->getFile().'['.$e->getLine().']']); |
|
| 175 | 175 | return Admin::staticAdminLogon($route); |
| 176 | - } catch (RouterException $r) { |
|
| 176 | + }catch (RouterException $r) { |
|
| 177 | 177 | Logger::log($r->getMessage(), LOG_WARNING); |
| 178 | - } catch (\Exception $e) { |
|
| 178 | + }catch (\Exception $e) { |
|
| 179 | 179 | Logger::log($e->getMessage(), LOG_ERR); |
| 180 | 180 | throw $e; |
| 181 | 181 | } |
@@ -192,7 +192,7 @@ discard block |
||
| 192 | 192 | */ |
| 193 | 193 | protected function searchAction($route) |
| 194 | 194 | { |
| 195 | - Logger::log('Searching action to execute: ' . $route, LOG_INFO); |
|
| 195 | + Logger::log('Searching action to execute: '.$route, LOG_INFO); |
|
| 196 | 196 | //Revisamos si tenemos la ruta registrada |
| 197 | 197 | $parts = parse_url($route); |
| 198 | 198 | $path = array_key_exists('path', $parts) ? $parts['path'] : $route; |
@@ -207,12 +207,12 @@ discard block |
||
| 207 | 207 | /** @var $class \PSFS\base\types\Controller */ |
| 208 | 208 | $class = RouterHelper::getClassToCall($action); |
| 209 | 209 | try { |
| 210 | - if($this->checkRequirements($action, $get)) { |
|
| 210 | + if ($this->checkRequirements($action, $get)) { |
|
| 211 | 211 | $this->executeCachedRoute($route, $action, $class, $get); |
| 212 | - } else { |
|
| 212 | + }else { |
|
| 213 | 213 | throw new RouterException(_('La ruta no es válida'), 400); |
| 214 | 214 | } |
| 215 | - } catch (\Exception $e) { |
|
| 215 | + }catch (\Exception $e) { |
|
| 216 | 216 | Logger::log($e->getMessage(), LOG_ERR); |
| 217 | 217 | throw $e; |
| 218 | 218 | } |
@@ -227,15 +227,15 @@ discard block |
||
| 227 | 227 | * @return bool |
| 228 | 228 | */ |
| 229 | 229 | private function checkRequirements(array $action, $params = []) { |
| 230 | - if(!empty($params) && !empty($action['requirements'])) { |
|
| 230 | + if (!empty($params) && !empty($action['requirements'])) { |
|
| 231 | 231 | $checked = 0; |
| 232 | - foreach(array_keys($params) as $key) { |
|
| 233 | - if(in_array($key, $action['requirements'], true)) { |
|
| 232 | + foreach (array_keys($params) as $key) { |
|
| 233 | + if (in_array($key, $action['requirements'], true)) { |
|
| 234 | 234 | $checked++; |
| 235 | 235 | } |
| 236 | 236 | } |
| 237 | 237 | $valid = count($action['requirements']) === $checked; |
| 238 | - } else { |
|
| 238 | + }else { |
|
| 239 | 239 | $valid = true; |
| 240 | 240 | } |
| 241 | 241 | return $valid; |
@@ -285,14 +285,14 @@ discard block |
||
| 285 | 285 | $this->checkExternalModules(); |
| 286 | 286 | if (file_exists($modulesPath)) { |
| 287 | 287 | $modules = $this->finder->directories()->in($modulesPath)->depth(0); |
| 288 | - if($modules->hasResults()) { |
|
| 288 | + if ($modules->hasResults()) { |
|
| 289 | 289 | foreach ($modules->getIterator() as $modulePath) { |
| 290 | 290 | $module = $modulePath->getBasename(); |
| 291 | - $this->routing = $this->inspectDir($modulesPath . DIRECTORY_SEPARATOR . $module, $module, $this->routing); |
|
| 291 | + $this->routing = $this->inspectDir($modulesPath.DIRECTORY_SEPARATOR.$module, $module, $this->routing); |
|
| 292 | 292 | } |
| 293 | 293 | } |
| 294 | 294 | } |
| 295 | - $this->cache->storeData(CONFIG_DIR . DIRECTORY_SEPARATOR . 'domains.json', $this->domains, Cache::JSON, TRUE); |
|
| 295 | + $this->cache->storeData(CONFIG_DIR.DIRECTORY_SEPARATOR.'domains.json', $this->domains, Cache::JSON, TRUE); |
|
| 296 | 296 | } |
| 297 | 297 | |
| 298 | 298 | /** |
@@ -308,7 +308,7 @@ discard block |
||
| 308 | 308 | $home_params = NULL; |
| 309 | 309 | foreach ($this->routing as $pattern => $params) { |
| 310 | 310 | list($method, $route) = RouterHelper::extractHttpRoute($pattern); |
| 311 | - if (preg_match('/' . preg_quote($route, '/') . '$/i', '/' . $home)) { |
|
| 311 | + if (preg_match('/'.preg_quote($route, '/').'$/i', '/'.$home)) { |
|
| 312 | 312 | $home_params = $params; |
| 313 | 313 | } |
| 314 | 314 | } |
@@ -329,14 +329,14 @@ discard block |
||
| 329 | 329 | private function inspectDir($origen, $namespace = 'PSFS', $routing = []) |
| 330 | 330 | { |
| 331 | 331 | $files = $this->finder->files()->in($origen)->path('/(controller|api)/i')->depth(1)->name('*.php'); |
| 332 | - if($files->hasResults()) { |
|
| 332 | + if ($files->hasResults()) { |
|
| 333 | 333 | foreach ($files->getIterator() as $file) { |
| 334 | - if(method_exists($file, 'getRelativePathname') && $namespace !== 'PSFS') { |
|
| 335 | - $filename = '\\' . str_replace('/', '\\', str_replace($origen, '', $file->getRelativePathname())); |
|
| 336 | - } else { |
|
| 334 | + if (method_exists($file, 'getRelativePathname') && $namespace !== 'PSFS') { |
|
| 335 | + $filename = '\\'.str_replace('/', '\\', str_replace($origen, '', $file->getRelativePathname())); |
|
| 336 | + }else { |
|
| 337 | 337 | $filename = str_replace('/', '\\', str_replace($origen, '', $file->getPathname())); |
| 338 | 338 | } |
| 339 | - $routing = $this->addRouting($namespace . str_replace('.php', '', $filename), $routing, $namespace); |
|
| 339 | + $routing = $this->addRouting($namespace.str_replace('.php', '', $filename), $routing, $namespace); |
|
| 340 | 340 | } |
| 341 | 341 | } |
| 342 | 342 | $this->finder = new Finder(); |
@@ -365,7 +365,7 @@ discard block |
||
| 365 | 365 | private function addRouting($namespace, &$routing, $module = 'PSFS') |
| 366 | 366 | { |
| 367 | 367 | if (self::exists($namespace)) { |
| 368 | - if(I18nHelper::checkI18Class($namespace)) { |
|
| 368 | + if (I18nHelper::checkI18Class($namespace)) { |
|
| 369 | 369 | return $routing; |
| 370 | 370 | } |
| 371 | 371 | $reflection = new \ReflectionClass($namespace); |
@@ -407,7 +407,7 @@ discard block |
||
| 407 | 407 | if (!$this->domains) { |
| 408 | 408 | $this->domains = []; |
| 409 | 409 | } |
| 410 | - $domain = '@' . $class->getConstant('DOMAIN') . '/'; |
|
| 410 | + $domain = '@'.$class->getConstant('DOMAIN').'/'; |
|
| 411 | 411 | if (!array_key_exists($domain, $this->domains)) { |
| 412 | 412 | $this->domains[$domain] = RouterHelper::extractDomainInfo($class, $domain); |
| 413 | 413 | } |
@@ -423,11 +423,11 @@ discard block |
||
| 423 | 423 | */ |
| 424 | 424 | public function simpatize() |
| 425 | 425 | { |
| 426 | - $translationFileName = 'translations' . DIRECTORY_SEPARATOR . 'routes_translations.php'; |
|
| 427 | - $absoluteTranslationFileName = CACHE_DIR . DIRECTORY_SEPARATOR . $translationFileName; |
|
| 426 | + $translationFileName = 'translations'.DIRECTORY_SEPARATOR.'routes_translations.php'; |
|
| 427 | + $absoluteTranslationFileName = CACHE_DIR.DIRECTORY_SEPARATOR.$translationFileName; |
|
| 428 | 428 | $this->generateSlugs($absoluteTranslationFileName); |
| 429 | 429 | GeneratorHelper::createDir(CONFIG_DIR); |
| 430 | - Cache::getInstance()->storeData(CONFIG_DIR . DIRECTORY_SEPARATOR . 'urls.json', array($this->routing, $this->slugs), Cache::JSON, TRUE); |
|
| 430 | + Cache::getInstance()->storeData(CONFIG_DIR.DIRECTORY_SEPARATOR.'urls.json', array($this->routing, $this->slugs), Cache::JSON, TRUE); |
|
| 431 | 431 | |
| 432 | 432 | return $this; |
| 433 | 433 | } |
@@ -443,18 +443,18 @@ discard block |
||
| 443 | 443 | public function getRoute($slug = '', $absolute = FALSE, array $params = []) |
| 444 | 444 | { |
| 445 | 445 | if ('' === $slug) { |
| 446 | - return $absolute ? Request::getInstance()->getRootUrl() . '/' : '/'; |
|
| 446 | + return $absolute ? Request::getInstance()->getRootUrl().'/' : '/'; |
|
| 447 | 447 | } |
| 448 | 448 | if (!is_array($this->slugs) || !array_key_exists($slug, $this->slugs)) { |
| 449 | 449 | throw new RouterException(_('No existe la ruta especificada')); |
| 450 | 450 | } |
| 451 | - $url = $absolute ? Request::getInstance()->getRootUrl() . $this->slugs[$slug] : $this->slugs[$slug]; |
|
| 451 | + $url = $absolute ? Request::getInstance()->getRootUrl().$this->slugs[$slug] : $this->slugs[$slug]; |
|
| 452 | 452 | if (!empty($params)) { |
| 453 | 453 | foreach ($params as $key => $value) { |
| 454 | - $url = str_replace('{' . $key . '}', $value, $url); |
|
| 454 | + $url = str_replace('{'.$key.'}', $value, $url); |
|
| 455 | 455 | } |
| 456 | 456 | } elseif (!empty($this->routing[$this->slugs[$slug]]['default'])) { |
| 457 | - $url = $absolute ? Request::getInstance()->getRootUrl() . $this->routing[$this->slugs[$slug]]['default'] : $this->routing[$this->slugs[$slug]]['default']; |
|
| 457 | + $url = $absolute ? Request::getInstance()->getRootUrl().$this->routing[$this->slugs[$slug]]['default'] : $this->routing[$this->slugs[$slug]]['default']; |
|
| 458 | 458 | } |
| 459 | 459 | |
| 460 | 460 | return preg_replace('/(GET|POST|PUT|DELETE|ALL)\#\|\#/', '', $url); |
@@ -496,17 +496,17 @@ discard block |
||
| 496 | 496 | */ |
| 497 | 497 | protected function executeCachedRoute($route, $action, $class, $params = NULL) |
| 498 | 498 | { |
| 499 | - Logger::log('Executing route ' . $route, LOG_INFO); |
|
| 499 | + Logger::log('Executing route '.$route, LOG_INFO); |
|
| 500 | 500 | $action['params'] = array_merge($action['params'], $params, Request::getInstance()->getQueryParams()); |
| 501 | 501 | Security::getInstance()->setSessionKey(Cache::CACHE_SESSION_VAR, $action); |
| 502 | 502 | $cache = Cache::needCache(); |
| 503 | 503 | $execute = TRUE; |
| 504 | 504 | if (FALSE !== $cache && $action['http'] === 'GET' && Config::getParam('debug') === FALSE) { |
| 505 | 505 | list($path, $cacheDataName) = $this->cache->getRequestCacheHash(); |
| 506 | - $cachedData = $this->cache->readFromCache('json' . DIRECTORY_SEPARATOR . $path . $cacheDataName, |
|
| 506 | + $cachedData = $this->cache->readFromCache('json'.DIRECTORY_SEPARATOR.$path.$cacheDataName, |
|
| 507 | 507 | $cache); |
| 508 | 508 | if (NULL !== $cachedData) { |
| 509 | - $headers = $this->cache->readFromCache('json' . DIRECTORY_SEPARATOR . $path . $cacheDataName . '.headers', |
|
| 509 | + $headers = $this->cache->readFromCache('json'.DIRECTORY_SEPARATOR.$path.$cacheDataName.'.headers', |
|
| 510 | 510 | $cache, null, Cache::JSON); |
| 511 | 511 | Template::getInstance()->renderCache($cachedData, $headers); |
| 512 | 512 | $execute = FALSE; |
@@ -549,11 +549,11 @@ discard block |
||
| 549 | 549 | private function loadExternalAutoloader($hydrateRoute, SplFileInfo $modulePath, $externalModulePath) |
| 550 | 550 | { |
| 551 | 551 | $extModule = $modulePath->getBasename(); |
| 552 | - $moduleAutoloader = realpath($externalModulePath . DIRECTORY_SEPARATOR . $extModule . DIRECTORY_SEPARATOR . 'autoload.php'); |
|
| 553 | - if(file_exists($moduleAutoloader)) { |
|
| 552 | + $moduleAutoloader = realpath($externalModulePath.DIRECTORY_SEPARATOR.$extModule.DIRECTORY_SEPARATOR.'autoload.php'); |
|
| 553 | + if (file_exists($moduleAutoloader)) { |
|
| 554 | 554 | include_once $moduleAutoloader; |
| 555 | 555 | if ($hydrateRoute) { |
| 556 | - $this->routing = $this->inspectDir($externalModulePath . DIRECTORY_SEPARATOR . $extModule, '\\' . $extModule, $this->routing); |
|
| 556 | + $this->routing = $this->inspectDir($externalModulePath.DIRECTORY_SEPARATOR.$extModule, '\\'.$extModule, $this->routing); |
|
| 557 | 557 | } |
| 558 | 558 | } |
| 559 | 559 | } |
@@ -567,14 +567,14 @@ discard block |
||
| 567 | 567 | { |
| 568 | 568 | try { |
| 569 | 569 | $module = preg_replace('/(\\\|\/)/', DIRECTORY_SEPARATOR, $module); |
| 570 | - $externalModulePath = VENDOR_DIR . DIRECTORY_SEPARATOR . $module . DIRECTORY_SEPARATOR . 'src'; |
|
| 570 | + $externalModulePath = VENDOR_DIR.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.'src'; |
|
| 571 | 571 | $externalModule = $this->finder->directories()->in($externalModulePath)->depth(0); |
| 572 | - if($externalModule->hasResults()) { |
|
| 572 | + if ($externalModule->hasResults()) { |
|
| 573 | 573 | foreach ($externalModule->getIterator() as $modulePath) { |
| 574 | 574 | $this->loadExternalAutoloader($hydrateRoute, $modulePath, $externalModulePath); |
| 575 | 575 | } |
| 576 | 576 | } |
| 577 | - } catch (\Exception $e) { |
|
| 577 | + }catch (\Exception $e) { |
|
| 578 | 578 | Logger::log($e->getMessage(), LOG_WARNING); |
| 579 | 579 | $module = null; |
| 580 | 580 | } |