Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reduce repetitive getDefaultNamespace() and controllerName() function call in Router #3298

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
reduce repetitive getDefaultNamespace() and controllerName() function…
… call in Router
  • Loading branch information
samsonasik committed Jul 13, 2020
commit 01ba49ff60f4f8b9a8f5e7e303ca9f46b92204f6
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