@@ -57,12 +57,12 @@ discard block  | 
                                                    ||
| 57 | 57 | */  | 
                                                        
| 58 | 58 | public function init()  | 
                                                        
| 59 | 59 |      { | 
                                                        
| 60 | -        if (!file_exists(CONFIG_DIR . DIRECTORY_SEPARATOR . "urls.json") || Config::getInstance()->getDebugMode()) { | 
                                                        |
| 60 | +        if (!file_exists(CONFIG_DIR.DIRECTORY_SEPARATOR."urls.json") || Config::getInstance()->getDebugMode()) { | 
                                                        |
| 61 | 61 | $this->hydrateRouting();  | 
                                                        
| 62 | 62 | $this->simpatize();  | 
                                                        
| 63 | -        } else { | 
                                                        |
| 64 | - list($this->routing, $this->slugs) = $this->cache->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . "urls.json", Cache::JSON, TRUE);  | 
                                                        |
| 65 | - $this->domains = $this->cache->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . "domains.json", Cache::JSON, TRUE);  | 
                                                        |
| 63 | +        }else { | 
                                                        |
| 64 | + list($this->routing, $this->slugs) = $this->cache->getDataFromFile(CONFIG_DIR.DIRECTORY_SEPARATOR."urls.json", Cache::JSON, TRUE);  | 
                                                        |
| 65 | + $this->domains = $this->cache->getDataFromFile(CONFIG_DIR.DIRECTORY_SEPARATOR."domains.json", Cache::JSON, TRUE);  | 
                                                        |
| 66 | 66 | }  | 
                                                        
| 67 | 67 | }  | 
                                                        
| 68 | 68 | |
@@ -82,7 +82,7 @@ discard block  | 
                                                    ||
| 82 | 82 | "success" => FALSE,  | 
                                                        
| 83 | 83 | "error" => $e->getMessage(),  | 
                                                        
| 84 | 84 | )), 'application/json');  | 
                                                        
