Exceptions: Added some types, simplified some classes
During review of #4291
This commit is contained in:
		
							parent
							
								
									34d8268b2b
								
							
						
					
					
						commit
						e72cf61f7e
					
				| 
						 | 
					@ -9,13 +9,8 @@ use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
 | 
				
			||||||
class NotifyException extends Exception implements Responsable, HttpExceptionInterface
 | 
					class NotifyException extends Exception implements Responsable, HttpExceptionInterface
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    public $message;
 | 
					    public $message;
 | 
				
			||||||
    public $redirectLocation;
 | 
					    public string $redirectLocation;
 | 
				
			||||||
    protected $status;
 | 
					    protected int $status;
 | 
				
			||||||
 | 
					 | 
				
			||||||
    /**
 | 
					 | 
				
			||||||
     * @var array<mixed>
 | 
					 | 
				
			||||||
     */
 | 
					 | 
				
			||||||
    protected array $headers = [];
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public function __construct(string $message, string $redirectLocation = '/', int $status = 500)
 | 
					    public function __construct(string $message, string $redirectLocation = '/', int $status = 500)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
| 
						 | 
					@ -23,18 +18,11 @@ class NotifyException extends Exception implements Responsable, HttpExceptionInt
 | 
				
			||||||
        $this->redirectLocation = $redirectLocation;
 | 
					        $this->redirectLocation = $redirectLocation;
 | 
				
			||||||
        $this->status = $status;
 | 
					        $this->status = $status;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if ($status >= 300 && $status < 400) {
 | 
					 | 
				
			||||||
            // add redirect header only when a matching HTTP status is given
 | 
					 | 
				
			||||||
            $this->headers = ['location' => $redirectLocation];
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        parent::__construct();
 | 
					        parent::__construct();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Get the desired HTTP status code for this exception.
 | 
					     * Get the desired HTTP status code for this exception.
 | 
				
			||||||
     *
 | 
					 | 
				
			||||||
     * {@inheritdoc}
 | 
					 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public function getStatusCode(): int
 | 
					    public function getStatusCode(): int
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
| 
						 | 
					@ -43,20 +31,10 @@ class NotifyException extends Exception implements Responsable, HttpExceptionInt
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Get the desired HTTP headers for this exception.
 | 
					     * Get the desired HTTP headers for this exception.
 | 
				
			||||||
     *
 | 
					 | 
				
			||||||
     * {@inheritdoc}
 | 
					 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public function getHeaders(): array
 | 
					    public function getHeaders(): array
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        return $this->headers;
 | 
					        return [];
 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /**
 | 
					 | 
				
			||||||
     * @param array<mixed> $headers
 | 
					 | 
				
			||||||
     */
 | 
					 | 
				
			||||||
    public function setHeaders(array $headers): void
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        $this->headers = $headers;
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -8,20 +8,8 @@ use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class PrettyException extends Exception implements Responsable, HttpExceptionInterface
 | 
					class PrettyException extends Exception implements Responsable, HttpExceptionInterface
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    /**
 | 
					    protected ?string $subtitle = null;
 | 
				
			||||||
     * @var ?string
 | 
					    protected ?string $details = null;
 | 
				
			||||||
     */
 | 
					 | 
				
			||||||
    protected $subtitle = null;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /**
 | 
					 | 
				
			||||||
     * @var ?string
 | 
					 | 
				
			||||||
     */
 | 
					 | 
				
			||||||
    protected $details = null;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /**
 | 
					 | 
				
			||||||
     * @var array
 | 
					 | 
				
			||||||
     */
 | 
					 | 
				
			||||||
    protected $headers = [];
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Render a response for when this exception occurs.
 | 
					     * Render a response for when this exception occurs.
 | 
				
			||||||
| 
						 | 
					@ -63,19 +51,9 @@ class PrettyException extends Exception implements Responsable, HttpExceptionInt
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Get the desired HTTP headers for this exception.
 | 
					     * Get the desired HTTP headers for this exception.
 | 
				
			||||||
     * @return array<mixed>
 | 
					 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public function getHeaders(): array
 | 
					    public function getHeaders(): array
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        return $this->headers;
 | 
					        return [];
 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /**
 | 
					 | 
				
			||||||
     * Set the desired HTTP headers for this exception.
 | 
					 | 
				
			||||||
     * @param array<mixed> $headers
 | 
					 | 
				
			||||||
     */
 | 
					 | 
				
			||||||
    public function setHeaders(array $headers): void
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        $this->headers = $headers;
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue