HttpRedirectionException

Since v2.0.0

Description

HttpRedirectionException is an interface. It is implemented by any exception that maps onto any of the HTTP 3xx status values.

Public Interface

HttpRedirectionException has the following public interface:

// HttpRedirectionException lives in this namespace
namespace GanbaroDigital\HttpStatus\Interfaces;

// our base interfaces
use GanbaroDigital\HttpStatus\Interfaces\HttpException;

// our return types
use GanbaroDigital\HttpStatus\Interfaces\HttpStatus;

interface HttpRedirectionException extends HttpException
{
    /**
     * returns the HTTP status code that best represents this object
     *
     * @return HttpStatus
     * @inheritedFrom HttpStatusProvider
     */
    public function getHttpStatus();
}

How To Use

In Your Own Exceptions

Implement HttpRedirectionException in any exceptions that map onto a HTTP 3xx status value. Combine it with one of the status provider traits to quickly and easily add the getHttpStatus() method that HttpRedirectionException requires:

use GanbaroDigital\HttpStatus\Interfaces\HttpRedirectionException;
use GanbaroDigital\HttpStatus\StatusProviders\Redirection\TemporaryRedirectStatusProvider;
use RuntimeException;

class MyException extends HttpRedirectionException
{
    // adds getHttpStatus()
    // returns a HttpStatus value object of 307 Temporary Redirect
    use TemporaryRedirectStatusProvider;
}

try {
    // ...
}
catch (HttpRedirectionException $e) {
    $httpStatus = $e->getHttpStatus();
    // ...
}

Notes

None at this time.

See Also