From 6e63f8200474b15ac7cb3d4b7e4995b895ba02b9 Mon Sep 17 00:00:00 2001 From: "John Paul E. Balandan, CPA" Date: Sat, 21 Feb 2026 22:06:30 +0800 Subject: [PATCH] refactor: cleanup deprecations in `Cache`'s `FileHandler` --- system/Cache/Handlers/FileHandler.php | 198 -------------------- user_guide_src/source/changelogs/v4.8.0.rst | 5 + 2 files changed, 5 insertions(+), 198 deletions(-) diff --git a/system/Cache/Handlers/FileHandler.php b/system/Cache/Handlers/FileHandler.php index adc31c8f447c..b9b1075d115a 100644 --- a/system/Cache/Handlers/FileHandler.php +++ b/system/Cache/Handlers/FileHandler.php @@ -229,202 +229,4 @@ protected function getItem(string $filename): array|false return $data; } - - /** - * Writes a file to disk, or returns false if not successful. - * - * @deprecated 4.6.1 Use `write_file()` instead. - * - * @param string $path - * @param string $data - * @param string $mode - */ - protected function writeFile($path, $data, $mode = 'wb'): bool - { - if (($fp = @fopen($path, $mode)) === false) { - return false; - } - - flock($fp, LOCK_EX); - - $result = 0; - - for ($written = 0, $length = strlen($data); $written < $length; $written += $result) { - if (($result = fwrite($fp, substr($data, $written))) === false) { - break; - } - } - - flock($fp, LOCK_UN); - fclose($fp); - - return is_int($result); - } - - /** - * Deletes all files contained in the supplied directory path. - * Files must be writable or owned by the system in order to be deleted. - * If the second parameter is set to TRUE, any directories contained - * within the supplied base directory will be nuked as well. - * - * @deprecated 4.6.1 Use `delete_files()` instead. - * - * @param string $path File path - * @param bool $delDir Whether to delete any directories found in the path - * @param bool $htdocs Whether to skip deleting .htaccess and index page files - * @param int $_level Current directory depth level (default: 0; internal use only) - */ - protected function deleteFiles(string $path, bool $delDir = false, bool $htdocs = false, int $_level = 0): bool - { - // Trim the trailing slash - $path = rtrim($path, '/\\'); - - if (! $currentDir = @opendir($path)) { - return false; - } - - while (false !== ($filename = @readdir($currentDir))) { - if ($filename !== '.' && $filename !== '..') { - if (is_dir($path . DIRECTORY_SEPARATOR . $filename) && $filename[0] !== '.') { - $this->deleteFiles($path . DIRECTORY_SEPARATOR . $filename, $delDir, $htdocs, $_level + 1); - } elseif (! $htdocs || preg_match('/^(\.htaccess|index\.(html|htm|php)|web\.config)$/i', $filename) !== 1) { - @unlink($path . DIRECTORY_SEPARATOR . $filename); - } - } - } - - closedir($currentDir); - - return ($delDir && $_level > 0) ? @rmdir($path) : true; - } - - /** - * Reads the specified directory and builds an array containing the filenames, - * filesize, dates, and permissions - * - * Any sub-folders contained within the specified path are read as well. - * - * @deprecated 4.6.1 Use `get_dir_file_info()` instead. - * - * @param string $sourceDir Path to source - * @param bool $topLevelOnly Look only at the top level directory specified? - * @param bool $_recursion Internal variable to determine recursion status - do not use in calls - * - * @return array|false - */ - protected function getDirFileInfo(string $sourceDir, bool $topLevelOnly = true, bool $_recursion = false): array|false - { - static $filedata = []; - - $relativePath = $sourceDir; - $filePointer = @opendir($sourceDir); - - if (! is_bool($filePointer)) { - // reset the array and make sure $sourceDir has a trailing slash on the initial call - if ($_recursion === false) { - $filedata = []; - - $resolvedSrc = realpath($sourceDir); - $resolvedSrc = $resolvedSrc === false ? $sourceDir : $resolvedSrc; - - $sourceDir = rtrim($resolvedSrc, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; - } - - // Used to be foreach (scandir($sourceDir, 1) as $file), but scandir() is simply not as fast - while (false !== $file = readdir($filePointer)) { - if (is_dir($sourceDir . $file) && $file[0] !== '.' && $topLevelOnly === false) { - $this->getDirFileInfo($sourceDir . $file . DIRECTORY_SEPARATOR, $topLevelOnly, true); - } elseif (! is_dir($sourceDir . $file) && $file[0] !== '.') { - $filedata[$file] = $this->getFileInfo($sourceDir . $file); - - $filedata[$file]['relative_path'] = $relativePath; - } - } - - closedir($filePointer); - - return $filedata; - } - - return false; - } - - /** - * Given a file and path, returns the name, path, size, date modified - * Second parameter allows you to explicitly declare what information you want returned - * Options are: name, server_path, size, date, readable, writable, executable, fileperms - * Returns FALSE if the file cannot be found. - * - * @deprecated 4.6.1 Use `get_file_info()` instead. - * - * @param string $file Path to file - * @param list|string $returnedValues Array or comma separated string of information returned - * - * @return array{ - * name?: string, - * server_path?: string, - * size?: int, - * date?: int, - * readable?: bool, - * writable?: bool, - * executable?: bool, - * fileperms?: int - * }|false - */ - protected function getFileInfo(string $file, $returnedValues = ['name', 'server_path', 'size', 'date']): array|false - { - if (! is_file($file)) { - return false; - } - - if (is_string($returnedValues)) { - $returnedValues = explode(',', $returnedValues); - } - - $fileInfo = []; - - foreach ($returnedValues as $key) { - switch ($key) { - case 'name': - $fileInfo['name'] = basename($file); - break; - - case 'server_path': - $fileInfo['server_path'] = $file; - break; - - case 'size': - $fileInfo['size'] = filesize($file); - break; - - case 'date': - $fileInfo['date'] = filemtime($file); - break; - - case 'readable': - $fileInfo['readable'] = is_readable($file); - break; - - case 'writable': - $fileInfo['writable'] = is_writable($file); - break; - - case 'executable': - $fileInfo['executable'] = is_executable($file); - break; - - case 'fileperms': - $fileInfo['fileperms'] = fileperms($file); - break; - } - } - - return $fileInfo; - } } diff --git a/user_guide_src/source/changelogs/v4.8.0.rst b/user_guide_src/source/changelogs/v4.8.0.rst index 135f620e31fd..e311d21962bc 100644 --- a/user_guide_src/source/changelogs/v4.8.0.rst +++ b/user_guide_src/source/changelogs/v4.8.0.rst @@ -40,6 +40,11 @@ Removed Deprecated Items - **Autoloader:** Removed the following deprecated methods: - ``CodeIgniter\Autoloader\Autoloader::sanitizeFileName()`` - ``CodeIgniter\Autoloader\Autoloader::discoverComposerNamespaces()`` +- **Cache:** Removed the following methods deprecated since v4.6.0: + - ``CodeIgniter\Cache\Handlers\FileHandler::writeFile()`` + - ``CodeIgniter\Cache\Handlers\FileHandler::deleteFile()`` + - ``CodeIgniter\Cache\Handlers\FileHandler::getDirFileInfo()`` + - ``CodeIgniter\Cache\Handlers\FileHandler::getFileInfo()`` - **Exceptions:** Removed the following properties and methods deprecated since v4.4.0: - ``CodeIgniter\Debug\Exceptions::$ob_level`` - ``CodeIgniter\Debug\Exceptions::$viewPath``