| 85 | -        } else { | 
                                                        |
| 85 | +        }else { | 
                                                        |
| 86 | 86 |              if (NULL === $e) { | 
                                                        
| 87 | 87 |                  Logger::log('Not found page throwed without previous exception', LOG_WARNING); | 
                                                        
| 88 | 88 |                  $e = new \Exception(_('Page not found'), 404); | 
                                                        
@@ -111,8 +111,8 @@ discard block  | 
                                                    ||
| 111 | 111 | */  | 
                                                        
| 112 | 112 |      public function getAllRoutes() { | 
                                                        
| 113 | 113 | $routes = [];  | 
                                                        
| 114 | -        foreach($this->routing as $path => $route) { | 
                                                        |
| 115 | -            if(array_key_exists('slug', $route)) { | 
                                                        |
| 114 | +        foreach ($this->routing as $path => $route) { | 
                                                        |
| 115 | +            if (array_key_exists('slug', $route)) { | 
                                                        |
| 116 | 116 | $routes[$route['slug']] = $path;  | 
                                                        
| 117 | 117 | }  | 
                                                        
| 118 | 118 | }  | 
                                                        
@@ -137,15 +137,15 @@ discard block  | 
                                                    ||
| 137 | 137 | SecurityHelper::checkRestrictedAccess($route);  | 
                                                        
| 138 | 138 | //Search action and execute  | 
                                                        
| 139 | 139 | $this->searchAction($route);  | 
                                                        
| 140 | -        } catch (AccessDeniedException $e) { | 
                                                        |
| 140 | +        }catch (AccessDeniedException $e) { | 
                                                        |
| 141 | 141 |              Logger::log(_('Solicitamos credenciales de acceso a zona restringida')); | 
                                                        
| 142 | 142 | return Admin::staticAdminLogon($route);  | 
                                                        
| 143 | -        } catch (RouterException $r) { | 
                                                        |
| 144 | -            if(null === RouterHelper::checkDefaultRoute($route)) { | 
                                                        |
| 143 | +        }catch (RouterException $r) { | 
                                                        |
| 144 | +            if (null === RouterHelper::checkDefaultRoute($route)) { | 
                                                        |
| 145 | 145 | Logger::log($r->getMessage(), LOG_WARNING);  | 
                                                        
| 146 | 146 | throw $r;  | 
                                                        
| 147 | 147 | }  | 
                                                        
| 148 | -        } catch (\Exception $e) { | 
                                                        |
| 148 | +        }catch (\Exception $e) { | 
                                                        |
| 149 | 149 | Logger::log($e->getMessage(), LOG_ERR);  | 
                                                        
| 150 | 150 | throw $e;  | 
                                                        
| 151 | 151 | }  | 
                                                        
@@ -162,7 +162,7 @@ discard block  | 
                                                    ||
| 162 | 162 | */  | 
                                                        
| 163 | 163 | protected function searchAction($route)  | 
                                                        
| 164 | 164 |      { | 
                                                        
| 165 | -        Logger::log('Searching action to execute: ' . $route, LOG_INFO); | 
                                                        |
| 165 | +        Logger::log('Searching action to execute: '.$route, LOG_INFO); | 
                                                        |
| 166 | 166 | //Revisamos si tenemos la ruta registrada  | 
                                                        
| 167 | 167 | $parts = parse_url($route);  | 
                                                        
| 168 | 168 |          $path = (array_key_exists('path', $parts)) ? $parts['path'] : $route; | 
                                                        
@@ -176,7 +176,7 @@ discard block  | 
                                                    ||
| 176 | 176 | $class = RouterHelper::getClassToCall($action);  | 
                                                        
| 177 | 177 |                  try { | 
                                                        
| 178 | 178 | $this->executeCachedRoute($route, $action, $class, $get);  | 
                                                        
| 179 | -                } catch (\Exception $e) { | 
                                                        |
| 179 | +                }catch (\Exception $e) { | 
                                                        |
| 180 | 180 | Logger::log($e->getMessage(), LOG_ERR);  | 
                                                        
| 181 | 181 | throw new RouterException($e->getMessage(), 404, $e);  | 
                                                        
| 182 | 182 | }  | 
                                                        
@@ -204,13 +204,13 @@ discard block  | 
                                                    ||
| 204 | 204 | $this->routing = $this->inspectDir($base, "PSFS", array());  | 
                                                        
| 205 | 205 |          if (file_exists($modules)) { | 
                                                        
| 206 | 206 | $module = "";  | 
                                                        
| 207 | -            if(file_exists($modules . DIRECTORY_SEPARATOR . 'module.json')) { | 
                                                        |
| 208 | - $mod_cfg = json_decode(file_get_contents($modules . DIRECTORY_SEPARATOR . 'module.json'), true);  | 
                                                        |
| 207 | +            if (file_exists($modules.DIRECTORY_SEPARATOR.'module.json')) { | 
                                                        |
| 208 | + $mod_cfg = json_decode(file_get_contents($modules.DIRECTORY_SEPARATOR.'module.json'), true);  | 
                                                        |
| 209 | 209 | $module = $mod_cfg['module'];  | 
                                                        
| 210 | 210 | }  | 
                                                        
| 211 | 211 | $this->routing = $this->inspectDir($modules, $module, $this->routing);  | 
                                                        
| 212 | 212 | }  | 
                                                        
| 213 | - $this->cache->storeData(CONFIG_DIR . DIRECTORY_SEPARATOR . "domains.json", $this->domains, Cache::JSON, TRUE);  | 
                                                        |
| 213 | + $this->cache->storeData(CONFIG_DIR.DIRECTORY_SEPARATOR."domains.json", $this->domains, Cache::JSON, TRUE);  | 
                                                        |
| 214 | 214 | }  | 
                                                        
| 215 | 215 | |
| 216 | 216 | /**  | 
                                                        
@@ -225,7 +225,7 @@ discard block  | 
                                                    ||
| 225 | 225 | $home_params = NULL;  | 
                                                        
| 226 | 226 |              foreach ($this->routing as $pattern => $params) { | 
                                                        
| 227 | 227 | list($method, $route) = RouterHelper::extractHttpRoute($pattern);  | 
                                                        
| 228 | -                if (preg_match("/" . preg_quote($route, "/") . "$/i", "/" . $home)) { | 
                                                        |
| 228 | +                if (preg_match("/".preg_quote($route, "/")."$/i", "/".$home)) { | 
                                                        |
| 229 | 229 | $home_params = $params;  | 
                                                        
| 230 | 230 | }  | 
                                                        
| 231 | 231 | }  | 
                                                        
@@ -250,7 +250,7 @@ discard block  | 
                                                    ||
| 250 | 250 |          $files = $this->finder->files()->in($origen)->path('/(controller|api)/i')->name("*.php"); | 
                                                        
| 251 | 251 |          foreach ($files as $file) { | 
                                                        
| 252 | 252 |              $filename = str_replace("/", '\\', str_replace($origen, '', $file->getPathname())); | 
                                                        
| 253 | -            $routing = $this->addRouting($namespace . str_replace('.php', '', $filename), $routing); | 
                                                        |
| 253 | +            $routing = $this->addRouting($namespace.str_replace('.php', '', $filename), $routing); | 
                                                        |
| 254 | 254 | }  | 
                                                        
| 255 | 255 | $this->finder = new Finder();  | 
                                                        
| 256 | 256 | |
@@ -289,7 +289,7 @@ discard block  | 
                                                    ||
| 289 | 289 | }  | 
                                                        
| 290 | 290 |                  foreach ($reflection->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) { | 
                                                        
| 291 | 291 | list($route, $info) = RouterHelper::extractRouteInfo($method, $api);  | 
                                                        
| 292 | -                    if(null !== $route && null !== $info) { | 
                                                        |
| 292 | +                    if (null !== $route && null !== $info) { | 
                                                        |
| 293 | 293 | $info['class'] = $namespace;  | 
                                                        
| 294 | 294 | $routing[$route] = $info;  | 
                                                        
| 295 | 295 | }  | 
                                                        
@@ -312,7 +312,7 @@ discard block  | 
                                                    ||
| 312 | 312 |      { | 
                                                        
| 313 | 313 | //Calculamos los dominios para las plantillas  | 
                                                        
| 314 | 314 |          if ($class->hasConstant("DOMAIN")) { | 
                                                        
| 315 | -            $domain = "@" . $class->getConstant("DOMAIN") . "/"; | 
                                                        |
| 315 | +            $domain = "@".$class->getConstant("DOMAIN")."/"; | 
                                                        |
| 316 | 316 | $this->domains[$domain] = RouterHelper::extractDomainInfo($class, $domain);  | 
                                                        
| 317 | 317 | }  | 
                                                        
| 318 | 318 | |
@@ -325,11 +325,11 @@ discard block  | 
                                                    ||
| 325 | 325 | */  | 
                                                        
| 326 | 326 | public function simpatize()  | 
                                                        
| 327 | 327 |      { | 
                                                        
| 328 | - $translationFileName = "translations" . DIRECTORY_SEPARATOR . "routes_translations.php";  | 
                                                        |
| 329 | - $absoluteTranslationFileName = CACHE_DIR . DIRECTORY_SEPARATOR . $translationFileName;  | 
                                                        |
| 328 | + $translationFileName = "translations".DIRECTORY_SEPARATOR."routes_translations.php";  | 
                                                        |
| 329 | + $absoluteTranslationFileName = CACHE_DIR.DIRECTORY_SEPARATOR.$translationFileName;  | 
                                                        |
| 330 | 330 | $this->generateSlugs($absoluteTranslationFileName);  | 
                                                        
| 331 | 331 | Config::createDir(CONFIG_DIR);  | 
                                                        
| 332 | - Cache::getInstance()->storeData(CONFIG_DIR . DIRECTORY_SEPARATOR . "urls.json", array($this->routing, $this->slugs), Cache::JSON, TRUE);  | 
                                                        |
| 332 | + Cache::getInstance()->storeData(CONFIG_DIR.DIRECTORY_SEPARATOR."urls.json", array($this->routing, $this->slugs), Cache::JSON, TRUE);  | 
                                                        |
| 333 | 333 | |
| 334 | 334 | return $this;  | 
                                                        
| 335 | 335 | }  | 
                                                        
@@ -380,16 +380,16 @@ discard block  | 
                                                    ||
| 380 | 380 | public function getRoute($slug = '', $absolute = FALSE, $params = [])  | 
                                                        
| 381 | 381 |      { | 
                                                        
| 382 | 382 |          if (strlen($slug) === 0) { | 
                                                        
| 383 | - return ($absolute) ? Request::getInstance()->getRootUrl() . '/' : '/';  | 
                                                        |
| 383 | + return ($absolute) ? Request::getInstance()->getRootUrl().'/' : '/';  | 
                                                        |
| 384 | 384 | }  | 
                                                        
| 385 | 385 |          if (NULL === $slug || !array_key_exists($slug, $this->slugs)) { | 
                                                        
| 386 | 386 |              throw new RouterException(_("No existe la ruta especificada")); | 
                                                        
| 387 | 387 | }  | 
                                                        
| 388 | - $url = ($absolute) ? Request::getInstance()->getRootUrl() . $this->slugs[$slug] : $this->slugs[$slug];  | 
                                                        |
| 388 | + $url = ($absolute) ? Request::getInstance()->getRootUrl().$this->slugs[$slug] : $this->slugs[$slug];  | 
                                                        |
| 389 | 389 |          if (!empty($params)) foreach ($params as $key => $value) { | 
                                                        
| 390 | -            $url = str_replace("{" . $key . "}", $value, $url); | 
                                                        |
| 390 | +            $url = str_replace("{".$key."}", $value, $url); | 
                                                        |
| 391 | 391 |          } elseif (!empty($this->routing[$this->slugs[$slug]]["default"])) { | 
                                                        
| 392 | - $url = ($absolute) ? Request::getInstance()->getRootUrl() . $this->routing[$this->slugs[$slug]]["default"] : $this->routing[$this->slugs[$slug]]["default"];  | 
                                                        |
| 392 | + $url = ($absolute) ? Request::getInstance()->getRootUrl().$this->routing[$this->slugs[$slug]]["default"] : $this->routing[$this->slugs[$slug]]["default"];  | 
                                                        |
| 393 | 393 | }  | 
                                                        
| 394 | 394 | |
| 395 | 395 |          return preg_replace('/(GET|POST|PUT|DELETE|ALL)\#\|\#/', '', $url); | 
                                                        
@@ -407,7 +407,7 @@ discard block  | 
                                                    ||
| 407 | 407 |              if (preg_match('/^\/admin(\/|$)/', $routePattern)) { | 
                                                        
| 408 | 408 |                  if (preg_match('/^\\\?PSFS/', $params["class"])) { | 
                                                        
| 409 | 409 | $profile = "superadmin";  | 
                                                        
| 410 | -                } else { | 
                                                        |
| 410 | +                }else { | 
                                                        |
| 411 | 411 | $profile = "admin";  | 
                                                        
| 412 | 412 | }  | 
                                                        
| 413 | 413 |                  if (!empty($params["default"]) && preg_match('/(GET|ALL)/i', $httpMethod)) { | 
                                                        
@@ -459,17 +459,17 @@ discard block  | 
                                                    ||
| 459 | 459 | */  | 
                                                        
| 460 | 460 | protected function executeCachedRoute($route, $action, $class, $params = NULL)  | 
                                                        
| 461 | 461 |      { | 
                                                        
| 462 | -        Logger::log('Executing route ' . $route, LOG_INFO); | 
                                                        |
| 462 | +        Logger::log('Executing route '.$route, LOG_INFO); | 
                                                        |
| 463 | 463 |          Security::getInstance()->setSessionKey("__CACHE__", $action); | 
                                                        
| 464 | 464 | $cache = Cache::needCache();  | 
                                                        
| 465 | 465 | $execute = TRUE;  | 
                                                        
| 466 | 466 |          if (FALSE !== $cache && Config::getInstance()->getDebugMode() === FALSE) { | 
                                                        
| 467 | 467 | $cacheDataName = $this->cache->getRequestCacheHash();  | 
                                                        
| 468 | -            $cachedData = $this->cache->readFromCache("templates" . DIRECTORY_SEPARATOR . $cacheDataName, | 
                                                        |
| 469 | -                $cache, function () {}); | 
                                                        |
| 468 | +            $cachedData = $this->cache->readFromCache("templates".DIRECTORY_SEPARATOR.$cacheDataName, | 
                                                        |
| 469 | +                $cache, function() {}); | 
                                                        |
| 470 | 470 |              if (NULL !== $cachedData) { | 
                                                        
| 471 | -                $headers = $this->cache->readFromCache("templates" . DIRECTORY_SEPARATOR . $cacheDataName . ".headers", | 
                                                        |
| 472 | -                    $cache, function () {}, Cache::JSON); | 
                                                        |
| 471 | +                $headers = $this->cache->readFromCache("templates".DIRECTORY_SEPARATOR.$cacheDataName.".headers", | 
                                                        |
| 472 | +                    $cache, function() {}, Cache::JSON); | 
                                                        |
| 473 | 473 | Template::getInstance()->renderCache($cachedData, $headers);  | 
                                                        
| 474 | 474 | $execute = FALSE;  | 
                                                        
| 475 | 475 | }  | 
                                                        
@@ -515,7 +515,7 @@ discard block  | 
                                                    ||
| 515 | 515 | $translations = array();  | 
                                                        
| 516 | 516 |          if (file_exists($absoluteTranslationFileName)) { | 
                                                        
| 517 | 517 | include($absoluteTranslationFileName);  | 
                                                        
| 518 | -        } else { | 
                                                        |
| 518 | +        }else { | 
                                                        |
| 519 | 519 | Cache::getInstance()->storeData($absoluteTranslationFileName, "<?php \$translations = array();\n", Cache::TEXT, TRUE);  | 
                                                        
| 520 | 520 | }  | 
                                                        
| 521 | 521 | |
@@ -51,7 +51,7 @@ discard block  | 
                                                    ||
| 51 | 51 | }  | 
                                                        
| 52 | 52 | $this->user = (array_key_exists(self::USER_ID_TOKEN, $this->session)) ? unserialize($this->session[self::USER_ID_TOKEN]) : NULL;  | 
                                                        
| 53 | 53 | $this->admin = (array_key_exists(self::ADMIN_ID_TOKEN, $this->session)) ? unserialize($this->session[self::ADMIN_ID_TOKEN]) : NULL;  | 
                                                        
| 54 | -        if(null === $this->admin) { | 
                                                        |
| 54 | +        if (null === $this->admin) { | 
                                                        |
| 55 | 55 | $this->checkAdmin();  | 
                                                        
| 56 | 56 | }  | 
                                                        
| 57 | 57 | }  | 
                                                        
@@ -110,13 +110,13 @@ discard block  | 
                                                    ||
| 110 | 110 | public static function save($user)  | 
                                                        
| 111 | 111 |      { | 
                                                        
| 112 | 112 | $admins = array();  | 
                                                        
| 113 | -        if (file_exists(CONFIG_DIR . DIRECTORY_SEPARATOR . 'admins.json')) { | 
                                                        |
| 114 | - $admins = json_decode(file_get_contents(CONFIG_DIR . DIRECTORY_SEPARATOR . 'admins.json'), TRUE);  | 
                                                        |
| 113 | +        if (file_exists(CONFIG_DIR.DIRECTORY_SEPARATOR.'admins.json')) { | 
                                                        |
| 114 | + $admins = json_decode(file_get_contents(CONFIG_DIR.DIRECTORY_SEPARATOR.'admins.json'), TRUE);  | 
                                                        |
| 115 | 115 | }  | 
                                                        
| 116 | - $admins[$user['username']]['hash'] = sha1($user['username'] . $user['password']);  | 
                                                        |
| 116 | + $admins[$user['username']]['hash'] = sha1($user['username'].$user['password']);  | 
                                                        |
| 117 | 117 | $admins[$user['username']]['profile'] = $user['profile'];  | 
                                                        
| 118 | 118 | |
| 119 | - return (FALSE !== file_put_contents(CONFIG_DIR . DIRECTORY_SEPARATOR . 'admins.json', json_encode($admins, JSON_PRETTY_PRINT)));  | 
                                                        |
| 119 | + return (FALSE !== file_put_contents(CONFIG_DIR.DIRECTORY_SEPARATOR.'admins.json', json_encode($admins, JSON_PRETTY_PRINT)));  | 
                                                        |
| 120 | 120 | }  | 
                                                        
| 121 | 121 | |
| 122 | 122 | /**  | 
                                                        
@@ -150,8 +150,8 @@ discard block  | 
                                                    ||
| 150 | 150 | public function getAdmins()  | 
                                                        
| 151 | 151 |      { | 
                                                        
| 152 | 152 | $admins = array();  | 
                                                        
| 153 | -        if (file_exists(CONFIG_DIR . DIRECTORY_SEPARATOR . 'admins.json')) { | 
                                                        |
| 154 | - $admins = json_decode(file_get_contents(CONFIG_DIR . DIRECTORY_SEPARATOR . 'admins.json'), TRUE);  | 
                                                        |
| 153 | +        if (file_exists(CONFIG_DIR.DIRECTORY_SEPARATOR.'admins.json')) { | 
                                                        |
| 154 | + $admins = json_decode(file_get_contents(CONFIG_DIR.DIRECTORY_SEPARATOR.'admins.json'), TRUE);  | 
                                                        |
| 155 | 155 | }  | 
                                                        
| 156 | 156 | |
| 157 | 157 | return $admins;  | 
                                                        
@@ -171,7 +171,7 @@ discard block  | 
                                                    ||
| 171 | 171 |          Logger::log('Checking admin session'); | 
                                                        
| 172 | 172 |          if (!$this->authorized) { | 
                                                        
| 173 | 173 | $request = Request::getInstance();  | 
                                                        
| 174 | -            if (!file_exists(CONFIG_DIR . DIRECTORY_SEPARATOR . 'admins.json')) { | 
                                                        |
| 174 | +            if (!file_exists(CONFIG_DIR.DIRECTORY_SEPARATOR.'admins.json')) { | 
                                                        |
| 175 | 175 | //Si no hay fichero de usuarios redirigimos directamente al gestor  | 
                                                        
| 176 | 176 | return UserController::getInstance()->adminers();  | 
                                                        
| 177 | 177 | }  | 
                                                        
@@ -184,8 +184,8 @@ discard block  | 
                                                    ||
| 184 | 184 | }  | 
                                                        
| 185 | 185 |              if (!empty($user) && !empty($admins[$user])) { | 
                                                        
| 186 | 186 | $auth = $admins[$user]['hash'];  | 
                                                        
| 187 | - $this->authorized = ($auth == sha1($user . $pass));  | 
                                                        |
| 188 | -                if($this->authorized) { | 
                                                        |
| 187 | + $this->authorized = ($auth == sha1($user.$pass));  | 
                                                        |
| 188 | +                if ($this->authorized) { | 
                                                        |
| 189 | 189 | $this->admin = array(  | 
                                                        
| 190 | 190 | 'alias' => $user,  | 
                                                        
| 191 | 191 | 'profile' => $admins[$user]['profile'],  | 
                                                        
@@ -406,12 +406,12 @@ discard block  | 
                                                    ||
| 406 | 406 | $axis = 0;  | 
                                                        
| 407 | 407 | $parts = array();  | 
                                                        
| 408 | 408 |          try { | 
                                                        
| 409 | - $partLength = floor(strlen($token) / 10);  | 
                                                        |
| 410 | -            for ($i = 0, $ct = ceil(strlen($token) / $partLength); $i < $ct; $i++) { | 
                                                        |
| 409 | + $partLength = floor(strlen($token)/10);  | 
                                                        |
| 410 | +            for ($i = 0, $ct = ceil(strlen($token)/$partLength); $i < $ct; $i++) { | 
                                                        |
| 411 | 411 | $parts[] = substr($token, $axis, $partLength);  | 
                                                        
| 412 | 412 | $axis += $partLength;  | 
                                                        
| 413 | 413 | }  | 
                                                        
| 414 | -        } catch (\Exception $e) { | 
                                                        |
| 414 | +        }catch (\Exception $e) { | 
                                                        |
| 415 | 415 | $partLength = 0;  | 
                                                        
| 416 | 416 | }  | 
                                                        
| 417 | 417 | |
@@ -451,7 +451,7 @@ discard block  | 
                                                    ||
| 451 | 451 | $decoded = NULL;  | 
                                                        
| 452 | 452 | list($partLength, $parts) = self::extractTokenParts($token);  | 
                                                        
| 453 | 453 | list($ts, $mod) = self::extractTsAndMod($parts, $partLength);  | 
                                                        
| 454 | - $hashMod = substr(strtoupper(sha1($module)), strlen($ts) / 2, strlen($ts) * 2);  | 
                                                        |
| 454 | + $hashMod = substr(strtoupper(sha1($module)), strlen($ts)/2, strlen($ts)*2);  | 
                                                        |
| 455 | 455 |          if (time() - (integer)$ts < 300 && $hashMod === $mod) { | 
                                                        
| 456 | 456 |              $decoded = implode('', $parts); | 
                                                        
| 457 | 457 | }  | 
                                                        
@@ -468,16 +468,16 @@ discard block  | 
                                                    ||
| 468 | 468 | public static function generateToken($secret, $module = 'PSFS')  | 
                                                        
| 469 | 469 |      { | 
                                                        
| 470 | 470 | $ts = time();  | 
                                                        
| 471 | - $hashModule = substr(strtoupper(sha1($module)), strlen($ts) / 2, strlen($ts) * 2);  | 
                                                        |
| 471 | + $hashModule = substr(strtoupper(sha1($module)), strlen($ts)/2, strlen($ts)*2);  | 
                                                        |
| 472 | 472 |          $hash = hash('sha256', $secret); | 
                                                        
| 473 | - $insert = floor(strlen($hash) / strlen($ts));  | 
                                                        |
| 473 | + $insert = floor(strlen($hash)/strlen($ts));  | 
                                                        |
| 474 | 474 | $j = 0;  | 
                                                        
| 475 | 475 | $token = '';  | 
                                                        
| 476 | 476 |          for ($i = 0, $ct = strlen($ts); $i < $ct; $i++) { | 
                                                        
| 477 | - $token .= substr($ts, $i, 1) . substr($hash, $j, $insert) . substr($hashModule, $i, 2);  | 
                                                        |
| 477 | + $token .= substr($ts, $i, 1).substr($hash, $j, $insert).substr($hashModule, $i, 2);  | 
                                                        |
| 478 | 478 | $j += $insert;  | 
                                                        
| 479 | 479 | }  | 
                                                        
| 480 | - $token .= substr($hash, ($insert * strlen($ts)), strlen($hash) - ($insert * strlen($ts)));  | 
                                                        |
| 480 | + $token .= substr($hash, ($insert*strlen($ts)), strlen($hash) - ($insert*strlen($ts)));  | 
                                                        |
| 481 | 481 | return $token;  | 
                                                        
| 482 | 482 | }  | 
                                                        
| 483 | 483 | |
@@ -33,10 +33,10 @@  | 
                                                    ||
| 33 | 33 | */  | 
                                                        
| 34 | 34 |          private static function __init($instance) { | 
                                                        
| 35 | 35 | $loaded = false;  | 
                                                        
| 36 | -            if(method_exists($instance, 'isLoaded')) { | 
                                                        |
| 36 | +            if (method_exists($instance, 'isLoaded')) { | 
                                                        |
| 37 | 37 | $loaded = $instance->isLoaded();  | 
                                                        
| 38 | 38 | }  | 
                                                        
| 39 | -            if(false === $loaded && method_exists($instance, "init")) { | 
                                                        |
| 39 | +            if (false === $loaded && method_exists($instance, "init")) { | 
                                                        |
| 40 | 40 | $instance->init();  | 
                                                        
| 41 | 41 | }  | 
                                                        
| 42 | 42 | }  | 
                                                        
@@ -54,13 +54,13 @@ discard block  | 
                                                    ||
| 54 | 54 | */  | 
                                                        
| 55 | 55 | public static function constructInyectableInstance($variable, $singleton, $classNameSpace, $calledClass)  | 
                                                        
| 56 | 56 |      { | 
                                                        
| 57 | -        Logger::log('Create inyectable instance for ' . $classNameSpace); | 
                                                        |
| 57 | +        Logger::log('Create inyectable instance for '.$classNameSpace); | 
                                                        |
| 58 | 58 | $reflector = new \ReflectionClass($calledClass);  | 
                                                        
| 59 | 59 | $property = $reflector->getProperty($variable);  | 
                                                        
| 60 | 60 | $varInstanceType = (null === $classNameSpace) ? InjectorHelper::extractVarType($property->getDocComment()) : $classNameSpace;  | 
                                                        
| 61 | 61 |          if (true === $singleton && method_exists($varInstanceType, "getInstance")) { | 
                                                        
| 62 | 62 | $instance = $varInstanceType::getInstance();  | 
                                                        
| 63 | -        } else { | 
                                                        |
| 63 | +        }else { | 
                                                        |
| 64 | 64 | $instance = new $varInstanceType();  | 
                                                        
| 65 | 65 | }  | 
                                                        
| 66 | 66 | return $instance;  | 
                                                        
@@ -74,7 +74,7 @@ discard block  | 
                                                    ||
| 74 | 74 | public static function getClassProperties($class)  | 
                                                        
| 75 | 75 |      { | 
                                                        
| 76 | 76 | $properties = [];  | 
                                                        
| 77 | -        Logger::log('Extracting annotations properties from class ' . $class); | 
                                                        |
| 77 | +        Logger::log('Extracting annotations properties from class '.$class); | 
                                                        |
| 78 | 78 | $selfReflector = new \ReflectionClass($class);  | 
                                                        
| 79 | 79 |          if (false !== $selfReflector->getParentClass()) { | 
                                                        
| 80 | 80 | $properties = self::getClassProperties($selfReflector->getParentClass()->getName());  | 
                                                        
@@ -20,7 +20,7 @@ discard block  | 
                                                    ||
| 20 | 20 | public static function getClassToCall($action)  | 
                                                        
| 21 | 21 |      { | 
                                                        
| 22 | 22 |          Logger::log('Getting class to call for executing the request action', LOG_DEBUG, $action); | 
                                                        
| 23 | - $actionClass = class_exists($action["class"]) ? $action["class"] : "\\" . $action["class"];  | 
                                                        |
| 23 | + $actionClass = class_exists($action["class"]) ? $action["class"] : "\\".$action["class"];  | 
                                                        |
| 24 | 24 | $class = (method_exists($actionClass, "getInstance")) ? $actionClass::getInstance() : new $actionClass;  | 
                                                        
| 25 | 25 | return $class;  | 
                                                        
| 26 | 26 | }  | 
                                                        
@@ -106,7 +106,7 @@ discard block  | 
                                                    ||
| 106 | 106 | $expr = preg_quote($expr, '/');  | 
                                                        
| 107 | 107 |          $expr = str_replace('###', '(.*)', $expr); | 
                                                        
| 108 | 108 |          $expr2 = preg_replace('/\(\.\*\)$/', '', $expr); | 
                                                        
| 109 | -        $matched = preg_match('/^' . $expr . '\/?$/i', $path) || preg_match('/^' . $expr2 . '?$/i', $path); | 
                                                        |
| 109 | +        $matched = preg_match('/^'.$expr.'\/?$/i', $path) || preg_match('/^'.$expr2.'?$/i', $path); | 
                                                        |
| 110 | 110 | return $matched;  | 
                                                        
| 111 | 111 | }  | 
                                                        
| 112 | 112 | |
@@ -117,8 +117,8 @@ discard block  | 
                                                    ||
| 117 | 117 | */  | 
                                                        
| 118 | 118 | public static function extractDomainInfo(\ReflectionClass $class, $domain)  | 
                                                        
| 119 | 119 |      { | 
                                                        
| 120 | - $path = dirname($class->getFileName()) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR;  | 
                                                        |
| 121 | - $path = realpath($path) . DIRECTORY_SEPARATOR;  | 
                                                        |
| 120 | + $path = dirname($class->getFileName()).DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR;  | 
                                                        |
| 121 | + $path = realpath($path).DIRECTORY_SEPARATOR;  | 
                                                        |
| 122 | 122 | $tpl_path = "templates";  | 
                                                        
| 123 | 123 | $public_path = "public";  | 
                                                        
| 124 | 124 | $model_path = "models";  | 
                                                        
@@ -128,12 +128,12 @@ discard block  | 
                                                    ||
| 128 | 128 | $model_path = ucfirst($model_path);  | 
                                                        
| 129 | 129 | }  | 
                                                        
| 130 | 130 |          if ($class->hasConstant("TPL")) { | 
                                                        
| 131 | -            $tpl_path .= DIRECTORY_SEPARATOR . $class->getConstant("TPL"); | 
                                                        |
| 131 | +            $tpl_path .= DIRECTORY_SEPARATOR.$class->getConstant("TPL"); | 
                                                        |
| 132 | 132 | }  | 
                                                        
| 133 | 133 | return [  | 
                                                        
| 134 | - "template" => $path . $tpl_path,  | 
                                                        |
| 135 | - "model" => $path . $model_path,  | 
                                                        |
| 136 | - "public" => $path . $public_path,  | 
                                                        |
| 134 | + "template" => $path.$tpl_path,  | 
                                                        |
| 135 | + "model" => $path.$model_path,  | 
                                                        |
| 136 | + "public" => $path.$public_path,  | 
                                                        |
| 137 | 137 | ];  | 
                                                        
| 138 | 138 | }  | 
                                                        
| 139 | 139 | |
@@ -155,9 +155,9 @@ discard block  | 
                                                    ||
| 155 | 155 |          if (count($parameters) > 0) foreach ($parameters as $param) { | 
                                                        
| 156 | 156 |              if ($param->isOptional() && !is_array($param->getDefaultValue())) { | 
                                                        
| 157 | 157 | $params[$param->getName()] = $param->getDefaultValue();  | 
                                                        
| 158 | -                $default = str_replace('{' . $param->getName() . '}', $param->getDefaultValue(), $regex); | 
                                                        |
| 158 | +                $default = str_replace('{'.$param->getName().'}', $param->getDefaultValue(), $regex); | 
                                                        |
| 159 | 159 | }  | 
                                                        
| 160 | - } else $default = $regex;  | 
                                                        |
| 160 | + }else $default = $regex;  | 
                                                        |
| 161 | 161 | |
| 162 | 162 | return array($regex, $default, $params);  | 
                                                        
| 163 | 163 | }  | 
                                                        
@@ -212,10 +212,10 @@ discard block  | 
                                                    ||
| 212 | 212 |      { | 
                                                        
| 213 | 213 | $is_enabled = true;  | 
                                                        
| 214 | 214 | // For non api routes  | 
                                                        
| 215 | -        if(strlen($api) > 0 && preg_match('/admin/i', $route)) { | 
                                                        |
| 215 | +        if (strlen($api) > 0 && preg_match('/admin/i', $route)) { | 
                                                        |
| 216 | 216 | // If route is for api, check if admin is enabled in config  | 
                                                        
| 217 | 217 |              $admin_enabled = Config::getInstance()->get('api.admin'); | 
                                                        
| 218 | -            if(empty($admin_enabled)) { | 
                                                        |
| 218 | +            if (empty($admin_enabled)) { | 
                                                        |
| 219 | 219 | $is_enabled = false;  | 
                                                        
| 220 | 220 | }  | 
                                                        
| 221 | 221 | }  | 
                                                        
@@ -239,8 +239,8 @@ discard block  | 
                                                    ||
| 239 | 239 |                  $default = str_replace('{__API__}', $api, $default); | 
                                                        
| 240 | 240 | }  | 
                                                        
| 241 | 241 | $httpMethod = RouterHelper::extractReflectionHttpMethod($docComments);  | 
                                                        
| 242 | -            if(self::checkCanAddRoute($regex, $api)) { | 
                                                        |
| 243 | - $route = $httpMethod . "#|#" . $regex;  | 
                                                        |
| 242 | +            if (self::checkCanAddRoute($regex, $api)) { | 
                                                        |
| 243 | + $route = $httpMethod."#|#".$regex;  | 
                                                        |
| 244 | 244 | $info = [  | 
                                                        
| 245 | 245 | "method" => $method->getName(),  | 
                                                        
| 246 | 246 | "params" => $params,  | 
                                                        
@@ -267,7 +267,7 @@ discard block  | 
                                                    ||
| 267 | 267 |              $default = Config::getInstance()->get('admin_action') ?: 'admin-login'; | 
                                                        
| 268 | 268 | |
| 269 | 269 | }  | 
                                                        
| 270 | -        if(null !== $default) { | 
                                                        |
| 270 | +        if (null !== $default) { | 
                                                        |
| 271 | 271 | return Router::getInstance()->execute(Router::getInstance()->getRoute($default));  | 
                                                        
| 272 | 272 | }  | 
                                                        
| 273 | 273 | return null;  | 
                                                        
@@ -20,7 +20,7 @@ discard block  | 
                                                    ||
| 20 | 20 | |
| 21 | 21 | public function __construct()  | 
                                                        
| 22 | 22 |      { | 
                                                        
| 23 | - Logger::log(get_class($this) . ' constructor invoked');  | 
                                                        |
| 23 | + Logger::log(get_class($this).' constructor invoked');  | 
                                                        |
| 24 | 24 | $this->init();  | 
                                                        
| 25 | 25 | }  | 
                                                        
| 26 | 26 | |
@@ -90,14 +90,14 @@ discard block  | 
                                                    ||
| 90 | 90 | $calledClass = get_called_class();  | 
                                                        
| 91 | 91 |          try { | 
                                                        
| 92 | 92 | $instance = InjectorHelper::constructInyectableInstance($variable, $singleton, $classNameSpace, $calledClass);  | 
                                                        
| 93 | - $setter = "set" . ucfirst($variable);  | 
                                                        |
| 93 | + $setter = "set".ucfirst($variable);  | 
                                                        |
| 94 | 94 |              if (method_exists($calledClass, $setter)) { | 
                                                        
| 95 | 95 | $this->$setter($instance);  | 
                                                        
| 96 | -            } else { | 
                                                        |
| 96 | +            }else { | 
                                                        |
| 97 | 97 | $this->$variable = $instance;  | 
                                                        
| 98 | 98 | }  | 
                                                        
| 99 | -        } catch (\Exception $e) { | 
                                                        |
| 100 | - Logger::log($e->getMessage() . ': ' . $e->getFile() . ' [' . $e->getLine() . ']', LOG_ERR);  | 
                                                        |
| 99 | +        }catch (\Exception $e) { | 
                                                        |
| 100 | + Logger::log($e->getMessage().': '.$e->getFile().' ['.$e->getLine().']', LOG_ERR);  | 
                                                        |
| 101 | 101 | }  | 
                                                        
| 102 | 102 | return $this;  | 
                                                        
| 103 | 103 | }  | 
                                                        
@@ -108,7 +108,7 @@ discard block  | 
                                                    ||
| 108 | 108 | public function init()  | 
                                                        
| 109 | 109 |      { | 
                                                        
| 110 | 110 |          if (!$this->isLoaded()) { | 
                                                        
| 111 | - $cacheFilename = "reflections" . DIRECTORY_SEPARATOR . sha1(get_class($this)) . ".json";  | 
                                                        |
| 111 | + $cacheFilename = "reflections".DIRECTORY_SEPARATOR.sha1(get_class($this)).".json";  | 
                                                        |
| 112 | 112 | /** @var \PSFS\base\Cache $cacheService */  | 
                                                        
| 113 | 113 | $cacheService = Cache::getInstance();  | 
                                                        
| 114 | 114 | /** @var \PSFS\base\config\Config $configService */  | 
                                                        
@@ -123,8 +123,8 @@ discard block  | 
                                                    ||
| 123 | 123 | $this->load($property, true, $class);  | 
                                                        
| 124 | 124 | }  | 
                                                        
| 125 | 125 | $this->setLoaded();  | 
                                                        
| 126 | -        } else { | 
                                                        |
| 127 | - Logger::log(get_class($this) . ' already loaded', LOG_INFO);  | 
                                                        |
| 126 | +        }else { | 
                                                        |
| 127 | + Logger::log(get_class($this).' already loaded', LOG_INFO);  | 
                                                        |
| 128 | 128 | }  | 
                                                        
| 129 | 129 | }  | 
                                                        
| 130 | 130 | }  |