From f67bc687d596cbb4a39a008c40f4fa8f72d75e96 Mon Sep 17 00:00:00 2001 From: neznaika0 Date: Sat, 11 Jan 2025 22:12:59 +0300 Subject: [PATCH] refactor: Remove deprecated `RedirectException` (#9399) * refacror: Remove CodeIgniter\Router\Exceptions\RedirectException * docs: Update changelog, userguide --- system/CodeIgniter.php | 6 +--- .../Router/Exceptions/RedirectException.php | 32 ------------------- tests/system/CodeIgniterTest.php | 24 -------------- user_guide_src/source/changelogs/v4.6.0.rst | 1 + user_guide_src/source/general/errors.rst | 2 +- .../codeigniter.superglobalAccessAssign.neon | 4 +-- .../phpstan-baseline/property.phpDocType.neon | 7 +--- 7 files changed, 6 insertions(+), 70 deletions(-) delete mode 100644 system/Router/Exceptions/RedirectException.php diff --git a/system/CodeIgniter.php b/system/CodeIgniter.php index 14ae2d7bc495..9f41545c7c65 100644 --- a/system/CodeIgniter.php +++ b/system/CodeIgniter.php @@ -29,7 +29,6 @@ use CodeIgniter\HTTP\ResponsableInterface; use CodeIgniter\HTTP\ResponseInterface; use CodeIgniter\HTTP\URI; -use CodeIgniter\Router\Exceptions\RedirectException as DeprecatedRedirectException; use CodeIgniter\Router\RouteCollectionInterface; use CodeIgniter\Router\Router; use Config\App; @@ -353,11 +352,8 @@ public function run(?RouteCollectionInterface $routes = null, bool $returnRespon } else { try { $this->response = $this->handleRequest($routes, config(Cache::class), $returnResponse); - } catch (DeprecatedRedirectException|ResponsableInterface $e) { + } catch (ResponsableInterface $e) { $this->outputBufferingEnd(); - if ($e instanceof DeprecatedRedirectException) { - $e = new RedirectException($e->getMessage(), $e->getCode(), $e); - } $this->response = $e->getResponse(); } catch (PageNotFoundException $e) { diff --git a/system/Router/Exceptions/RedirectException.php b/system/Router/Exceptions/RedirectException.php deleted file mode 100644 index 4baef3278dd9..000000000000 --- a/system/Router/Exceptions/RedirectException.php +++ /dev/null @@ -1,32 +0,0 @@ - - * - * For the full copyright and license information, please view - * the LICENSE file that was distributed with this source code. - */ - -namespace CodeIgniter\Router\Exceptions; - -use CodeIgniter\Exceptions\HTTPExceptionInterface; -use Exception; - -/** - * RedirectException - * - * @deprecated Use \CodeIgniter\HTTP\Exceptions\RedirectException instead - */ -class RedirectException extends Exception implements HTTPExceptionInterface -{ - /** - * HTTP status code for redirects - * - * @var int - */ - protected $code = 302; -} diff --git a/tests/system/CodeIgniterTest.php b/tests/system/CodeIgniterTest.php index 5679c0540858..988eac4cf48d 100644 --- a/tests/system/CodeIgniterTest.php +++ b/tests/system/CodeIgniterTest.php @@ -19,7 +19,6 @@ use CodeIgniter\Exceptions\PageNotFoundException; use CodeIgniter\HTTP\Method; use CodeIgniter\HTTP\Response; -use CodeIgniter\Router\Exceptions\RedirectException; use CodeIgniter\Router\RouteCollection; use CodeIgniter\Test\CIUnitTestCase; use CodeIgniter\Test\Filters\CITestStreamFilter; @@ -600,29 +599,6 @@ public function testRunRedirectionWithPOSTAndHTTPCode301(): void $this->assertSame(301, $response->getStatusCode()); } - /** - * test for deprecated \CodeIgniter\Router\Exceptions\RedirectException for backward compatibility - */ - public function testRedirectExceptionDeprecated(): void - { - $_SERVER['argv'] = ['index.php', '/']; - $_SERVER['argc'] = 2; - - // Inject mock router. - $routes = service('routes'); - $routes->get('/', static function (): never { - throw new RedirectException('redirect-exception', 503); - }); - - $router = service('router', $routes, service('incomingrequest')); - Services::injectMock('router', $router); - - $response = $this->codeigniter->run($routes, true); - - $this->assertSame(503, $response->getStatusCode()); - $this->assertSame('http://example.com/redirect-exception', $response->getHeaderLine('Location')); - } - public function testStoresPreviousURL(): void { $_SERVER['argv'] = ['index.php', '/']; diff --git a/user_guide_src/source/changelogs/v4.6.0.rst b/user_guide_src/source/changelogs/v4.6.0.rst index cc3dcacd1a73..a9d78539e23c 100644 --- a/user_guide_src/source/changelogs/v4.6.0.rst +++ b/user_guide_src/source/changelogs/v4.6.0.rst @@ -198,6 +198,7 @@ Removed Deprecated Items - **Logger:** The deprecated ``CodeIgniter\Log\Logger::cleanFilenames()`` and ``CodeIgniter\Test\TestLogger::cleanup()`` have been removed. Use the ``clean_path()`` function instead. + **Router:** The deprecated ``CodeIgniter\Router\Exceptions\RedirectException`` has been removed. Use ``CodeIgniter\HTTP\Exceptions\RedirectException`` instead. ************ Enhancements diff --git a/user_guide_src/source/general/errors.rst b/user_guide_src/source/general/errors.rst index 9adeb7c6db26..2a79f5a33425 100644 --- a/user_guide_src/source/general/errors.rst +++ b/user_guide_src/source/general/errors.rst @@ -209,7 +209,7 @@ RedirectException .. note:: Since v4.4.0, the namespace of ``RedirectException`` has been changed. Previously it was ``CodeIgniter\Router\Exceptions\RedirectException``. The - previous class is deprecated. + previous class has been removed in v4.6.0. This exception is a special case allowing for overriding of all other response routing and forcing a redirect to a specific URI: diff --git a/utils/phpstan-baseline/codeigniter.superglobalAccessAssign.neon b/utils/phpstan-baseline/codeigniter.superglobalAccessAssign.neon index 1db54be1c767..7071f868984a 100644 --- a/utils/phpstan-baseline/codeigniter.superglobalAccessAssign.neon +++ b/utils/phpstan-baseline/codeigniter.superglobalAccessAssign.neon @@ -164,12 +164,12 @@ parameters: - message: '#^Assigning 2 directly on offset ''argc'' of \$_SERVER is discouraged\.$#' - count: 27 + count: 26 path: ../../tests/system/CodeIgniterTest.php - message: '#^Assigning array\{''index\.php'', ''/''\} directly on offset ''argv'' of \$_SERVER is discouraged\.$#' - count: 12 + count: 11 path: ../../tests/system/CodeIgniterTest.php - diff --git a/utils/phpstan-baseline/property.phpDocType.neon b/utils/phpstan-baseline/property.phpDocType.neon index 3e3eaeecbd38..f186ad067cb0 100644 --- a/utils/phpstan-baseline/property.phpDocType.neon +++ b/utils/phpstan-baseline/property.phpDocType.neon @@ -1,4 +1,4 @@ -# total 48 errors +# total 47 errors parameters: ignoreErrors: @@ -172,11 +172,6 @@ parameters: count: 1 path: ../../system/Images/Handlers/ImageMagickHandler.php - - - message: '#^PHPDoc type int of property CodeIgniter\\Router\\Exceptions\\RedirectException\:\:\$code is not the same as PHPDoc type mixed of overridden property Exception\:\:\$code\.$#' - count: 1 - path: ../../system/Router/Exceptions/RedirectException.php - - message: '#^PHPDoc type string of property CodeIgniter\\Session\\Handlers\\FileHandler\:\:\$savePath is not the same as PHPDoc type array\|string of overridden property CodeIgniter\\Session\\Handlers\\BaseHandler\:\:\$savePath\.$#' count: 1