From 01ba49ff60f4f8b9a8f5e7e303ca9f46b92204f6 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 13 Jul 2020 11:35:48 +0700 Subject: [PATCH 1/2] reduce repetitive getDefaultNamespace() and controllerName() function call in Router --- system/Router/Router.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/system/Router/Router.php b/system/Router/Router.php index 91c399edfa44..fc2c178fdb67 100644 --- a/system/Router/Router.php +++ b/system/Router/Router.php @@ -548,11 +548,13 @@ public function autoRoute(string $uri) $this->params = $segments; } + $defaultNameSpace = $this->collection->getDefaultNamespace(); + $controllerName = $this->controllerName(); if ($this->collection->getHTTPVerb() !== 'cli') { - $controller = '\\' . $this->collection->getDefaultNamespace(); + $controller = '\\' . $defaultNameSpace; $controller .= $this->directory ? str_replace('/', '\\', $this->directory) : ''; - $controller .= $this->controllerName(); + $controller .= $controllerName; $controller = strtolower($controller); $methodName = strtolower($this->methodName()); @@ -575,7 +577,7 @@ public function autoRoute(string $uri) } // Load the file so that it's available for CodeIgniter. - $file = APPPATH . 'Controllers/' . $this->directory . $this->controllerName() . '.php'; + $file = APPPATH . 'Controllers/' . $this->directory . $controllerName . '.php'; if (is_file($file)) { include_once $file; @@ -583,9 +585,9 @@ public function autoRoute(string $uri) // Ensure the controller stores the fully-qualified class name // We have to check for a length over 1, since by default it will be '\' - if (strpos($this->controller, '\\') === false && strlen($this->collection->getDefaultNamespace()) > 1) + if (strpos($this->controller, '\\') === false && strlen($defaultNameSpace) > 1) { - $this->controller = '\\' . ltrim(str_replace('/', '\\', $this->collection->getDefaultNamespace() . $this->directory . $this->controllerName()), '\\'); + $this->controller = '\\' . ltrim(str_replace('/', '\\', $defaultNameSpace . $this->directory . $controllerName), '\\'); } } From 56c780b01d46b0ba9059438aeff7b44f7859899a Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 13 Jul 2020 20:12:44 +0700 Subject: [PATCH 2/2] rename defaultNameSpace to defaultNamespace --- system/Router/Router.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/system/Router/Router.php b/system/Router/Router.php index fc2c178fdb67..3ef915058692 100644 --- a/system/Router/Router.php +++ b/system/Router/Router.php @@ -548,11 +548,11 @@ public function autoRoute(string $uri) $this->params = $segments; } - $defaultNameSpace = $this->collection->getDefaultNamespace(); + $defaultNamespace = $this->collection->getDefaultNamespace(); $controllerName = $this->controllerName(); if ($this->collection->getHTTPVerb() !== 'cli') { - $controller = '\\' . $defaultNameSpace; + $controller = '\\' . $defaultNamespace; $controller .= $this->directory ? str_replace('/', '\\', $this->directory) : ''; $controller .= $controllerName; $controller = strtolower($controller); @@ -585,9 +585,9 @@ public function autoRoute(string $uri) // Ensure the controller stores the fully-qualified class name // We have to check for a length over 1, since by default it will be '\' - if (strpos($this->controller, '\\') === false && strlen($defaultNameSpace) > 1) + if (strpos($this->controller, '\\') === false && strlen($defaultNamespace) > 1) { - $this->controller = '\\' . ltrim(str_replace('/', '\\', $defaultNameSpace . $this->directory . $controllerName), '\\'); + $this->controller = '\\' . ltrim(str_replace('/', '\\', $defaultNamespace . $this->directory . $controllerName), '\\'); } }