From ae1a10fcf3bd87515b010824e8ad857588e5d099 Mon Sep 17 00:00:00 2001 From: "John Paul E. Balandan, CPA" Date: Sun, 22 Feb 2026 00:27:59 +0800 Subject: [PATCH] refactor: remove deprecated static constructors of `FrameworkException` and child classes --- system/Exceptions/DownloadException.php | 10 --------- system/Exceptions/FrameworkException.php | 21 ------------------- system/HTTP/Exceptions/HTTPException.php | 14 ------------- .../Honeypot/Exceptions/HoneypotException.php | 12 ----------- system/Images/Handlers/ImageMagickHandler.php | 6 +++++- system/Language/en/Core.php | 1 - system/Language/en/HTTP.php | 5 ----- system/Language/en/Security.php | 3 --- system/Language/en/Session.php | 3 --- .../Security/Exceptions/SecurityException.php | 12 ----------- .../Session/Exceptions/SessionException.php | 12 ----------- system/bootstrap.php | 13 ++++++------ tests/_support/Language/en/Core.php | 4 ++-- tests/system/Language/LanguageTest.php | 15 ++++++++----- user_guide_src/source/changelogs/v4.8.0.rst | 16 +++++++++++++- 15 files changed, 38 insertions(+), 109 deletions(-) diff --git a/system/Exceptions/DownloadException.php b/system/Exceptions/DownloadException.php index c3bde8ed2556..35908620a8fa 100644 --- a/system/Exceptions/DownloadException.php +++ b/system/Exceptions/DownloadException.php @@ -44,16 +44,6 @@ public static function forNotFoundDownloadSource() return new static(lang('HTTP.notFoundDownloadSource')); } - /** - * @deprecated Since v4.5.6 - * - * @return static - */ - public static function forCannotSetCache() - { - return new static(lang('HTTP.cannotSetCache')); - } - /** * @return static */ diff --git a/system/Exceptions/FrameworkException.php b/system/Exceptions/FrameworkException.php index 4650c6c3541f..dec877e8dea0 100644 --- a/system/Exceptions/FrameworkException.php +++ b/system/Exceptions/FrameworkException.php @@ -55,27 +55,6 @@ public static function forCopyError(string $path) return new static(lang('Core.copyError', [$path])); } - /** - * @return static - * - * @deprecated 4.5.0 No longer used. - */ - public static function forMissingExtension(string $extension) - { - if (str_contains($extension, 'intl')) { - // @codeCoverageIgnoreStart - $message = sprintf( - 'The framework needs the following extension(s) installed and loaded: %s.', - $extension, - ); - // @codeCoverageIgnoreEnd - } else { - $message = lang('Core.missingExtension', [$extension]); - } - - return new static($message); - } - /** * @return static */ diff --git a/system/HTTP/Exceptions/HTTPException.php b/system/HTTP/Exceptions/HTTPException.php index 146a565b8c77..8e2d93841f67 100644 --- a/system/HTTP/Exceptions/HTTPException.php +++ b/system/HTTP/Exceptions/HTTPException.php @@ -217,20 +217,6 @@ public static function forMoveFailed(string $source, string $target, string $err return new static(lang('HTTP.moveFailed', [$source, $target, $error])); } - /** - * For Invalid SameSite attribute setting - * - * @return HTTPException - * - * @deprecated Use `CookieException::forInvalidSameSite()` instead. - * - * @codeCoverageIgnore - */ - public static function forInvalidSameSiteSetting(string $samesite) - { - return new static(lang('Security.invalidSameSiteSetting', [$samesite])); - } - /** * Thrown when the JSON format is not supported. * This is specifically for cases where data validation is expected to work with key-value structures. diff --git a/system/Honeypot/Exceptions/HoneypotException.php b/system/Honeypot/Exceptions/HoneypotException.php index 5185f6d3c843..2a03ec2a8d5c 100644 --- a/system/Honeypot/Exceptions/HoneypotException.php +++ b/system/Honeypot/Exceptions/HoneypotException.php @@ -37,18 +37,6 @@ public static function forNoNameField() return new static(lang('Honeypot.noNameField')); } - /** - * Thrown when the hidden value of config is false. - * - * @return static - * - * @deprecated 4.6.4 Never used. - */ - public static function forNoHiddenValue() - { - return new static(lang('Honeypot.noHiddenValue')); - } - /** * Thrown when there are no data in the request of honeypot field. * diff --git a/system/Images/Handlers/ImageMagickHandler.php b/system/Images/Handlers/ImageMagickHandler.php index 0655a4c13ced..f0071b7e0e6a 100644 --- a/system/Images/Handlers/ImageMagickHandler.php +++ b/system/Images/Handlers/ImageMagickHandler.php @@ -21,6 +21,7 @@ use ImagickException; use ImagickPixel; use ImagickPixelException; +use RuntimeException; /** * Image handler for Imagick extension. @@ -46,7 +47,10 @@ public function __construct($config = null) parent::__construct($config); if (! extension_loaded('imagick')) { - throw ImageException::forMissingExtension('IMAGICK'); // @codeCoverageIgnore + throw new RuntimeException(sprintf( + 'The "%s" handler requires the "imagick" PHP extension.', + static::class, + )); } } diff --git a/system/Language/en/Core.php b/system/Language/en/Core.php index c01d43a9a2c0..f6f98693bcaa 100644 --- a/system/Language/en/Core.php +++ b/system/Language/en/Core.php @@ -18,6 +18,5 @@ 'invalidFile' => 'Invalid file: "{0}"', 'invalidDirectory' => 'Directory does not exist: "{0}"', 'invalidPhpVersion' => 'Your PHP version must be {0} or higher to run CodeIgniter. Current version: {1}', - 'missingExtension' => 'The framework needs the following extension(s) installed and loaded: "{0}".', 'noHandlers' => '"{0}" must provide at least one Handler.', ]; diff --git a/system/Language/en/HTTP.php b/system/Language/en/HTTP.php index 854a897c017b..25a67d050ef3 100644 --- a/system/Language/en/HTTP.php +++ b/system/Language/en/HTTP.php @@ -37,7 +37,6 @@ 'cannotSetBinary' => 'When setting filepath cannot set binary.', 'cannotSetFilepath' => 'When setting binary cannot set filepath: "{0}"', 'notFoundDownloadSource' => 'Not found download body source.', - 'cannotSetCache' => 'It does not support caching for downloading.', 'cannotSetStatusCode' => 'It does not support change status code for downloading. code: {0}, reason: {1}', // Response @@ -76,8 +75,4 @@ 'uploadErrNoTmpDir' => 'File could not be uploaded: missing temporary directory.', 'uploadErrExtension' => 'File upload was stopped by a PHP extension.', 'uploadErrUnknown' => 'The file "%s" was not uploaded due to an unknown error.', - - // SameSite setting - // @deprecated - 'invalidSameSiteSetting' => 'The SameSite setting must be None, Lax, Strict, or a blank string. Given: {0}', ]; diff --git a/system/Language/en/Security.php b/system/Language/en/Security.php index fd906e378a29..345aaa7ce0c2 100644 --- a/system/Language/en/Security.php +++ b/system/Language/en/Security.php @@ -15,7 +15,4 @@ return [ 'disallowedAction' => 'The action you requested is not allowed.', 'insecureCookie' => 'Attempted to send a secure cookie over a non-secure connection.', - - // @deprecated - 'invalidSameSite' => 'The SameSite value must be None, Lax, Strict, or a blank string. Given: "{0}"', ]; diff --git a/system/Language/en/Session.php b/system/Language/en/Session.php index 53d8bba95789..d067410462c0 100644 --- a/system/Language/en/Session.php +++ b/system/Language/en/Session.php @@ -18,7 +18,4 @@ 'writeProtectedSavePath' => 'Session: Configured save path "{0}" is not writable by the PHP process.', 'emptySavePath' => 'Session: No save path configured.', 'invalidSavePathFormat' => 'Session: Invalid Redis save path format: "{0}"', - - // @deprecated - 'invalidSameSiteSetting' => 'Session: The SameSite setting must be None, Lax, Strict, or a blank string. Given: "{0}"', ]; diff --git a/system/Security/Exceptions/SecurityException.php b/system/Security/Exceptions/SecurityException.php index 09ecc26e6bc8..14b8a5464aa5 100644 --- a/system/Security/Exceptions/SecurityException.php +++ b/system/Security/Exceptions/SecurityException.php @@ -69,16 +69,4 @@ public static function forInvalidControlChars(string $source, string $string) 400, ); } - - /** - * @deprecated Use `CookieException::forInvalidSameSite()` instead. - * - * @codeCoverageIgnore - * - * @return static - */ - public static function forInvalidSameSite(string $samesite) - { - return new static(lang('Security.invalidSameSite', [$samesite])); - } } diff --git a/system/Session/Exceptions/SessionException.php b/system/Session/Exceptions/SessionException.php index 2548d5f5dc18..29c9a74ab3c1 100644 --- a/system/Session/Exceptions/SessionException.php +++ b/system/Session/Exceptions/SessionException.php @@ -56,16 +56,4 @@ public static function forInvalidSavePathFormat(string $path) { return new static(lang('Session.invalidSavePathFormat', [$path])); } - - /** - * @deprecated - * - * @return static - * - * @codeCoverageIgnore - */ - public static function forInvalidSameSiteSetting(string $samesite) - { - return new static(lang('Session.invalidSameSiteSetting', [$samesite])); - } } diff --git a/system/bootstrap.php b/system/bootstrap.php index c0b021494737..73a12ea803a6 100644 --- a/system/bootstrap.php +++ b/system/bootstrap.php @@ -17,7 +17,6 @@ * --------------------------------------------------------------- */ -use CodeIgniter\Exceptions\FrameworkException; use Config\Autoload; use Config\Modules; use Config\Paths; @@ -135,18 +134,18 @@ if (! is_file(COMPOSER_PATH)) { $missingExtensions = []; - foreach ([ - 'intl', - 'json', - 'mbstring', - ] as $extension) { + foreach (['intl', 'json', 'mbstring'] as $extension) { if (! extension_loaded($extension)) { $missingExtensions[] = $extension; } } if ($missingExtensions !== []) { - throw FrameworkException::forMissingExtension(implode(', ', $missingExtensions)); + throw new RuntimeException(sprintf( + 'The framework needs the following extension%s installed and loaded: "%s".', + count($missingExtensions) > 1 ? 's' : '', + implode('", "', $missingExtensions), + )); } unset($missingExtensions); diff --git a/tests/_support/Language/en/Core.php b/tests/_support/Language/en/Core.php index 7b3355cf311c..bbbd6657a330 100644 --- a/tests/_support/Language/en/Core.php +++ b/tests/_support/Language/en/Core.php @@ -12,6 +12,6 @@ */ return [ - 'missingExtension' => '{0} extension could not be found.', - 'bazillion' => 'billions and billions', // adds a new setting + 'invalidFile' => 'The file provided is invalid.', // replacement + 'bazillion' => 'billions and billions', // new setting ]; diff --git a/tests/system/Language/LanguageTest.php b/tests/system/Language/LanguageTest.php index 749a30e88b3d..1bb7478ba611 100644 --- a/tests/system/Language/LanguageTest.php +++ b/tests/system/Language/LanguageTest.php @@ -265,11 +265,16 @@ public function testGetLocale(): void public function testPrioritizedLocator(): void { - // this should load the replacement bundle of messages - $message = lang('Core.missingExtension', [], 'en'); - $this->assertSame('The framework needs the following extension(s) installed and loaded: "{0}".', $message); - // and we should have our new message too - $this->assertSame('billions and billions', lang('Core.bazillion', [], 'en')); + $this->assertSame( + 'Invalid file: "{0}"', + lang('Core.invalidFile', [], 'en'), + 'Failed asserting that the system language file is prioritized over the test support language file.', + ); + $this->assertSame( + 'billions and billions', + lang('Core.bazillion', [], 'en'), + 'Failed asserting that the test support language file is used if key is not found in the system language file.', + ); } /** diff --git a/user_guide_src/source/changelogs/v4.8.0.rst b/user_guide_src/source/changelogs/v4.8.0.rst index 7d0adfa27e0a..95e306063380 100644 --- a/user_guide_src/source/changelogs/v4.8.0.rst +++ b/user_guide_src/source/changelogs/v4.8.0.rst @@ -70,7 +70,7 @@ Removed Deprecated Items - ``CodeIgniter\CodeIgniter::determinePath()`` - ``CodeIgniter\CodeIgniter::callExit()`` - ``CodeIgniter\Test\MockCodeIgniter::callExit()`` -- **Exceptions:** Removed the following properties and methods deprecated since v4.4.0: +- **Debug:** Removed the following properties and methods deprecated since v4.4.0: - ``CodeIgniter\Debug\Exceptions::$ob_level`` - ``CodeIgniter\Debug\Exceptions::$viewPath`` - ``CodeIgniter\Debug\Exceptions::determineView()`` @@ -81,6 +81,13 @@ Removed Deprecated Items - ``CodeIgniter\Debug\Exceptions::cleanPath()`` - ``CodeIgniter\Debug\Exceptions::describeMemory()`` - ``CodeIgniter\Debug\Exceptions::highlightFile()`` +- **Exceptions:** Removed the following static constructors of ``FrameworkException`` and its child classes: + - ``CodeIgniter\Exceptions\DownloadException::forCannotSetCache()`` + - ``CodeIgniter\Exceptions\FrameworkException::forMissingExtension()`` + - ``CodeIgniter\Honeypot\Exceptions\HoneypotException::forNoHiddenValue()`` + - ``CodeIgniter\HTTP\Exceptions\HTTPException::forInvalidSameSiteSetting()`` + - ``CodeIgniter\Security\Exceptions\SecurityException::forInvalidSameSite()`` + - ``CodeIgniter\Session\Exceptions\SessionException::forInvalidSameSiteSetting()`` - **Security:** Removed the following properties and methods deprecated: - ``CodeIgniter\Security\SecurityInterface::sanitizeFilename()`` (deprecated since v4.6.2) - ``CodeIgniter\Security\Security::sanitizeFilename()`` (deprecated since v4.6.2) @@ -140,6 +147,13 @@ Others Message Changes *************** +- Removed deprecated language keys tied to removed exception constructors: + - ``Core.missingExtension`` (``FrameworkException::forMissingExtension()``) + - ``HTTP.cannotSetCache`` (``DownloadException::forCannotSetCache()``) + - ``HTTP.invalidSameSiteSetting`` (``HTTPException::forInvalidSameSiteSetting()``) + - ``Security.invalidSameSite`` (``SecurityException::forInvalidSameSite()``) + - ``Session.invalidSameSiteSetting`` (``SessionException::forInvalidSameSiteSetting()``) + ******* Changes *******