From 2822a186f61b95f3ef6b69272f384834e691b13a 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 6886f92e6555..d088879a6122 100644 --- a/user_guide_src/source/changelogs/v4.2.0.rst +++ b/user_guide_src/source/changelogs/v4.2.0.rst @@ -42,6 +42,7 @@ Deprecations - ``CodeIgniter\Database\SQLSRV\Connection::getError()`` is deprecated. Use ``CodeIgniter\Database\SQLSRV\Connection::error()`` instead. - ``CodeIgniter\Debug\Exceptions::cleanPath()`` and ``CodeIgniter\Debug\Toolbar\Collectors\BaseCollector::cleanPath()`` are deprecated. Use the ``clean_path()`` function instead. - ``CodeIgniter\Log\Logger::cleanFilenames()`` and ``CodeIgniter\Test\TestLogger::cleanup()`` are both deprecated. Use the ``clean_path()`` function instead. +- ``CodeIgniter\Router\setDefaultController()`` is deprecated. Bugs Fixed **********