Passed
Push — master ( f26e4a...fc5a43 )
by Fran
04:04
created
src/base/Router.php 1 patch
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -64,8 +64,8 @@  discard block
 block discarded – undo
64 64
      */
65 65
     public function init()
66 66
     {
67
-        list($this->routing, $this->slugs) = $this->cache->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . "urls.json", $this->cacheType, TRUE);
68
-        $this->domains = $this->cache->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . "domains.json", $this->cacheType, TRUE);
67
+        list($this->routing, $this->slugs) = $this->cache->getDataFromFile(CONFIG_DIR.DIRECTORY_SEPARATOR."urls.json", $this->cacheType, TRUE);
68
+        $this->domains = $this->cache->getDataFromFile(CONFIG_DIR.DIRECTORY_SEPARATOR."domains.json", $this->cacheType, TRUE);
69 69
         if (empty($this->routing) || Config::getInstance()->getDebugMode()) {
70 70
             $this->debugLoad();
71 71
         }
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
                 "success" => FALSE,
103 103
                 "error" => $e->getMessage(),
104 104
             )), 'application/json');
105
-        } else {
105
+        }else {
106 106
             return $template->render('error.html.twig', array(
107 107
                 'exception' => $e,
108 108
                 'trace' => $e->getTraceAsString(),
@@ -160,12 +160,12 @@  discard block
 block discarded – undo
160 160
             SecurityHelper::checkRestrictedAccess($route);
161 161
             //Search action and execute
162 162
             $this->searchAction($route);
163
-        } catch (AccessDeniedException $e) {
163
+        }catch (AccessDeniedException $e) {
164 164
             Logger::log(_('Solicitamos credenciales de acceso a zona restringida'));
165 165
             return Admin::staticAdminLogon($route);
166
-        } catch (RouterException $r) {
166
+        }catch (RouterException $r) {
167 167
             Logger::log($r->getMessage(), LOG_WARNING);
168
-        } catch (\Exception $e) {
168
+        }catch (\Exception $e) {
169 169
             Logger::log($e->getMessage(), LOG_ERR);
170 170
             throw $e;
171 171
         }
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
      */
183 183
     protected function searchAction($route)
184 184
     {
185
-        Logger::log('Searching action to execute: ' . $route, LOG_INFO);
185
+        Logger::log('Searching action to execute: '.$route, LOG_INFO);
186 186
         //Revisamos si tenemos la ruta registrada
187 187
         $parts = parse_url($route);
188 188
         $path = (array_key_exists('path', $parts)) ? $parts['path'] : $route;
@@ -196,7 +196,7 @@  discard block
 block discarded – undo
196 196
                 $class = RouterHelper::getClassToCall($action);
197 197
                 try {
198 198
                     $this->executeCachedRoute($route, $action, $class, $get);
199
-                } catch (\Exception $e) {
199
+                }catch (\Exception $e) {
200 200
                     Logger::log($e->getMessage(), LOG_ERR);
201 201
                     throw new \RuntimeException($e->getMessage(), 404, $e);
202 202
                 }
@@ -225,17 +225,17 @@  discard block
 block discarded – undo
225 225
             $externalModules = explode(',', $externalModules);
226 226
             foreach ($externalModules as &$module) {
227 227
                 $module = preg_replace('/(\\\|\/)/', DIRECTORY_SEPARATOR, $module);
228
-                $externalModulePath = VENDOR_DIR . DIRECTORY_SEPARATOR . $module . DIRECTORY_SEPARATOR . 'src';
228
+                $externalModulePath = VENDOR_DIR.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.'src';
229 229
                 if (file_exists($externalModulePath)) {
230 230
                     $externalModule = $this->finder->directories()->in($externalModulePath)->depth(0);
231 231
                     if (!empty($externalModule)) {
232 232
                         foreach ($externalModule as $modulePath) {
233 233
                             $extModule = $modulePath->getBasename();
234
-                            $moduleAutoloader = realpath($externalModulePath . DIRECTORY_SEPARATOR . $extModule . DIRECTORY_SEPARATOR . 'autoload.php');
234
+                            $moduleAutoloader = realpath($externalModulePath.DIRECTORY_SEPARATOR.$extModule.DIRECTORY_SEPARATOR.'autoload.php');
235 235
                             if (file_exists($moduleAutoloader)) {
236 236
                                 @include $moduleAutoloader;
237 237
                                 if ($hydrateRoute) {
238
-                                    $this->routing = $this->inspectDir($externalModulePath . DIRECTORY_SEPARATOR . $extModule, '\\' . $extModule, $this->routing);
238
+                                    $this->routing = $this->inspectDir($externalModulePath.DIRECTORY_SEPARATOR.$extModule, '\\'.$extModule, $this->routing);
239 239
                                 }
240 240
                             }
241 241
                         }
@@ -258,10 +258,10 @@  discard block
 block discarded – undo
258 258
             $modules = $this->finder->directories()->in($modulesPath)->depth(0);
259 259
             foreach ($modules as $modulePath) {
260 260
                 $module = $modulePath->getBasename();
261
-                $this->routing = $this->inspectDir($modulesPath . DIRECTORY_SEPARATOR . $module, $module, $this->routing);
261
+                $this->routing = $this->inspectDir($modulesPath.DIRECTORY_SEPARATOR.$module, $module, $this->routing);
262 262
             }
263 263
         }
264
-        $this->cache->storeData(CONFIG_DIR . DIRECTORY_SEPARATOR . "domains.json", $this->domains, Cache::JSON, TRUE);
264
+        $this->cache->storeData(CONFIG_DIR.DIRECTORY_SEPARATOR."domains.json", $this->domains, Cache::JSON, TRUE);
265 265
     }
266 266
 
267 267
     /**
@@ -276,7 +276,7 @@  discard block
 block discarded – undo
276 276
             $home_params = NULL;
277 277
             foreach ($this->routing as $pattern => $params) {
278 278
                 list($method, $route) = RouterHelper::extractHttpRoute($pattern);
279
-                if (preg_match("/" . preg_quote($route, "/") . "$/i", "/" . $home)) {
279
+                if (preg_match("/".preg_quote($route, "/")."$/i", "/".$home)) {
280 280
                     $home_params = $params;
281 281
                 }
282 282
             }
@@ -301,7 +301,7 @@  discard block
 block discarded – undo
301 301
         $files = $this->finder->files()->in($origen)->path('/(controller|api)/i')->depth(1)->name("*.php");
302 302
         foreach ($files as $file) {
303 303
             $filename = str_replace("/", '\\', str_replace($origen, '', $file->getPathname()));
304
-            $routing = $this->addRouting($namespace . str_replace('.php', '', $filename), $routing, $namespace);
304
+            $routing = $this->addRouting($namespace.str_replace('.php', '', $filename), $routing, $namespace);
305 305
         }
306 306
         $this->finder = new Finder();
307 307
 
@@ -371,7 +371,7 @@  discard block
 block discarded – undo
371 371
             if (!$this->domains) {
372 372
                 $this->domains = [];
373 373
             }
374
-            $domain = "@" . $class->getConstant("DOMAIN") . "/";
374
+            $domain = "@".$class->getConstant("DOMAIN")."/";
375 375
             if (!array_key_exists($domain, $this->domains)) {
376 376
                 $this->domains[$domain] = RouterHelper::extractDomainInfo($class, $domain);
377 377
             }
@@ -386,11 +386,11 @@  discard block
 block discarded – undo
386 386
      */
387 387
     public function simpatize()
388 388
     {
389
-        $translationFileName = "translations" . DIRECTORY_SEPARATOR . "routes_translations.php";
390
-        $absoluteTranslationFileName = CACHE_DIR . DIRECTORY_SEPARATOR . $translationFileName;
389
+        $translationFileName = "translations".DIRECTORY_SEPARATOR."routes_translations.php";
390
+        $absoluteTranslationFileName = CACHE_DIR.DIRECTORY_SEPARATOR.$translationFileName;
391 391
         $this->generateSlugs($absoluteTranslationFileName);
392 392
         GeneratorHelper::createDir(CONFIG_DIR);
393
-        Cache::getInstance()->storeData(CONFIG_DIR . DIRECTORY_SEPARATOR . "urls.json", array($this->routing, $this->slugs), Cache::JSON, TRUE);
393
+        Cache::getInstance()->storeData(CONFIG_DIR.DIRECTORY_SEPARATOR."urls.json", array($this->routing, $this->slugs), Cache::JSON, TRUE);
394 394
 
395 395
         return $this;
396 396
     }
@@ -408,16 +408,16 @@  discard block
 block discarded – undo
408 408
     public function getRoute($slug = '', $absolute = FALSE, $params = [])
409 409
     {
410 410
         if (strlen($slug) === 0) {
411
-            return ($absolute) ? Request::getInstance()->getRootUrl() . '/' : '/';
411
+            return ($absolute) ? Request::getInstance()->getRootUrl().'/' : '/';
412 412
         }
413 413
         if (!is_array($this->slugs) || !array_key_exists($slug, $this->slugs)) {
414 414
             throw new RouterException(_("No existe la ruta especificada"));
415 415
         }
416
-        $url = ($absolute) ? Request::getInstance()->getRootUrl() . $this->slugs[$slug] : $this->slugs[$slug];
416
+        $url = ($absolute) ? Request::getInstance()->getRootUrl().$this->slugs[$slug] : $this->slugs[$slug];
417 417
         if (!empty($params)) foreach ($params as $key => $value) {
418
-            $url = str_replace("{" . $key . "}", $value, $url);
418
+            $url = str_replace("{".$key."}", $value, $url);
419 419
         } elseif (!empty($this->routing[$this->slugs[$slug]]["default"])) {
420
-            $url = ($absolute) ? Request::getInstance()->getRootUrl() . $this->routing[$this->slugs[$slug]]["default"] : $this->routing[$this->slugs[$slug]]["default"];
420
+            $url = ($absolute) ? Request::getInstance()->getRootUrl().$this->routing[$this->slugs[$slug]]["default"] : $this->routing[$this->slugs[$slug]]["default"];
421 421
         }
422 422
 
423 423
         return preg_replace('/(GET|POST|PUT|DELETE|ALL)\#\|\#/', '', $url);
@@ -462,19 +462,19 @@  discard block
 block discarded – undo
462 462
      */
463 463
     protected function executeCachedRoute($route, $action, $class, $params = NULL)
464 464
     {
465
-        Logger::log('Executing route ' . $route, LOG_INFO);
465
+        Logger::log('Executing route '.$route, LOG_INFO);
466 466
         Security::getInstance()->setSessionKey("__CACHE__", $action);
467 467
         $cache = Cache::needCache();
468 468
         $execute = TRUE;
469 469
         if (FALSE !== $cache && Config::getInstance()->getDebugMode() === FALSE) {
470 470
             $cacheDataName = $this->cache->getRequestCacheHash();
471
-            $tmpDir = substr($cacheDataName, 0, 2) . DIRECTORY_SEPARATOR . substr($cacheDataName, 2, 2) . DIRECTORY_SEPARATOR;
472
-            $cachedData = $this->cache->readFromCache("json" . DIRECTORY_SEPARATOR . $tmpDir . $cacheDataName,
473
-                $cache, function () {
471
+            $tmpDir = substr($cacheDataName, 0, 2).DIRECTORY_SEPARATOR.substr($cacheDataName, 2, 2).DIRECTORY_SEPARATOR;
472
+            $cachedData = $this->cache->readFromCache("json".DIRECTORY_SEPARATOR.$tmpDir.$cacheDataName,
473
+                $cache, function() {
474 474
                 });
475 475
             if (NULL !== $cachedData) {
476
-                $headers = $this->cache->readFromCache("json" . DIRECTORY_SEPARATOR . $tmpDir . $cacheDataName . ".headers",
477
-                    $cache, function () {
476
+                $headers = $this->cache->readFromCache("json".DIRECTORY_SEPARATOR.$tmpDir.$cacheDataName.".headers",
477
+                    $cache, function() {
478 478
                     }, Cache::JSON);
479 479
                 Template::getInstance()->renderCache($cachedData, $headers);
480 480
                 $execute = FALSE;
Please login to merge, or discard this patch.