Passed
Push — master ( 658447...16f32d )
by Fran
03:59
created
src/base/Router.php 1 patch
Spacing   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -60,12 +60,12 @@  discard block
 block discarded – undo
60 60
      */
61 61
     public function init()
62 62
     {
63
-        if (!file_exists(CONFIG_DIR . DIRECTORY_SEPARATOR . "urls.json") || Config::getInstance()->getDebugMode()) {
63
+        if (!file_exists(CONFIG_DIR.DIRECTORY_SEPARATOR."urls.json") || Config::getInstance()->getDebugMode()) {
64 64
             $this->hydrateRouting();
65 65
             $this->simpatize();
66
-        } else {
67
-            list($this->routing, $this->slugs) = $this->cache->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . "urls.json", Cache::JSON, TRUE);
68
-            $this->domains = $this->cache->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . "domains.json", Cache::JSON, TRUE);
66
+        }else {
67
+            list($this->routing, $this->slugs) = $this->cache->getDataFromFile(CONFIG_DIR.DIRECTORY_SEPARATOR."urls.json", Cache::JSON, TRUE);
68
+            $this->domains = $this->cache->getDataFromFile(CONFIG_DIR.DIRECTORY_SEPARATOR."domains.json", Cache::JSON, TRUE);
69 69
             $this->checkExternalModules(false);
70 70
         }
71 71
     }
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
                 "success" => FALSE,
91 91
                 "error" => $e->getMessage(),
92 92
             )), 'application/json');
