Passed
Push — master ( ad40bf...cd8dc0 )
by Fran
09:35
created
src/base/Router.php 1 patch
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -62,8 +62,8 @@  discard block
 block discarded – undo
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);
66
-        $this->domains = $this->cache->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . "domains.json", $this->cacheType, TRUE);
65
+        list($this->routing, $this->slugs) = $this->cache->getDataFromFile(CONFIG_DIR.DIRECTORY_SEPARATOR."urls.json", $this->cacheType, TRUE);
66
+        $this->domains = $this->cache->getDataFromFile(CONFIG_DIR.DIRECTORY_SEPARATOR."domains.json", $this->cacheType, TRUE);
67 67
         if (empty($this->routing) || Config::getInstance()->getDebugMode()) {
68 68
             $this->debugLoad();
69 69
         }
@@ -101,11 +101,11 @@  discard block
 block discarded – undo
101 101
                 "success" => FALSE,
102 102
                 "error" => $e->getMessage(),
103 103
             )), 'application/json');
104
-        } else {
104
+        }else {
105 105
             $not_found_rouote = Config::getParam('route.404');
106
-            if(null !== $not_found_rouote) {
106
+            if (null !== $not_found_rouote) {
107 107
                 Request::getInstance()->redirect($this->getRoute($not_found_rouote, true));
108
-            } else {
108
+            }else {
109 109
                 return $template->render('error.html.twig', array(
110 110
                     'exception' => $e,
111 111
                     'trace' => $e->getTraceAsString(),
@@ -164,12 +164,12 @@  discard block
 block discarded – undo
164 164
             SecurityHelper::checkRestrictedAccess($route);
165 165
             //Search action and execute
166 166
             $this->searchAction($route);
167
-        } catch (AccessDeniedException $e) {
167
+        }catch (AccessDeniedException $e) {
168 168
             Logger::log(_('Solicitamos credenciales de acceso a zona restringida'));
169 169
             return Admin::staticAdminLogon($route);
170
-        } catch (RouterException $r) {
170
+        }catch (RouterException $r) {
171 171
             Logger::log($r->getMessage(), LOG_WARNING);
172
-        } catch (\Exception $e) {
172
+        }catch (\Exception $e) {
173 173
             Logger::log($e->getMessage(), LOG_ERR);
174 174
             throw $e;
175 175
         }
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
      */
187 187
     protected function searchAction($route)
188 188
     {
189
-        Logger::log('Searching action to execute: ' . $route, LOG_INFO);
189
+        Logger::log('Searching action to execute: '.$route, LOG_INFO);
190 190
         //Revisamos si tenemos la ruta registrada
191 191
         $parts = parse_url($route);
192 192
         $path = (array_key_exists('path', $parts)) ? $parts['path'] : $route;
@@ -200,7 +200,7 @@  discard block
 block discarded – undo
200 200
                 $class = RouterHelper::getClassToCall($action);
201 201
                 try {
202 202
                     $this->executeCachedRoute($route, $action, $class, $get);
203
-                } catch (\Exception $e) {
203
+                }catch (\Exception $e) {
204 204
                     Logger::log($e->getMessage(), LOG_ERR);
205 205
                     throw new \RuntimeException($e->getMessage(), 404, $e);
206 206
                 }
@@ -223,7 +223,7 @@  discard block
 block discarded – undo
223 223
      */
224 224
     private function getExternalModules() {
225 225
         $externalModules = Config::getParam('modules.extend', '');
226
-        if(Config::getParam('psfs.auth', false)) {
226
+        if (Config::getParam('psfs.auth', false)) {
227 227
             $externalModules .= ',psfs/auth';
228 228
         }
229 229
         return $externalModules;
@@ -240,17 +240,17 @@  discard block
 block discarded – undo
240 240
             $externalModules = explode(',', $externalModules);
241 241
             foreach ($externalModules as &$module) {
242 242
                 $module = preg_replace('/(\\\|\/)/', DIRECTORY_SEPARATOR, $module);
243
-                $externalModulePath = VENDOR_DIR . DIRECTORY_SEPARATOR . $module . DIRECTORY_SEPARATOR . 'src';
243
+                $externalModulePath = VENDOR_DIR.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.'src';
244 244
                 if (file_exists($externalModulePath)) {
245 245
                     $externalModule = $this->finder->directories()->in($externalModulePath)->depth(0);
246 246
                     if (!empty($externalModule)) {
247 247
                         foreach ($externalModule as $modulePath) {
248 248
                             $extModule = $modulePath->getBasename();
249
-                            $moduleAutoloader = realpath($externalModulePath . DIRECTORY_SEPARATOR . $extModule . DIRECTORY_SEPARATOR . 'autoload.php');
249
+                            $moduleAutoloader = realpath($externalModulePath.DIRECTORY_SEPARATOR.$extModule.DIRECTORY_SEPARATOR.'autoload.php');
250 250
                             if (file_exists($moduleAutoloader)) {
251 251
                                 @include $moduleAutoloader;
252 252
                                 if ($hydrateRoute) {
253
-                                    $this->routing = $this->inspectDir($externalModulePath . DIRECTORY_SEPARATOR . $extModule, '\\' . $extModule, $this->routing);
253
+                                    $this->routing = $this->inspectDir($externalModulePath.DIRECTORY_SEPARATOR.$extModule, '\\'.$extModule, $this->routing);
254 254
                                 }
255 255
                             }
256 256
                         }
@@ -273,10 +273,10 @@  discard block
 block discarded – undo
273 273
             $modules = $this->finder->directories()->in($modulesPath)->depth(0);
274 274
             foreach ($modules as $modulePath) {
275 275
                 $module = $modulePath->getBasename();
276
-                $this->routing = $this->inspectDir($modulesPath . DIRECTORY_SEPARATOR . $module, $module, $this->routing);
276
+                $this->routing = $this->inspectDir($modulesPath.DIRECTORY_SEPARATOR.$module, $module, $this->routing);
277 277
             }
278 278
         }
279
-        $this->cache->storeData(CONFIG_DIR . DIRECTORY_SEPARATOR . "domains.json", $this->domains, Cache::JSON, TRUE);
279
+        $this->cache->storeData(CONFIG_DIR.DIRECTORY_SEPARATOR."domains.json", $this->domains, Cache::JSON, TRUE);
280 280
     }
281 281
 
282 282
     /**
@@ -291,7 +291,7 @@  discard block
 block discarded – undo
291 291
             $home_params = NULL;
292 292
             foreach ($this->routing as $pattern => $params) {
293 293
                 list($method, $route) = RouterHelper::extractHttpRoute($pattern);
294
-                if (preg_match("/" . preg_quote($route, "/") . "$/i", "/" . $home)) {
294
+                if (preg_match("/".preg_quote($route, "/")."$/i", "/".$home)) {
295 295
                     $home_params = $params;
296 296
                 }
297 297
             }
@@ -316,7 +316,7 @@  discard block
 block discarded – undo
316 316
         $files = $this->finder->files()->in($origen)->path('/(controller|api)/i')->depth(1)->name("*.php");
317 317
         foreach ($files as $file) {
318 318
             $filename = str_replace("/", '\\', str_replace($origen, '', $file->getPathname()));
319
-            $routing = $this->addRouting($namespace . str_replace('.php', '', $filename), $routing, $namespace);
319
+            $routing = $this->addRouting($namespace.str_replace('.php', '', $filename), $routing, $namespace);
320 320
         }
321 321
         $this->finder = new Finder();
322 322
 
@@ -386,7 +386,7 @@  discard block
 block discarded – undo
386 386
             if (!$this->domains) {
387 387
                 $this->domains = [];
388 388
             }
389
-            $domain = "@" . $class->getConstant("DOMAIN") . "/";
389
+            $domain = "@".$class->getConstant("DOMAIN")."/";
390 390
             if (!array_key_exists($domain, $this->domains)) {
391 391
                 $this->domains[$domain] = RouterHelper::extractDomainInfo($class, $domain);
392 392
             }
@@ -401,11 +401,11 @@  discard block
 block discarded – undo
401 401
      */
402 402
     public function simpatize()
403 403
     {
404
-        $translationFileName = "translations" . DIRECTORY_SEPARATOR . "routes_translations.php";
405
-        $absoluteTranslationFileName = CACHE_DIR . DIRECTORY_SEPARATOR . $translationFileName;
404
+        $translationFileName = "translations".DIRECTORY_SEPARATOR."routes_translations.php";
405
+        $absoluteTranslationFileName = CACHE_DIR.DIRECTORY_SEPARATOR.$translationFileName;
406 406
         $this->generateSlugs($absoluteTranslationFileName);
407 407
         GeneratorHelper::createDir(CONFIG_DIR);
408
-        Cache::getInstance()->storeData(CONFIG_DIR . DIRECTORY_SEPARATOR . "urls.json", array($this->routing, $this->slugs), Cache::JSON, TRUE);
408
+        Cache::getInstance()->storeData(CONFIG_DIR.DIRECTORY_SEPARATOR."urls.json", array($this->routing, $this->slugs), Cache::JSON, TRUE);
409 409
 
410 410
         return $this;
411 411
     }
@@ -423,16 +423,16 @@  discard block
 block discarded – undo
423 423
     public function getRoute($slug = '', $absolute = FALSE, $params = [])
424 424
     {
425 425
         if (strlen($slug) === 0) {
426
-            return ($absolute) ? Request::getInstance()->getRootUrl() . '/' : '/';
426
+            return ($absolute) ? Request::getInstance()->getRootUrl().'/' : '/';
427 427
         }
428 428
         if (!is_array($this->slugs) || !array_key_exists($slug, $this->slugs)) {
429 429
             throw new RouterException(_("No existe la ruta especificada"));
430 430
         }
431
-        $url = ($absolute) ? Request::getInstance()->getRootUrl() . $this->slugs[$slug] : $this->slugs[$slug];
431
+        $url = ($absolute) ? Request::getInstance()->getRootUrl().$this->slugs[$slug] : $this->slugs[$slug];
432 432
         if (!empty($params)) foreach ($params as $key => $value) {
433
-            $url = str_replace("{" . $key . "}", $value, $url);
433
+            $url = str_replace("{".$key."}", $value, $url);
434 434
         } elseif (!empty($this->routing[$this->slugs[$slug]]["default"])) {
435
-            $url = ($absolute) ? Request::getInstance()->getRootUrl() . $this->routing[$this->slugs[$slug]]["default"] : $this->routing[$this->slugs[$slug]]["default"];
435
+            $url = ($absolute) ? Request::getInstance()->getRootUrl().$this->routing[$this->slugs[$slug]]["default"] : $this->routing[$this->slugs[$slug]]["default"];
436 436
         }
437 437
 
438 438
         return preg_replace('/(GET|POST|PUT|DELETE|ALL)\#\|\#/', '', $url);
@@ -477,18 +477,18 @@  discard block
 block discarded – undo
477 477
      */
478 478
     protected function executeCachedRoute($route, $action, $class, $params = NULL)
479 479
     {
480
-        Logger::log('Executing route ' . $route, LOG_INFO);
480
+        Logger::log('Executing route '.$route, LOG_INFO);
481 481
         Security::getInstance()->setSessionKey("__CACHE__", $action);
482 482
         $cache = Cache::needCache();
483 483
         $execute = TRUE;
484 484
         if (FALSE !== $cache && Config::getInstance()->getDebugMode() === FALSE) {
485 485
             list($path, $cacheDataName) = $this->cache->getRequestCacheHash();
486
-            $cachedData = $this->cache->readFromCache("json" . DIRECTORY_SEPARATOR . $path . $cacheDataName,
487
-                $cache, function () {
486
+            $cachedData = $this->cache->readFromCache("json".DIRECTORY_SEPARATOR.$path.$cacheDataName,
487
+                $cache, function() {
488 488
                 });
489 489
             if (NULL !== $cachedData) {
490
-                $headers = $this->cache->readFromCache("json" . DIRECTORY_SEPARATOR . $path . $cacheDataName . ".headers",
491
-                    $cache, function () {
490
+                $headers = $this->cache->readFromCache("json".DIRECTORY_SEPARATOR.$path.$cacheDataName.".headers",
491
+                    $cache, function() {
492 492
                     }, Cache::JSON);
493 493
                 Template::getInstance()->renderCache($cachedData, $headers);
494 494
                 $execute = FALSE;
Please login to merge, or discard this patch.