From c6bb6e95525ebc0ddda3ec8d03b61ff9301f3892 Mon Sep 17 00:00:00 2001 From: neznaika0 Date: Sun, 12 Jan 2025 13:21:30 +0300 Subject: [PATCH 1/2] refactor: Remove deprecated `Cache::$storePath` --- app/Config/Cache.php | 14 ++----------- system/Cache/Handlers/FileHandler.php | 7 ------- tests/system/Cache/CacheFactoryTest.php | 20 +++++++++---------- .../function.alreadyNarrowedType.neon | 7 +------ 4 files changed, 13 insertions(+), 35 deletions(-) diff --git a/app/Config/Cache.php b/app/Config/Cache.php index 3fbade6840cc..9ae2e843ac91 100644 --- a/app/Config/Cache.php +++ b/app/Config/Cache.php @@ -34,18 +34,6 @@ class Cache extends BaseConfig */ public string $backupHandler = 'dummy'; - /** - * -------------------------------------------------------------------------- - * Cache Directory Path - * -------------------------------------------------------------------------- - * - * The path to where cache files should be stored, if using a file-based - * system. - * - * @deprecated Use the driver-specific variant under $file - */ - public string $storePath = WRITEPATH . 'cache/'; - /** * -------------------------------------------------------------------------- * Key Prefix @@ -86,6 +74,7 @@ class Cache extends BaseConfig * -------------------------------------------------------------------------- * File settings * -------------------------------------------------------------------------- + * * Your file storage preferences can be specified below, if you are using * the File driver. * @@ -100,6 +89,7 @@ class Cache extends BaseConfig * ------------------------------------------------------------------------- * Memcached settings * ------------------------------------------------------------------------- + * * Your Memcached servers can be specified below, if you are using * the Memcached drivers. * diff --git a/system/Cache/Handlers/FileHandler.php b/system/Cache/Handlers/FileHandler.php index 525616a71068..0a97a89f4862 100644 --- a/system/Cache/Handlers/FileHandler.php +++ b/system/Cache/Handlers/FileHandler.php @@ -54,13 +54,6 @@ class FileHandler extends BaseHandler */ public function __construct(Cache $config) { - if (! property_exists($config, 'file')) { - $config->file = [ - 'storePath' => $config->storePath ?? WRITEPATH . 'cache', - 'mode' => 0640, - ]; - } - $this->path = ! empty($config->file['storePath']) ? $config->file['storePath'] : WRITEPATH . 'cache'; $this->path = rtrim($this->path, '/') . '/'; diff --git a/tests/system/Cache/CacheFactoryTest.php b/tests/system/Cache/CacheFactoryTest.php index 0947f31d5045..02fce236e3eb 100644 --- a/tests/system/Cache/CacheFactoryTest.php +++ b/tests/system/Cache/CacheFactoryTest.php @@ -37,14 +37,14 @@ protected function setUp(): void // Initialize path $this->config = new Cache(); - $this->config->storePath .= self::$directory; + $this->config->file['storePath'] .= self::$directory; } protected function tearDown(): void { - if (is_dir($this->config->storePath)) { - chmod($this->config->storePath, 0777); - rmdir($this->config->storePath); + if (is_dir($this->config->file['storePath'])) { + chmod($this->config->file['storePath'], 0777); + rmdir($this->config->file['storePath']); } } @@ -75,8 +75,8 @@ public function testGetHandlerExceptionCacheHandlerNotFound(): void public function testGetDummyHandler(): void { - if (! is_dir($this->config->storePath)) { - mkdir($this->config->storePath, 0555, true); + if (! is_dir($this->config->file['storePath'])) { + mkdir($this->config->file['storePath'], 0555, true); } $this->config->handler = 'dummy'; @@ -85,13 +85,13 @@ public function testGetDummyHandler(): void // Initialize path $this->config = new Cache(); - $this->config->storePath .= self::$directory; + $this->config->file['storePath'] .= self::$directory; } public function testHandlesBadHandler(): void { - if (! is_dir($this->config->storePath)) { - mkdir($this->config->storePath, 0555, true); + if (! is_dir($this->config->file['storePath'])) { + mkdir($this->config->file['storePath'], 0555, true); } $this->config->handler = 'dummy'; @@ -104,6 +104,6 @@ public function testHandlesBadHandler(): void // Initialize path $this->config = new Cache(); - $this->config->storePath .= self::$directory; + $this->config->file['storePath'] .= self::$directory; } } diff --git a/utils/phpstan-baseline/function.alreadyNarrowedType.neon b/utils/phpstan-baseline/function.alreadyNarrowedType.neon index 346807df2847..740fa9659412 100644 --- a/utils/phpstan-baseline/function.alreadyNarrowedType.neon +++ b/utils/phpstan-baseline/function.alreadyNarrowedType.neon @@ -1,12 +1,7 @@ -# total 3 errors +# total 2 errors parameters: ignoreErrors: - - - message: '#^Call to function property_exists\(\) with Config\\Cache and ''file'' will always evaluate to true\.$#' - count: 1 - path: ../../system/Cache/Handlers/FileHandler.php - - message: '#^Call to function is_array\(\) with array will always evaluate to true\.$#' count: 1 From 23f2559369aefa95543919303b6ed5875c52c1de Mon Sep 17 00:00:00 2001 From: neznaika0 Date: Sun, 12 Jan 2025 23:44:54 +0300 Subject: [PATCH 2/2] docs: Update changelog --- user_guide_src/source/changelogs/v4.6.0.rst | 1 + user_guide_src/source/installation/upgrade_460.rst | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/user_guide_src/source/changelogs/v4.6.0.rst b/user_guide_src/source/changelogs/v4.6.0.rst index d35749753443..94aeb3cb33ea 100644 --- a/user_guide_src/source/changelogs/v4.6.0.rst +++ b/user_guide_src/source/changelogs/v4.6.0.rst @@ -201,6 +201,7 @@ Removed Deprecated Items - **Router:** The deprecated ``CodeIgniter\Router\Exceptions\RedirectException`` has been removed. Use ``CodeIgniter\HTTP\Exceptions\RedirectException`` instead. - **Constants:** The deprecated constants ``EVENT_PRIORITY_*`` in has been removed. Use the class constants ``CodeIgniter\Events\Events::PRIORITY_LOW``, ``CodeIgniter\Events\Events::PRIORITY_NORMAL`` and ``CodeIgniter\Events\Events::PRIORITY_HIGH`` instead. - **View:** The deprecated property ``CodeIgniter\View\View::$currentSection`` has been removed. +- **Config:** The deprecated property ``Config\Cache::$storePath`` has been removed. Use ``Config\Cache::$file['storePath']`` instead. ************ Enhancements diff --git a/user_guide_src/source/installation/upgrade_460.rst b/user_guide_src/source/installation/upgrade_460.rst index f1f1243392d6..f9e73ac84a75 100644 --- a/user_guide_src/source/installation/upgrade_460.rst +++ b/user_guide_src/source/installation/upgrade_460.rst @@ -222,4 +222,5 @@ 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: - app/Config/Feature.php -- app/Config/Constants.php \ No newline at end of file +- app/Config/Constants.php +- app/Config/Cache.php \ No newline at end of file