From 7facfb03a46e713dee8a56e0ce4e460c089a0146 Mon Sep 17 00:00:00 2001 From: kenjis Date: Sun, 13 Feb 2022 08:56:14 +0900 Subject: [PATCH] refactor: do not use and deprecate setDefaultController() method The constructor of the Router class already defines the default controller. --- system/Router/Router.php | 13 +++++-------- user_guide_src/source/changelogs/v4.2.0.rst | 1 + 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/system/Router/Router.php b/system/Router/Router.php index 1993c60aba30..9755e146fe77 100644 --- a/system/Router/Router.php +++ b/system/Router/Router.php @@ -459,15 +459,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)); } @@ -643,8 +640,6 @@ protected function setRequest(array $segments = []) { // If we don't have any segments - try the default controller; if (empty($segments)) { - $this->setDefaultController(); - return; } @@ -665,6 +660,8 @@ protected function setRequest(array $segments = []) /** * Sets the default controller based on the info set in the RouteCollection. + * + * @deprecated This was an unnecessary method, so it is no longer used. */ protected function setDefaultController() { diff --git a/user_guide_src/source/changelogs/v4.2.0.rst b/user_guide_src/source/changelogs/v4.2.0.rst index 3d2a2223350f..84f1a160f9c2 100644 --- a/user_guide_src/source/changelogs/v4.2.0.rst +++ b/user_guide_src/source/changelogs/v4.2.0.rst @@ -40,6 +40,7 @@ Deprecations ************ - ``CodeIgniter\Database\SQLSRV\Connection::getError()`` is deprecated. Use ``CodeIgniter\Database\SQLSRV\Connection::error()`` instead. +- ``CodeIgniter\Router\setDefaultController()`` is deprecated. Bugs Fixed **********