Skip to content

Commit

Permalink
refactor: remove setDefaultController() method
Browse files Browse the repository at this point in the history
The constructor of the Router class already defines the default controller.
  • Loading branch information
kenjis committed Feb 12, 2022
1 parent 3eeae7d commit 3488391
Showing 1 changed file with 3 additions and 29 deletions.
32 changes: 3 additions & 29 deletions system/Router/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use CodeIgniter\Exceptions\PageNotFoundException;
use CodeIgniter\HTTP\Request;
use CodeIgniter\Router\Exceptions\RedirectException;
use CodeIgniter\Router\Exceptions\RouterException;

/**
* Request router.
Expand Down Expand Up @@ -459,15 +458,12 @@ public function autoRoute(string $uri)
{
$segments = explode('/', $uri);

// WARNING: Directories get shifted out of the segments array.
$segments = $this->scanControllers($segments);

// If we don't have any segments left - try the default controller;
// WARNING: Directories get shifted out of the segments array.
if (empty($segments)) {
$this->setDefaultController();
}
// If we don't have any segments left - use the default controller;
// If not empty, then the first segment should be the controller
else {
if (! empty($segments)) {
$this->controller = ucfirst(array_shift($segments));
}

Expand Down Expand Up @@ -643,8 +639,6 @@ protected function setRequest(array $segments = [])
{
// If we don't have any segments - try the default controller;
if (empty($segments)) {
$this->setDefaultController();

return;
}

Expand All @@ -662,24 +656,4 @@ protected function setRequest(array $segments = [])

$this->params = $segments;
}

/**
* Sets the default controller based on the info set in the RouteCollection.
*/
protected function setDefaultController()
{
if (empty($this->controller)) {
throw RouterException::forMissingDefaultRoute();
}

sscanf($this->controller, '%[^/]/%s', $class, $this->method);

if (! is_file(APPPATH . 'Controllers/' . $this->directory . ucfirst($class) . '.php')) {
return;
}

$this->controller = ucfirst($class);

log_message('info', 'Used the default controller.');
}
}

0 comments on commit 3488391

Please sign in to comment.