93
-        } else {
93
+        }else {
94 94
             return $template->render('error.html.twig', array(
95 95
                 'exception' => $e,
96 96
                 'trace' => $e->getTraceAsString(),
@@ -141,12 +141,12 @@  discard block
 block discarded – undo
141 141
             SecurityHelper::checkRestrictedAccess($route);
142 142
             //Search action and execute
143 143
             $this->searchAction($route);
144
-        } catch (AccessDeniedException $e) {
144
+        }catch (AccessDeniedException $e) {
145 145
             Logger::log(_('Solicitamos credenciales de acceso a zona restringida'));
146 146
             return Admin::staticAdminLogon($route);
147
-        } catch (RouterException $r) {
147
+        }catch (RouterException $r) {
148 148
             Logger::log($r->getMessage(), LOG_WARNING);
149
-        } catch (\Exception $e) {
149
+        }catch (\Exception $e) {
150 150
             Logger::log($e->getMessage(), LOG_ERR);
151 151
             throw $e;
152 152
         }
@@ -163,7 +163,7 @@  discard block
 block discarded – undo
163 163
      */
164 164
     protected function searchAction($route)
165 165
     {
166
-        Logger::log('Searching action to execute: ' . $route, LOG_INFO);
166
+        Logger::log('Searching action to execute: '.$route, LOG_INFO);
167 167
         //Revisamos si tenemos la ruta registrada
168 168
         $parts = parse_url($route);
169 169
         $path = (array_key_exists('path', $parts)) ? $parts['path'] : $route;
@@ -177,7 +177,7 @@  discard block
 block discarded – undo
177 177
                 $class = RouterHelper::getClassToCall($action);
178 178
                 try {
179 179
                     $this->executeCachedRoute($route, $action, $class, $get);
180
-                } catch (\Exception $e) {
180
+                }catch (\Exception $e) {
181 181
                     Logger::log($e->getMessage(), LOG_ERR);
182 182
                     throw new RouterException($e->getMessage(), 404, $e);
183 183
                 }
@@ -206,17 +206,17 @@  discard block
 block discarded – undo
206 206
             $externalModules = explode(',', $externalModules);
207 207
             foreach ($externalModules as &$module) {
208 208
                 $module = preg_replace('/(\\\|\/)/', DIRECTORY_SEPARATOR, $module);
209
-                $externalModulePath = VENDOR_DIR . DIRECTORY_SEPARATOR . $module . DIRECTORY_SEPARATOR . 'src';
209
+                $externalModulePath = VENDOR_DIR.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.'src';
210 210
                 if (file_exists($externalModulePath)) {
211 211
                     $externalModule = $this->finder->directories()->in($externalModulePath)->depth(0);
212 212
                     if (!empty($externalModule)) {
213 213
                         foreach ($externalModule as $modulePath) {
214 214
                             $extModule = $modulePath->getBasename();
215
-                            $moduleAutoloader = realpath($externalModulePath . DIRECTORY_SEPARATOR . $extModule . DIRECTORY_SEPARATOR . 'autoload.php');
215
+                            $moduleAutoloader = realpath($externalModulePath.DIRECTORY_SEPARATOR.$extModule.DIRECTORY_SEPARATOR.'autoload.php');
216 216
                             if (file_exists($moduleAutoloader)) {
217 217
                                 @include $moduleAutoloader;
218
-                                if($hydrateRoute) {
219
-                                    $this->routing = $this->inspectDir($externalModulePath . DIRECTORY_SEPARATOR . $extModule, '\\' . $extModule, $this->routing);
218
+                                if ($hydrateRoute) {
219
+                                    $this->routing = $this->inspectDir($externalModulePath.DIRECTORY_SEPARATOR.$extModule, '\\'.$extModule, $this->routing);
220 220
                                 }
221 221
                             }
222 222
                         }
@@ -238,11 +238,11 @@  discard block
 block discarded – undo
238 238
             $modules = $this->finder->directories()->in($modulesPath)->depth(0);
239 239
             foreach ($modules as $modulePath) {
240 240
                 $module = $modulePath->getBasename();
241
-                $this->routing = $this->inspectDir($modulesPath . DIRECTORY_SEPARATOR . $module, $module, $this->routing);
241
+                $this->routing = $this->inspectDir($modulesPath.DIRECTORY_SEPARATOR.$module, $module, $this->routing);
242 242
             }
243 243
         }
244 244
         $this->checkExternalModules();
245
-        $this->cache->storeData(CONFIG_DIR . DIRECTORY_SEPARATOR . "domains.json", $this->domains, Cache::JSON, TRUE);
245
+        $this->cache->storeData(CONFIG_DIR.DIRECTORY_SEPARATOR."domains.json", $this->domains, Cache::JSON, TRUE);
246 246
     }
247 247
 
248 248
     /**
@@ -257,7 +257,7 @@  discard block
 block discarded – undo
257 257
             $home_params = NULL;
258 258
             foreach ($this->routing as $pattern => $params) {
259 259
                 list($method, $route) = RouterHelper::extractHttpRoute($pattern);
260
-                if (preg_match("/" . preg_quote($route, "/") . "$/i", "/" . $home)) {
260
+                if (preg_match("/".preg_quote($route, "/")."$/i", "/".$home)) {
261 261
                     $home_params = $params;
262 262
                 }
263 263
             }
@@ -282,7 +282,7 @@  discard block
 block discarded – undo
282 282
         $files = $this->finder->files()->in($origen)->path('/(controller|api)/i')->depth(1)->name("*.php");
283 283
         foreach ($files as $file) {
284 284
             $filename = str_replace("/", '\\', str_replace($origen, '', $file->getPathname()));
285
-            $routing = $this->addRouting($namespace . str_replace('.php', '', $filename), $routing, $namespace);
285
+            $routing = $this->addRouting($namespace.str_replace('.php', '', $filename), $routing, $namespace);
286 286
         }
287 287
         $this->finder = new Finder();
288 288
 
@@ -351,7 +351,7 @@  discard block
 block discarded – undo
351 351
             if (!$this->domains) {
352 352
                 $this->domains = [];
353 353
             }
354
-            $domain = "@" . $class->getConstant("DOMAIN") . "/";
354
+            $domain = "@".$class->getConstant("DOMAIN")."/";
355 355
             if (!array_key_exists($domain, $this->domains)) {
356 356
                 $this->domains[$domain] = RouterHelper::extractDomainInfo($class, $domain);
357 357
             }
@@ -366,11 +366,11 @@  discard block
 block discarded – undo
366 366
      */
367 367
     public function simpatize()
368 368
     {
369
-        $translationFileName = "translations" . DIRECTORY_SEPARATOR . "routes_translations.php";
370
-        $absoluteTranslationFileName = CACHE_DIR . DIRECTORY_SEPARATOR . $translationFileName;
369
+        $translationFileName = "translations".DIRECTORY_SEPARATOR."routes_translations.php";
370
+        $absoluteTranslationFileName = CACHE_DIR.DIRECTORY_SEPARATOR.$translationFileName;
371 371
         $this->generateSlugs($absoluteTranslationFileName);
372 372
         GeneratorHelper::createDir(CONFIG_DIR);
373
-        Cache::getInstance()->storeData(CONFIG_DIR . DIRECTORY_SEPARATOR . "urls.json", array($this->routing, $this->slugs), Cache::JSON, TRUE);
373
+        Cache::getInstance()->storeData(CONFIG_DIR.DIRECTORY_SEPARATOR."urls.json", array($this->routing, $this->slugs), Cache::JSON, TRUE);
374 374
 
375 375
         return $this;
376 376
     }
@@ -388,16 +388,16 @@  discard block
 block discarded – undo
388 388
     public function getRoute($slug = '', $absolute = FALSE, $params = [])
389 389
     {
390 390
         if (strlen($slug) === 0) {
391
-            return ($absolute) ? Request::getInstance()->getRootUrl() . '/' : '/';
391
+            return ($absolute) ? Request::getInstance()->getRootUrl().'/' : '/';
392 392
         }
393 393
         if (NULL === $slug || !array_key_exists($slug, $this->slugs)) {
394 394
             throw new RouterException(_("No existe la ruta especificada"));
395 395
         }
396
-        $url = ($absolute) ? Request::getInstance()->getRootUrl() . $this->slugs[$slug] : $this->slugs[$slug];
396
+        $url = ($absolute) ? Request::getInstance()->getRootUrl().$this->slugs[$slug] : $this->slugs[$slug];
397 397
         if (!empty($params)) foreach ($params as $key => $value) {
398
-            $url = str_replace("{" . $key . "}", $value, $url);
398
+            $url = str_replace("{".$key."}", $value, $url);
399 399
         } elseif (!empty($this->routing[$this->slugs[$slug]]["default"])) {
400
-            $url = ($absolute) ? Request::getInstance()->getRootUrl() . $this->routing[$this->slugs[$slug]]["default"] : $this->routing[$this->slugs[$slug]]["default"];
400
+            $url = ($absolute) ? Request::getInstance()->getRootUrl().$this->routing[$this->slugs[$slug]]["default"] : $this->routing[$this->slugs[$slug]]["default"];
401 401
         }
402 402
 
403 403
         return preg_replace('/(GET|POST|PUT|DELETE|ALL)\#\|\#/', '', $url);
@@ -458,19 +458,19 @@  discard block
 block discarded – undo
458 458
      */
459 459
     protected function executeCachedRoute($route, $action, $class, $params = NULL)
460 460
     {
461
-        Logger::log('Executing route ' . $route, LOG_INFO);
461
+        Logger::log('Executing route '.$route, LOG_INFO);
462 462
         Security::getInstance()->setSessionKey("__CACHE__", $action);
463 463
         $cache = Cache::needCache();
464 464
         $execute = TRUE;
465 465
         if (FALSE !== $cache && Config::getInstance()->getDebugMode() === FALSE) {
466 466
             $cacheDataName = $this->cache->getRequestCacheHash();
467
-            $tmpDir = substr($cacheDataName, 0, 2) . DIRECTORY_SEPARATOR . substr($cacheDataName, 2, 2) . DIRECTORY_SEPARATOR;
468
-            $cachedData = $this->cache->readFromCache("json" . DIRECTORY_SEPARATOR . $tmpDir . $cacheDataName,
469
-                $cache, function () {
467
+            $tmpDir = substr($cacheDataName, 0, 2).DIRECTORY_SEPARATOR.substr($cacheDataName, 2, 2).DIRECTORY_SEPARATOR;
468
+            $cachedData = $this->cache->readFromCache("json".DIRECTORY_SEPARATOR.$tmpDir.$cacheDataName,
469
+                $cache, function() {
470 470
                 });
471 471
             if (NULL !== $cachedData) {
472
-                $headers = $this->cache->readFromCache("json" . DIRECTORY_SEPARATOR . $tmpDir . $cacheDataName . ".headers",
473
-                    $cache, function () {
472
+                $headers = $this->cache->readFromCache("json".DIRECTORY_SEPARATOR.$tmpDir.$cacheDataName.".headers",
473
+                    $cache, function() {
474 474
                     }, Cache::JSON);
475 475
                 Template::getInstance()->renderCache($cachedData, $headers);
476 476
                 $execute = FALSE;
Please login to merge, or discard this patch.