Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert RedirectException change #2338

Merged
merged 4 commits into from
Oct 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions system/CodeIgniter.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
namespace CodeIgniter;

use Closure;
use CodeIgniter\Filters\Exceptions\FilterException;
use CodeIgniter\HTTP\DownloadResponse;
use CodeIgniter\HTTP\RedirectResponse;
use CodeIgniter\HTTP\Request;
Expand All @@ -50,6 +49,7 @@
use CodeIgniter\Events\Events;
use CodeIgniter\HTTP\Response;
use CodeIgniter\HTTP\CLIRequest;
use CodeIgniter\Router\Exceptions\RedirectException;
use CodeIgniter\Router\RouteCollectionInterface;
use CodeIgniter\Exceptions\PageNotFoundException;
use Exception;
Expand Down Expand Up @@ -209,7 +209,7 @@ public function initialize()
* @param boolean $returnResponse
*
* @return boolean|\CodeIgniter\HTTP\RequestInterface|\CodeIgniter\HTTP\Response|\CodeIgniter\HTTP\ResponseInterface|mixed
* @throws \CodeIgniter\Filters\Exceptions\FilterException
* @throws \CodeIgniter\Router\Exceptions\RedirectException
* @throws \Exception
*/
public function run(RouteCollectionInterface $routes = null, bool $returnResponse = false)
Expand Down Expand Up @@ -244,14 +244,16 @@ public function run(RouteCollectionInterface $routes = null, bool $returnRespons
{
return $this->handleRequest($routes, $cacheConfig, $returnResponse);
}
catch (FilterException $e)
catch (RedirectException $e)
{
$logger = Services::logger();
$logger->info('REDIRECTED ROUTE at ' . $e->getMessage());

// If the route is a 'redirect' route, it throws
// the exception with the $to as the message
$this->response->redirect($e->getMessage(), 'auto', $e->getCode());
$this->sendResponse();

$this->callExit(EXIT_SUCCESS);
}
catch (PageNotFoundException $e)
Expand Down
5 changes: 1 addition & 4 deletions system/Router/Exceptions/RedirectException.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,5 @@

class RedirectException extends \Exception
{
public static function forUnableToRedirect(string $route, string $code)
{
return new static(lang('Redirect.forUnableToRedirect', [$route, $code]));
}
protected $code = 302;
}
2 changes: 1 addition & 1 deletion system/Router/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ protected function checkRoutes(string $uri): bool
// Is this route supposed to redirect to another?
if ($this->collection->isRedirect($key))
{
throw RedirectException::forUnableToRedirect($val, $this->collection->getRedirectCode($key));
throw new RedirectException($val, $this->collection->getRedirectCode($key));
}

$this->setRequest(explode('/', $val));
Expand Down
13 changes: 13 additions & 0 deletions user_guide_src/source/general/errors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,16 @@ or when it is temporarily lost::
throw new \CodeIgniter\Database\Exceptions\DatabaseException();

This provides an HTTP status code of 500 and an exit code of 8.

RedirectException
-----------------

This exception is a special case allowing for overriding of all other response routing and
forcing a redirect to a specific route or URL.

throw new \CodeIgniter\Router\Exceptions\RedirectException($route);

``$route`` may be a named route, relative URI, or a complete URL. You can also supply a
redirect code to use instead of the default (``302``, "temporary redirect"):

throw new \CodeIgniter\Router\Exceptions\RedirectException($route, 301);