Skip to content

Commit

Permalink
refactor: Remove deprecated RedirectException (#9399)
Browse files Browse the repository at this point in the history
* refacror: Remove CodeIgniter\Router\Exceptions\RedirectException

* docs: Update changelog, userguide
  • Loading branch information
neznaika0 authored Jan 11, 2025
1 parent 1f7e106 commit f67bc68
Show file tree
Hide file tree
Showing 7 changed files with 6 additions and 70 deletions.
6 changes: 1 addition & 5 deletions system/CodeIgniter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
32 changes: 0 additions & 32 deletions system/Router/Exceptions/RedirectException.php

This file was deleted.

24 changes: 0 additions & 24 deletions tests/system/CodeIgniterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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', '/'];
Expand Down
1 change: 1 addition & 0 deletions user_guide_src/source/changelogs/v4.6.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion user_guide_src/source/general/errors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

-
Expand Down
7 changes: 1 addition & 6 deletions utils/phpstan-baseline/property.phpDocType.neon
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# total 48 errors
# total 47 errors

parameters:
ignoreErrors:
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f67bc68

Please sign in to comment.