Skip to content

Commit

Permalink
Merge pull request #3298 from samsonasik/reduce-repetitive-func-call-…
Browse files Browse the repository at this point in the history
…in-router

reduce repetitive getDefaultNamespace() and controllerName() function call in Router
  • Loading branch information
michalsn authored Jul 13, 2020
2 parents 81a8d59 + 56c780b commit 4334459
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions system/Router/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand All @@ -575,17 +577,17 @@ 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;
}

// 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), '\\');
}
}

Expand Down

0 comments on commit 4334459

Please sign in to comment.