From 931ed36570693cf79ed61f93caf687545589296d Mon Sep 17 00:00:00 2001 From: kenjis Date: Mon, 4 Sep 2023 11:36:41 +0900 Subject: [PATCH 01/14] docs: add changelog and upgrading for v4.5.0 --- user_guide_src/source/changelogs/index.rst | 1 + user_guide_src/source/changelogs/v4.5.0.rst | 76 +++++++++++++++++++ .../source/installation/upgrade_450.rst | 50 ++++++++++++ .../source/installation/upgrading.rst | 1 + 4 files changed, 128 insertions(+) create mode 100644 user_guide_src/source/changelogs/v4.5.0.rst create mode 100644 user_guide_src/source/installation/upgrade_450.rst diff --git a/user_guide_src/source/changelogs/index.rst b/user_guide_src/source/changelogs/index.rst index 73eab706433f..c6870f241f37 100644 --- a/user_guide_src/source/changelogs/index.rst +++ b/user_guide_src/source/changelogs/index.rst @@ -12,6 +12,7 @@ See all the changes. .. toctree:: :titlesonly: + v4.5.0 v4.4.2 v4.4.1 v4.4.0 diff --git a/user_guide_src/source/changelogs/v4.5.0.rst b/user_guide_src/source/changelogs/v4.5.0.rst new file mode 100644 index 000000000000..b4cca81c54f1 --- /dev/null +++ b/user_guide_src/source/changelogs/v4.5.0.rst @@ -0,0 +1,76 @@ +Version 4.5.0 +############# + +Release Date: Unreleased + +**4.5.0 release of CodeIgniter4** + +.. contents:: + :local: + :depth: 3 + +Highlights +********** + +- TBD + +BREAKING +******** + +Behavior Changes +================ + +Interface Changes +================= + +Method Signature Changes +======================== + +Enhancements +************ + +Commands +======== + +Testing +======= + +Database +======== + +Query Builder +------------- + +Forge +----- + +Others +------ + +Model +===== + +Libraries +========= + +Helpers and Functions +===================== + +Others +====== + +Message Changes +*************** + +Changes +******* + +Deprecations +************ + +Bugs Fixed +********** + +See the repo's +`CHANGELOG.md `_ +for a complete list of bugs fixed. diff --git a/user_guide_src/source/installation/upgrade_450.rst b/user_guide_src/source/installation/upgrade_450.rst new file mode 100644 index 000000000000..5a52bca43aae --- /dev/null +++ b/user_guide_src/source/installation/upgrade_450.rst @@ -0,0 +1,50 @@ +############################# +Upgrading from 4.4.x to 4.5.0 +############################# + +Please refer to the upgrade instructions corresponding to your installation method. + +- :ref:`Composer Installation App Starter Upgrading ` +- :ref:`Composer Installation Adding CodeIgniter4 to an Existing Project Upgrading ` +- :ref:`Manual Installation Upgrading ` + +.. contents:: + :local: + :depth: 2 + +Mandatory File Changes +********************** + +Breaking Changes +**************** + +Breaking Enhancements +********************* + +Project Files +************* + +Some files in the **project space** (root, app, public, writable) received updates. Due to +these files being outside of the **system** scope they will not be changed without your intervention. + +There are some third-party CodeIgniter modules available to assist with merging changes to +the project space: `Explore on Packagist `_. + +Content Changes +=============== + +The following files received significant changes (including deprecations or visual adjustments) +and it is recommended that you merge the updated versions with your application: + +Config +------ + +- @TODO + +All Changes +=========== + +This is a list of all files in the **project space** that received changes; +many will be simple comments or formatting that have no effect on the runtime: + +- @TODO diff --git a/user_guide_src/source/installation/upgrading.rst b/user_guide_src/source/installation/upgrading.rst index 9f9e17528052..f758b89047af 100644 --- a/user_guide_src/source/installation/upgrading.rst +++ b/user_guide_src/source/installation/upgrading.rst @@ -16,6 +16,7 @@ See also :doc:`./backward_compatibility_notes`. backward_compatibility_notes + upgrade_450 upgrade_442 upgrade_441 upgrade_440 From 8aedb6f69c20772e46ae4806642eb8ff441778ef Mon Sep 17 00:00:00 2001 From: kenjis Date: Mon, 11 Sep 2023 12:01:19 +0900 Subject: [PATCH 02/14] config: change default db charset to utf8mb4 --- app/Config/Database.php | 8 ++++---- system/Database/BaseConnection.php | 8 ++++++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/app/Config/Database.php b/app/Config/Database.php index e2450ec16cf1..75d5838fa9ae 100644 --- a/app/Config/Database.php +++ b/app/Config/Database.php @@ -34,8 +34,8 @@ class Database extends Config 'DBPrefix' => '', 'pConnect' => false, 'DBDebug' => true, - 'charset' => 'utf8', - 'DBCollat' => 'utf8_general_ci', + 'charset' => 'utf8mb4', + 'DBCollat' => 'utf8mb4_general_ci', 'swapPre' => '', 'encrypt' => false, 'compress' => false, @@ -59,8 +59,8 @@ class Database extends Config 'DBPrefix' => 'db_', // Needed to ensure we're working correctly with prefixes live. DO NOT REMOVE FOR CI DEVS 'pConnect' => false, 'DBDebug' => true, - 'charset' => 'utf8', - 'DBCollat' => 'utf8_general_ci', + 'charset' => 'utf8mb4', + 'DBCollat' => 'utf8mb4_general_ci', 'swapPre' => '', 'encrypt' => false, 'compress' => false, diff --git a/system/Database/BaseConnection.php b/system/Database/BaseConnection.php index 1116d3966439..83303fea963d 100644 --- a/system/Database/BaseConnection.php +++ b/system/Database/BaseConnection.php @@ -136,16 +136,20 @@ abstract class BaseConnection implements ConnectionInterface /** * Character set * + * This value must be updated by Config\Database if the driver use it. + * * @var string */ - protected $charset = 'utf8'; + protected $charset = 'utf8mb4'; /** * Collation * + * This value must be updated by Config\Database if the driver use it. + * * @var string */ - protected $DBCollat = 'utf8_general_ci'; + protected $DBCollat = 'utf8mb4_general_ci'; /** * Swap Prefix From 995da81a3be565b47f92767ab86922b6111d28d4 Mon Sep 17 00:00:00 2001 From: kenjis Date: Mon, 11 Sep 2023 12:06:13 +0900 Subject: [PATCH 03/14] docs: update utf8 to utf8mb4 --- user_guide_src/source/database/configuration/001.php | 4 ++-- user_guide_src/source/database/configuration/004.php | 2 +- user_guide_src/source/database/configuration/005.php | 8 ++++---- user_guide_src/source/database/configuration/006.php | 4 ++-- user_guide_src/source/database/connecting/006.php | 4 ++-- user_guide_src/source/dbmgmt/forge/016.php | 2 +- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/user_guide_src/source/database/configuration/001.php b/user_guide_src/source/database/configuration/001.php index b4336abbf1c0..874c673fe00a 100644 --- a/user_guide_src/source/database/configuration/001.php +++ b/user_guide_src/source/database/configuration/001.php @@ -18,8 +18,8 @@ class Database extends Config 'DBPrefix' => '', 'pConnect' => false, 'DBDebug' => true, - 'charset' => 'utf8', - 'DBCollat' => 'utf8_general_ci', + 'charset' => 'utf8mb4', + 'DBCollat' => 'utf8mb4_general_ci', 'swapPre' => '', 'encrypt' => false, 'compress' => false, diff --git a/user_guide_src/source/database/configuration/004.php b/user_guide_src/source/database/configuration/004.php index 4b77961706da..58243f8a3727 100644 --- a/user_guide_src/source/database/configuration/004.php +++ b/user_guide_src/source/database/configuration/004.php @@ -10,7 +10,7 @@ class Database extends Config // MySQLi public array $default = [ - 'DSN' => 'MySQLi://username:password@hostname:3306/database?charset=utf8&DBCollat=utf8_general_ci', + 'DSN' => 'MySQLi://username:password@hostname:3306/database?charset=utf8mb4&DBCollat=utf8mb4_general_ci', // ... ]; diff --git a/user_guide_src/source/database/configuration/005.php b/user_guide_src/source/database/configuration/005.php index ca23aea169d9..34f64e381970 100644 --- a/user_guide_src/source/database/configuration/005.php +++ b/user_guide_src/source/database/configuration/005.php @@ -20,8 +20,8 @@ class Database extends Config 'DBPrefix' => '', 'pConnect' => true, 'DBDebug' => true, - 'charset' => 'utf8', - 'DBCollat' => 'utf8_general_ci', + 'charset' => 'utf8mb4', + 'DBCollat' => 'utf8mb4_general_ci', 'swapPre' => '', 'encrypt' => false, 'compress' => false, @@ -36,8 +36,8 @@ class Database extends Config 'DBPrefix' => '', 'pConnect' => true, 'DBDebug' => true, - 'charset' => 'utf8', - 'DBCollat' => 'utf8_general_ci', + 'charset' => 'utf8mb4', + 'DBCollat' => 'utf8mb4_general_ci', 'swapPre' => '', 'encrypt' => false, 'compress' => false, diff --git a/user_guide_src/source/database/configuration/006.php b/user_guide_src/source/database/configuration/006.php index 1cd5fafe421b..ff63399207ad 100644 --- a/user_guide_src/source/database/configuration/006.php +++ b/user_guide_src/source/database/configuration/006.php @@ -18,8 +18,8 @@ class Database extends Config 'DBPrefix' => '', 'pConnect' => true, 'DBDebug' => true, - 'charset' => 'utf8', - 'DBCollat' => 'utf8_general_ci', + 'charset' => 'utf8mb4', + 'DBCollat' => 'utf8mb4_general_ci', 'swapPre' => '', 'compress' => false, 'encrypt' => false, diff --git a/user_guide_src/source/database/connecting/006.php b/user_guide_src/source/database/connecting/006.php index 55e8010730d2..6804ad8a9682 100644 --- a/user_guide_src/source/database/connecting/006.php +++ b/user_guide_src/source/database/connecting/006.php @@ -10,8 +10,8 @@ 'DBPrefix' => '', 'pConnect' => false, 'DBDebug' => true, - 'charset' => 'utf8', - 'DBCollat' => 'utf8_general_ci', + 'charset' => 'utf8mb4', + 'DBCollat' => 'utf8mb4_general_ci', 'swapPre' => '', 'encrypt' => false, 'compress' => false, diff --git a/user_guide_src/source/dbmgmt/forge/016.php b/user_guide_src/source/dbmgmt/forge/016.php index e8db91a9ed63..4fb2abfce753 100644 --- a/user_guide_src/source/dbmgmt/forge/016.php +++ b/user_guide_src/source/dbmgmt/forge/016.php @@ -2,4 +2,4 @@ $attributes = ['ENGINE' => 'InnoDB']; $forge->createTable('table_name', false, $attributes); -// produces: CREATE TABLE `table_name` (...) ENGINE = InnoDB DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci +// produces: CREATE TABLE `table_name` (...) ENGINE = InnoDB DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci From 7f4d0a95fc5377ea56a164c5833f1ca5b0f46472 Mon Sep 17 00:00:00 2001 From: kenjis Date: Mon, 11 Sep 2023 12:05:29 +0900 Subject: [PATCH 04/14] test: update charset utf8 to utf8mb4 --- tests/_support/Config/Registrar.php | 12 +++++----- tests/system/Database/BaseConnectionTest.php | 14 ++++++------ tests/system/Database/ConfigTest.php | 24 ++++++++++---------- tests/system/Models/GeneralModelTest.php | 2 +- 4 files changed, 26 insertions(+), 26 deletions(-) diff --git a/tests/_support/Config/Registrar.php b/tests/_support/Config/Registrar.php index a9c7c3097630..a8d1d40df579 100644 --- a/tests/_support/Config/Registrar.php +++ b/tests/_support/Config/Registrar.php @@ -34,8 +34,8 @@ class Registrar 'DBPrefix' => 'db_', 'pConnect' => false, 'DBDebug' => true, - 'charset' => 'utf8', - 'DBCollat' => 'utf8_general_ci', + 'charset' => 'utf8mb4', + 'DBCollat' => 'utf8mb4_general_ci', 'swapPre' => '', 'encrypt' => false, 'compress' => false, @@ -54,7 +54,7 @@ class Registrar 'pConnect' => false, 'DBDebug' => true, 'charset' => 'utf8', - 'DBCollat' => 'utf8_general_ci', + 'DBCollat' => '', 'swapPre' => '', 'encrypt' => false, 'compress' => false, @@ -73,7 +73,7 @@ class Registrar 'pConnect' => false, 'DBDebug' => true, 'charset' => 'utf8', - 'DBCollat' => 'utf8_general_ci', + 'DBCollat' => '', 'swapPre' => '', 'encrypt' => false, 'compress' => false, @@ -93,7 +93,7 @@ class Registrar 'pConnect' => false, 'DBDebug' => true, 'charset' => 'utf8', - 'DBCollat' => 'utf8_general_ci', + 'DBCollat' => '', 'swapPre' => '', 'encrypt' => false, 'compress' => false, @@ -112,7 +112,7 @@ class Registrar 'pConnect' => false, 'DBDebug' => true, 'charset' => 'AL32UTF8', - 'DBCollat' => 'utf8_general_ci', + 'DBCollat' => '', 'swapPre' => '', 'encrypt' => false, 'compress' => false, diff --git a/tests/system/Database/BaseConnectionTest.php b/tests/system/Database/BaseConnectionTest.php index 1d629832bf6c..ba612e4bed81 100644 --- a/tests/system/Database/BaseConnectionTest.php +++ b/tests/system/Database/BaseConnectionTest.php @@ -33,8 +33,8 @@ final class BaseConnectionTest extends CIUnitTestCase 'DBPrefix' => 'test_', 'pConnect' => true, 'DBDebug' => (ENVIRONMENT !== 'production'), - 'charset' => 'utf8', - 'DBCollat' => 'utf8_general_ci', + 'charset' => 'utf8mb4', + 'DBCollat' => 'utf8mb4_general_ci', 'swapPre' => '', 'encrypt' => false, 'compress' => false, @@ -51,8 +51,8 @@ final class BaseConnectionTest extends CIUnitTestCase 'DBPrefix' => 'test_', 'pConnect' => true, 'DBDebug' => (ENVIRONMENT !== 'production'), - 'charset' => 'utf8', - 'DBCollat' => 'utf8_general_ci', + 'charset' => 'utf8mb4', + 'DBCollat' => 'utf8mb4_general_ci', 'swapPre' => '', 'encrypt' => false, 'compress' => false, @@ -71,8 +71,8 @@ public function testSavesConfigOptions(): void $this->assertSame('MockDriver', $db->DBDriver); $this->assertTrue($db->pConnect); $this->assertTrue($db->DBDebug); - $this->assertSame('utf8', $db->charset); - $this->assertSame('utf8_general_ci', $db->DBCollat); + $this->assertSame('utf8mb4', $db->charset); + $this->assertSame('utf8mb4_general_ci', $db->DBCollat); $this->assertSame('', $db->swapPre); $this->assertFalse($db->encrypt); $this->assertFalse($db->compress); @@ -153,7 +153,7 @@ public function testMagicGet(): void { $db = new MockConnection($this->options); - $this->assertSame('utf8', $db->charset); + $this->assertSame('utf8mb4', $db->charset); } public function testMagicGetMissing(): void diff --git a/tests/system/Database/ConfigTest.php b/tests/system/Database/ConfigTest.php index 37ecfeb6f5e2..71c015c080a2 100644 --- a/tests/system/Database/ConfigTest.php +++ b/tests/system/Database/ConfigTest.php @@ -33,8 +33,8 @@ final class ConfigTest extends CIUnitTestCase 'DBPrefix' => 'test_', 'pConnect' => true, 'DBDebug' => (ENVIRONMENT !== 'production'), - 'charset' => 'utf8', - 'DBCollat' => 'utf8_general_ci', + 'charset' => 'utf8mb4', + 'DBCollat' => 'utf8mb4_general_ci', 'swapPre' => '', 'encrypt' => false, 'compress' => false, @@ -52,8 +52,8 @@ final class ConfigTest extends CIUnitTestCase 'DBPrefix' => 't_', 'pConnect' => false, 'DBDebug' => (ENVIRONMENT !== 'production'), - 'charset' => 'utf8', - 'DBCollat' => 'utf8_general_ci', + 'charset' => 'utf8mb4', + 'DBCollat' => 'utf8mb4_general_ci', 'swapPre' => '', 'encrypt' => false, 'compress' => false, @@ -71,8 +71,8 @@ final class ConfigTest extends CIUnitTestCase 'DBPrefix' => 't_', 'pConnect' => false, 'DBDebug' => (ENVIRONMENT !== 'production'), - 'charset' => 'utf8', - 'DBCollat' => 'utf8_general_ci', + 'charset' => 'utf8mb4', + 'DBCollat' => 'utf8mb4_general_ci', 'swapPre' => '', 'encrypt' => false, 'compress' => false, @@ -90,8 +90,8 @@ final class ConfigTest extends CIUnitTestCase 'DBPrefix' => 't_', 'pConnect' => false, 'DBDebug' => (ENVIRONMENT !== 'production'), - 'charset' => 'utf8', - 'DBCollat' => 'utf8_general_ci', + 'charset' => 'utf8mb4', + 'DBCollat' => 'utf8mb4_general_ci', 'swapPre' => '', 'encrypt' => false, 'compress' => false, @@ -157,8 +157,8 @@ public function testConnectionGroupWithDSNPostgre(): void $this->assertSame('Postgre', $this->getPrivateProperty($conn, 'DBDriver')); $this->assertSame('test_', $this->getPrivateProperty($conn, 'DBPrefix')); $this->assertFalse($this->getPrivateProperty($conn, 'pConnect')); - $this->assertSame('utf8', $this->getPrivateProperty($conn, 'charset')); - $this->assertSame('utf8_general_ci', $this->getPrivateProperty($conn, 'DBCollat')); + $this->assertSame('utf8mb4', $this->getPrivateProperty($conn, 'charset')); + $this->assertSame('utf8mb4_general_ci', $this->getPrivateProperty($conn, 'DBCollat')); $this->assertTrue($this->getPrivateProperty($conn, 'strictOn')); $this->assertSame([], $this->getPrivateProperty($conn, 'failover')); $this->assertSame('5', $this->getPrivateProperty($conn, 'connect_timeout')); @@ -185,8 +185,8 @@ public function testConnectionGroupWithDSNPostgreNative(): void $this->assertSame('Postgre', $this->getPrivateProperty($conn, 'DBDriver')); $this->assertSame('t_', $this->getPrivateProperty($conn, 'DBPrefix')); $this->assertFalse($this->getPrivateProperty($conn, 'pConnect')); - $this->assertSame('utf8', $this->getPrivateProperty($conn, 'charset')); - $this->assertSame('utf8_general_ci', $this->getPrivateProperty($conn, 'DBCollat')); + $this->assertSame('utf8mb4', $this->getPrivateProperty($conn, 'charset')); + $this->assertSame('utf8mb4_general_ci', $this->getPrivateProperty($conn, 'DBCollat')); $this->assertTrue($this->getPrivateProperty($conn, 'strictOn')); $this->assertSame([], $this->getPrivateProperty($conn, 'failover')); } diff --git a/tests/system/Models/GeneralModelTest.php b/tests/system/Models/GeneralModelTest.php index e3966ba5f8e5..65506a47b4a2 100644 --- a/tests/system/Models/GeneralModelTest.php +++ b/tests/system/Models/GeneralModelTest.php @@ -75,7 +75,7 @@ public function testMagicGetters(): void // from DB $this->assertTrue(isset($this->model->DBPrefix)); - $this->assertSame('utf8', $this->model->charset); + $this->assertSame('utf8mb4', $this->model->charset); // from Builder $this->assertTrue(isset($this->model->QBNoEscape)); From d2425b2e4fb461bd91fb9cdf8e69620d5ea13e5b Mon Sep 17 00:00:00 2001 From: kenjis Date: Tue, 12 Sep 2023 06:33:00 +0900 Subject: [PATCH 05/14] config: change default charset/DBCollat for SQLite3 Both are not used at the moment, though. --- app/Config/Database.php | 4 ++-- tests/system/Models/GeneralModelTest.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/Config/Database.php b/app/Config/Database.php index 75d5838fa9ae..4e4aac7c0449 100644 --- a/app/Config/Database.php +++ b/app/Config/Database.php @@ -59,8 +59,8 @@ class Database extends Config 'DBPrefix' => 'db_', // Needed to ensure we're working correctly with prefixes live. DO NOT REMOVE FOR CI DEVS 'pConnect' => false, 'DBDebug' => true, - 'charset' => 'utf8mb4', - 'DBCollat' => 'utf8mb4_general_ci', + 'charset' => 'utf8', + 'DBCollat' => '', 'swapPre' => '', 'encrypt' => false, 'compress' => false, diff --git a/tests/system/Models/GeneralModelTest.php b/tests/system/Models/GeneralModelTest.php index 65506a47b4a2..e3966ba5f8e5 100644 --- a/tests/system/Models/GeneralModelTest.php +++ b/tests/system/Models/GeneralModelTest.php @@ -75,7 +75,7 @@ public function testMagicGetters(): void // from DB $this->assertTrue(isset($this->model->DBPrefix)); - $this->assertSame('utf8mb4', $this->model->charset); + $this->assertSame('utf8', $this->model->charset); // from Builder $this->assertTrue(isset($this->model->QBNoEscape)); From 4e4f8bc9d0c2b4b3a404b965999b9898e05436ea Mon Sep 17 00:00:00 2001 From: kenjis Date: Tue, 12 Sep 2023 06:47:57 +0900 Subject: [PATCH 06/14] docs: add upgrade_450.rst --- user_guide_src/source/installation/upgrade_450.rst | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/user_guide_src/source/installation/upgrade_450.rst b/user_guide_src/source/installation/upgrade_450.rst index 5a52bca43aae..d3420edb64fe 100644 --- a/user_guide_src/source/installation/upgrade_450.rst +++ b/user_guide_src/source/installation/upgrade_450.rst @@ -39,7 +39,10 @@ and it is recommended that you merge the updated versions with your application: Config ------ -- @TODO +- app/Config/Database.php + - The default value of ``charset`` in ``$default`` has been change to ``utf8mb4``. + - The default value of ``DBCollat`` in ``$default`` has been change to ``utf8mb4_general_ci``. + - The default value of ``DBCollat`` in ``$tests`` has been change to ``''``. All Changes =========== From 263f6cd4c0a85d6382afb66b90fc3c2f3d38c21a Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 6 Sep 2023 11:39:03 +0900 Subject: [PATCH 07/14] test: update RouterTest Replaced deprecated methods. --- tests/system/Router/RouterTest.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/system/Router/RouterTest.php b/tests/system/Router/RouterTest.php index c5a05fb36ace..a2ca06c28a61 100644 --- a/tests/system/Router/RouterTest.php +++ b/tests/system/Router/RouterTest.php @@ -496,7 +496,7 @@ public function testRouteWorksWithFilters(): void $this->assertSame('\TestController', $router->controllerName()); $this->assertSame('foobar', $router->methodName()); - $this->assertSame('test', $router->getFilter()); + $this->assertSame(['test'], $router->getFilters()); } /** @@ -526,25 +526,25 @@ static function (RouteCollection $routes): void { $this->assertSame('\App\Controllers\Api\PostController', $router->controllerName()); $this->assertSame('index', $router->methodName()); - $this->assertSame('api-auth', $router->getFilter()); + $this->assertSame(['api-auth'], $router->getFilters()); $router->handle('api/posts/new'); $this->assertSame('\App\Controllers\Api\PostController', $router->controllerName()); $this->assertSame('new', $router->methodName()); - $this->assertSame('api-auth', $router->getFilter()); + $this->assertSame(['api-auth'], $router->getFilters()); $router->handle('api/posts/50'); $this->assertSame('\App\Controllers\Api\PostController', $router->controllerName()); $this->assertSame('show', $router->methodName()); - $this->assertSame('api-auth', $router->getFilter()); + $this->assertSame(['api-auth'], $router->getFilters()); $router->handle('api/posts/50/edit'); $this->assertSame('\App\Controllers\Api\PostController', $router->controllerName()); $this->assertSame('edit', $router->methodName()); - $this->assertSame('api-auth', $router->getFilter()); + $this->assertSame(['api-auth'], $router->getFilters()); // POST $this->collection->group(...$group); @@ -556,7 +556,7 @@ static function (RouteCollection $routes): void { $this->assertSame('\App\Controllers\Api\PostController', $router->controllerName()); $this->assertSame('create', $router->methodName()); - $this->assertSame('api-auth', $router->getFilter()); + $this->assertSame(['api-auth'], $router->getFilters()); // PUT $this->collection->group(...$group); @@ -568,7 +568,7 @@ static function (RouteCollection $routes): void { $this->assertSame('\App\Controllers\Api\PostController', $router->controllerName()); $this->assertSame('update', $router->methodName()); - $this->assertSame('api-auth', $router->getFilter()); + $this->assertSame(['api-auth'], $router->getFilters()); // PATCH $this->collection->group(...$group); @@ -580,7 +580,7 @@ static function (RouteCollection $routes): void { $this->assertSame('\App\Controllers\Api\PostController', $router->controllerName()); $this->assertSame('update', $router->methodName()); - $this->assertSame('api-auth', $router->getFilter()); + $this->assertSame(['api-auth'], $router->getFilters()); // DELETE $this->collection->group(...$group); @@ -592,7 +592,7 @@ static function (RouteCollection $routes): void { $this->assertSame('\App\Controllers\Api\PostController', $router->controllerName()); $this->assertSame('delete', $router->methodName()); - $this->assertSame('api-auth', $router->getFilter()); + $this->assertSame(['api-auth'], $router->getFilters()); } public function testRouteWorksWithClassnameFilter(): void @@ -606,7 +606,7 @@ public function testRouteWorksWithClassnameFilter(): void $this->assertSame('\TestController', $router->controllerName()); $this->assertSame('foo', $router->methodName()); - $this->assertSame(Customfilter::class, $router->getFilter()); + $this->assertSame([Customfilter::class], $router->getFilters()); $this->resetServices(); } From 0a6b0e76afa2266b3c05424e3a00db0ec0a3a4ac Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 6 Sep 2023 11:39:57 +0900 Subject: [PATCH 08/14] test: update FiltersTest Replaced deprecated methods. --- tests/system/Filters/FiltersTest.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/system/Filters/FiltersTest.php b/tests/system/Filters/FiltersTest.php index 8e80e4d5de1d..efe47300fd49 100644 --- a/tests/system/Filters/FiltersTest.php +++ b/tests/system/Filters/FiltersTest.php @@ -834,7 +834,7 @@ public function testEnableFilter(): void $filters = $this->createFilters($filtersConfig); $filters = $filters->initialize('admin/foo/bar'); - $filters->enableFilter('google', 'before'); + $filters->enableFilters(['google'], 'before'); $filters = $filters->getFilters(); $this->assertContains('google', $filters['before']); @@ -941,8 +941,8 @@ public function testEnableFilterWithArguments(): void $filters = $this->createFilters($filtersConfig); $filters = $filters->initialize('admin/foo/bar'); - $filters->enableFilter('role:admin , super', 'before'); - $filters->enableFilter('role:admin , super', 'after'); + $filters->enableFilters(['role:admin , super'], 'before'); + $filters->enableFilters(['role:admin , super'], 'after'); $found = $filters->getFilters(); $this->assertContains('role', $found['before']); @@ -973,8 +973,8 @@ public function testEnableFilterWithNoArguments(): void $filters = $this->createFilters($filtersConfig); $filters = $filters->initialize('admin/foo/bar'); - $filters->enableFilter('role', 'before'); - $filters->enableFilter('role', 'after'); + $filters->enableFilters(['role'], 'before'); + $filters->enableFilters(['role'], 'after'); $found = $filters->getFilters(); $this->assertContains('role', $found['before']); @@ -1005,7 +1005,7 @@ public function testEnableNonFilter(): void $filters = $this->createFilters($filtersConfig); $filters = $filters->initialize('admin/foo/bar'); - $filters->enableFilter('goggle', 'before'); + $filters->enableFilters(['goggle'], 'before'); } /** From 756d14315693c37648e7940d2e56247570a43ac0 Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 6 Sep 2023 11:42:55 +0900 Subject: [PATCH 09/14] refactor: remove Config\Feature::$multipleFilters $multipleFilters is always enabled, and cannot be disabled. --- app/Config/Feature.php | 14 -------------- system/CodeIgniter.php | 18 ++---------------- .../Commands/Utilities/Routes/FilterFinder.php | 8 -------- system/Router/Router.php | 8 +------- .../Utilities/Routes/FilterFinderTest.php | 4 ---- tests/system/Router/RouterTest.php | 5 ----- 6 files changed, 3 insertions(+), 54 deletions(-) diff --git a/app/Config/Feature.php b/app/Config/Feature.php index 0bc45c6f46c0..8ed8e01a0158 100644 --- a/app/Config/Feature.php +++ b/app/Config/Feature.php @@ -9,20 +9,6 @@ */ class Feature extends BaseConfig { - /** - * Enable multiple filters for a route or not. - * - * If you enable this: - * - CodeIgniter\CodeIgniter::handleRequest() uses: - * - CodeIgniter\Filters\Filters::enableFilters(), instead of enableFilter() - * - CodeIgniter\CodeIgniter::tryToRouteIt() uses: - * - CodeIgniter\Router\Router::getFilters(), instead of getFilter() - * - CodeIgniter\Router\Router::handle() uses: - * - property $filtersInfo, instead of $filterInfo - * - CodeIgniter\Router\RouteCollection::getFiltersForRoute(), instead of getFilterForRoute() - */ - public bool $multipleFilters = false; - /** * Use improved new auto routing instead of the default legacy version. */ diff --git a/system/CodeIgniter.php b/system/CodeIgniter.php index e017d6b9ccc2..bd1f9ce9f8b0 100644 --- a/system/CodeIgniter.php +++ b/system/CodeIgniter.php @@ -31,7 +31,6 @@ use CodeIgniter\Router\Router; use Config\App; use Config\Cache; -use Config\Feature; use Config\Kint as KintConfig; use Config\Services; use Exception; @@ -452,15 +451,8 @@ protected function handleRequest(?RouteCollectionInterface $routes, Cache $cache // If any filters were specified within the routes file, // we need to ensure it's active for the current request if ($routeFilter !== null) { - $multipleFiltersEnabled = config(Feature::class)->multipleFilters ?? false; - if ($multipleFiltersEnabled) { - $filters->enableFilters($routeFilter, 'before'); - $filters->enableFilters($routeFilter, 'after'); - } else { - // for backward compatibility - $filters->enableFilter($routeFilter, 'before'); - $filters->enableFilter($routeFilter, 'after'); - } + $filters->enableFilters($routeFilter, 'before'); + $filters->enableFilters($routeFilter, 'after'); } // Run "before" filters @@ -810,12 +802,6 @@ protected function tryToRouteIt(?RouteCollectionInterface $routes = null) $this->benchmark->stop('routing'); - // for backward compatibility - $multipleFiltersEnabled = config(Feature::class)->multipleFilters ?? false; - if (! $multipleFiltersEnabled) { - return $this->router->getFilter(); - } - return $this->router->getFilters(); } diff --git a/system/Commands/Utilities/Routes/FilterFinder.php b/system/Commands/Utilities/Routes/FilterFinder.php index 2e5da617e795..40a834df52f1 100644 --- a/system/Commands/Utilities/Routes/FilterFinder.php +++ b/system/Commands/Utilities/Routes/FilterFinder.php @@ -15,7 +15,6 @@ use CodeIgniter\Filters\Filters; use CodeIgniter\HTTP\Exceptions\RedirectException; use CodeIgniter\Router\Router; -use Config\Feature; use Config\Services; /** @@ -38,13 +37,6 @@ private function getRouteFilters(string $uri): array { $this->router->handle($uri); - $multipleFiltersEnabled = config(Feature::class)->multipleFilters ?? false; - if (! $multipleFiltersEnabled) { - $filter = $this->router->getFilter(); - - return $filter === null ? [] : [$filter]; - } - return $this->router->getFilters(); } diff --git a/system/Router/Router.php b/system/Router/Router.php index 0013d7cdf920..bb551f1b7d3a 100644 --- a/system/Router/Router.php +++ b/system/Router/Router.php @@ -185,13 +185,7 @@ public function handle(?string $uri = null) // Checks defined routes if ($this->checkRoutes($uri)) { if ($this->collection->isFiltered($this->matchedRoute[0])) { - $multipleFiltersEnabled = config(Feature::class)->multipleFilters ?? false; - if ($multipleFiltersEnabled) { - $this->filtersInfo = $this->collection->getFiltersForRoute($this->matchedRoute[0]); - } else { - // for backward compatibility - $this->filterInfo = $this->collection->getFilterForRoute($this->matchedRoute[0]); - } + $this->filtersInfo = $this->collection->getFiltersForRoute($this->matchedRoute[0]); } return $this->controller; diff --git a/tests/system/Commands/Utilities/Routes/FilterFinderTest.php b/tests/system/Commands/Utilities/Routes/FilterFinderTest.php index 67c9a1ca5815..652102976a19 100644 --- a/tests/system/Commands/Utilities/Routes/FilterFinderTest.php +++ b/tests/system/Commands/Utilities/Routes/FilterFinderTest.php @@ -171,8 +171,6 @@ public function testFindGlobalsAndRouteClassnameFilters(): void public function testFindGlobalsAndRouteMultipleFilters(): void { - config('Feature')->multipleFilters = true; - $collection = $this->createRouteCollection(); $collection->get('admin', ' AdminController::index', ['filter' => ['honeypot', InvalidChars::class]]); $router = $this->createRouter($collection); @@ -187,7 +185,5 @@ public function testFindGlobalsAndRouteMultipleFilters(): void 'after' => ['honeypot', InvalidChars::class, 'toolbar'], ]; $this->assertSame($expected, $filters); - - config('Feature')->multipleFilters = false; } } diff --git a/tests/system/Router/RouterTest.php b/tests/system/Router/RouterTest.php index a2ca06c28a61..d0c9b5a664ab 100644 --- a/tests/system/Router/RouterTest.php +++ b/tests/system/Router/RouterTest.php @@ -613,9 +613,6 @@ public function testRouteWorksWithClassnameFilter(): void public function testRouteWorksWithMultipleFilters(): void { - $feature = config('Feature'); - $feature->multipleFilters = true; - $collection = $this->collection; $collection->add('foo', 'TestController::foo', ['filter' => ['filter1', 'filter2:param']]); @@ -626,8 +623,6 @@ public function testRouteWorksWithMultipleFilters(): void $this->assertSame('\TestController', $router->controllerName()); $this->assertSame('foo', $router->methodName()); $this->assertSame(['filter1', 'filter2:param'], $router->getFilters()); - - $feature->multipleFilters = false; } /** From eca7c8271c2a32d3364abb3bc506c43f714fea55 Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 6 Sep 2023 11:45:44 +0900 Subject: [PATCH 10/14] refactor: remove Router::$filterInfo and getFilter() --- system/Router/Router.php | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/system/Router/Router.php b/system/Router/Router.php index bb551f1b7d3a..3e2f504b38bb 100644 --- a/system/Router/Router.php +++ b/system/Router/Router.php @@ -99,16 +99,6 @@ class Router implements RouterInterface */ protected $detectedLocale; - /** - * The filter info from Route Collection - * if the matched route should be filtered. - * - * @var string|null - * - * @deprecated Use $filtersInfo - */ - protected $filterInfo; - /** * The filter info from Route Collection * if the matched route should be filtered. @@ -179,7 +169,6 @@ public function handle(?string $uri = null) $uri = urldecode($uri); // Restart filterInfo - $this->filterInfo = null; $this->filtersInfo = []; // Checks defined routes @@ -206,18 +195,6 @@ public function handle(?string $uri = null) return $this->controllerName(); } - /** - * Returns the filter info for the matched route, if any. - * - * @return string|null - * - * @deprecated Use getFilters() - */ - public function getFilter() - { - return $this->filterInfo; - } - /** * Returns the filter info for the matched route, if any. * From 39c12701fdc66d3e5f6384178de9acca71636faa Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 6 Sep 2023 11:49:34 +0900 Subject: [PATCH 11/14] refactor: remove Filters::enableFilter() --- system/Filters/Filters.php | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/system/Filters/Filters.php b/system/Filters/Filters.php index d0c67845466f..33101aa512db 100644 --- a/system/Filters/Filters.php +++ b/system/Filters/Filters.php @@ -335,12 +335,8 @@ public function addFilter(string $class, ?string $alias = null, string $when = ' * are passed to the filter when executed. * * @param string $name filter_name or filter_name:arguments like 'role:admin,manager' - * - * @return $this - * - * @deprecated Use enableFilters(). This method will be private. */ - public function enableFilter(string $name, string $when = 'before') + private function enableFilter(string $name, string $when = 'before'): void { // Get arguments and clean name [$name, $arguments] = $this->getCleanName($name); @@ -362,8 +358,6 @@ public function enableFilter(string $name, string $when = 'before') $this->filters[$when][] = $name; $this->filtersClass[$when] = array_merge($this->filtersClass[$when], $classNames); } - - return $this; } /** From 4d29e231f9c46e3cca4f5445dc664e420728bae9 Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 6 Sep 2023 12:39:50 +0900 Subject: [PATCH 12/14] chore: update phpstan-baseline --- phpstan-baseline.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/phpstan-baseline.php b/phpstan-baseline.php index 106de3723ef0..86e9be4ca931 100644 --- a/phpstan-baseline.php +++ b/phpstan-baseline.php @@ -2346,11 +2346,6 @@ 'count' => 2, 'path' => __DIR__ . '/system/Router/Router.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Call to an undefined method CodeIgniter\\\\Router\\\\RouteCollectionInterface\\:\\:getFilterForRoute\\(\\)\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Router/Router.php', -]; $ignoreErrors[] = [ 'message' => '#^Call to an undefined method CodeIgniter\\\\Router\\\\RouteCollectionInterface\\:\\:getFiltersForRoute\\(\\)\\.$#', 'count' => 1, From 8e548b0e4e6d7ee41fbe8f2723aef37718983ec1 Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 6 Sep 2023 13:06:27 +0900 Subject: [PATCH 13/14] refactor: remove RouteCollection::getFilterForRoute() --- system/Router/RouteCollection.php | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/system/Router/RouteCollection.php b/system/Router/RouteCollection.php index 63b7397dbc4c..ec724016f301 100644 --- a/system/Router/RouteCollection.php +++ b/system/Router/RouteCollection.php @@ -1228,25 +1228,6 @@ public function isFiltered(string $search, ?string $verb = null): bool return isset($options[$search]['filter']); } - /** - * Returns the filter that should be applied for a single route, along - * with any parameters it might have. Parameters are found by splitting - * the parameter name on a colon to separate the filter name from the parameter list, - * and the splitting the result on commas. So: - * - * 'role:admin,manager' - * - * has a filter of "role", with parameters of ['admin', 'manager']. - * - * @deprecated Use getFiltersForRoute() - */ - public function getFilterForRoute(string $search, ?string $verb = null): string - { - $options = $this->loadRoutesOptions($verb); - - return $options[$search]['filter'] ?? ''; - } - /** * Returns the filters that should be applied for a single route, along * with any parameters it might have. Parameters are found by splitting From 581a5db2ee60b71bb232ccd51a018cc5e5f52ff6 Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 13 Sep 2023 15:07:19 +0900 Subject: [PATCH 14/14] docs: add docs --- user_guide_src/source/changelogs/v4.5.0.rst | 19 +++++++++++++++++++ user_guide_src/source/incoming/routing.rst | 8 +++++++- .../source/installation/upgrade_450.rst | 9 +++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/user_guide_src/source/changelogs/v4.5.0.rst b/user_guide_src/source/changelogs/v4.5.0.rst index b4cca81c54f1..d18f0884e0ce 100644 --- a/user_guide_src/source/changelogs/v4.5.0.rst +++ b/user_guide_src/source/changelogs/v4.5.0.rst @@ -26,6 +26,21 @@ Interface Changes Method Signature Changes ======================== +.. _v450-removed-deprecated-items: + +Removed Deprecated Items +======================== + +Filters +------- + +- The following deprecated items have been removed, because now :ref:`multiple-filters` are always enabled. + + - ``Filters::enableFilter()`` + - ``RouteCollection::getFilterForRoute()`` + - ``Router::$filterInfo`` + - ``Router::getFilter()`` + Enhancements ************ @@ -65,6 +80,10 @@ Message Changes Changes ******* +- **Config:** + - ``Config\Feature::$multipleFilters`` has been removed, because now + :ref:`multiple-filters` are always enabled. + Deprecations ************ diff --git a/user_guide_src/source/incoming/routing.rst b/user_guide_src/source/incoming/routing.rst index 0fa702ff10d2..f956c68fb4df 100644 --- a/user_guide_src/source/incoming/routing.rst +++ b/user_guide_src/source/incoming/routing.rst @@ -384,12 +384,18 @@ You specify a filter classname for the filter value: .. literalinclude:: routing/036.php +.. _multiple-filters: + Multiple Filters ---------------- .. versionadded:: 4.1.5 -.. important:: *Multiple filters* is disabled by default. Because it breaks backward compatibility. If you want to use it, you need to configure. See :ref:`upgrade-415-multiple-filters-for-a-route` for the details. +.. important:: Since v4.5.0, *Multiple Filters* are always enabled. + Prior to v4.5.0, *Multiple Filters* were disabled by default. + If you want to use with prior to v4.5.0, See + :ref:`Upgrading from 4.1.4 to 4.1.5 ` + for the details. You specify an array for the filter value: diff --git a/user_guide_src/source/installation/upgrade_450.rst b/user_guide_src/source/installation/upgrade_450.rst index d3420edb64fe..a9925320bf2d 100644 --- a/user_guide_src/source/installation/upgrade_450.rst +++ b/user_guide_src/source/installation/upgrade_450.rst @@ -18,6 +18,12 @@ Mandatory File Changes Breaking Changes **************** +Removed Deprecated Items +======================== + +Some deprecated items have been removed. If you extend these classes and are +using them, upgrade your code. See :ref:`v450-removed-deprecated-items` for details. + Breaking Enhancements ********************* @@ -43,6 +49,9 @@ Config - The default value of ``charset`` in ``$default`` has been change to ``utf8mb4``. - The default value of ``DBCollat`` in ``$default`` has been change to ``utf8mb4_general_ci``. - The default value of ``DBCollat`` in ``$tests`` has been change to ``''``. +- app/Config/Feature.php + - ``Config\Feature::$multipleFilters`` has been removed, because now + :ref:`multiple-filters` are always enabled. All Changes ===========