Skip to content

Commit

Permalink
feature #30729 [HttpKernel] change $previous argument for HttpExcepti…
Browse files Browse the repository at this point in the history
…on to \Throwable (sGy1980de)

This PR was submitted for the 4.2 branch but it was squashed and merged into the 4.3-dev branch instead (closes #30729).

Discussion
----------

[HttpKernel] change $previous argument for HttpException to \Throwable

| Q             | A
| ------------- | ---
| Branch?       |  4.2
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #30728
| License       | MIT

This will fix #30728 with the suggested solution to change the signature of `HttpException` and all its descendants from `\Exception` to `\Throwable`.

Commits
-------

15cb475 [HttpKernel] change $previous argument for HttpException to \Throwable
  • Loading branch information
fabpot committed Mar 30, 2019
2 parents 30b9617 + 15cb475 commit e9e2f21
Show file tree
Hide file tree
Showing 32 changed files with 77 additions and 59 deletions.
Expand Up @@ -19,11 +19,11 @@ class AccessDeniedHttpException extends HttpException
{
/**
* @param string $message The internal exception message
* @param \Exception $previous The previous exception
* @param \Throwable $previous The previous exception
* @param int $code The internal exception code
* @param array $headers
*/
public function __construct(string $message = null, \Exception $previous = null, int $code = 0, array $headers = [])
public function __construct(string $message = null, \Throwable $previous = null, int $code = 0, array $headers = [])
{
parent::__construct(403, $message, $previous, $headers, $code);
}
Expand Down
Expand Up @@ -18,11 +18,11 @@ class BadRequestHttpException extends HttpException
{
/**
* @param string $message The internal exception message
* @param \Exception $previous The previous exception
* @param \Throwable $previous The previous exception
* @param int $code The internal exception code
* @param array $headers
*/
public function __construct(string $message = null, \Exception $previous = null, int $code = 0, array $headers = [])
public function __construct(string $message = null, \Throwable $previous = null, int $code = 0, array $headers = [])
{
parent::__construct(400, $message, $previous, $headers, $code);
}
Expand Down
Expand Up @@ -18,11 +18,11 @@ class ConflictHttpException extends HttpException
{
/**
* @param string $message The internal exception message
* @param \Exception $previous The previous exception
* @param \Throwable $previous The previous exception
* @param int $code The internal exception code
* @param array $headers
*/
public function __construct(string $message = null, \Exception $previous = null, int $code = 0, array $headers = [])
public function __construct(string $message = null, \Throwable $previous = null, int $code = 0, array $headers = [])
{
parent::__construct(409, $message, $previous, $headers, $code);
}
Expand Down
Expand Up @@ -18,11 +18,11 @@ class GoneHttpException extends HttpException
{
/**
* @param string $message The internal exception message
* @param \Exception $previous The previous exception
* @param \Throwable $previous The previous exception
* @param int $code The internal exception code
* @param array $headers
*/
public function __construct(string $message = null, \Exception $previous = null, int $code = 0, array $headers = [])
public function __construct(string $message = null, \Throwable $previous = null, int $code = 0, array $headers = [])
{
parent::__construct(410, $message, $previous, $headers, $code);
}
Expand Down
Expand Up @@ -21,7 +21,7 @@ class HttpException extends \RuntimeException implements HttpExceptionInterface
private $statusCode;
private $headers;

public function __construct(int $statusCode, string $message = null, \Exception $previous = null, array $headers = [], ?int $code = 0)
public function __construct(int $statusCode, string $message = null, \Throwable $previous = null, array $headers = [], ?int $code = 0)
{
$this->statusCode = $statusCode;
$this->headers = $headers;
Expand Down
Expand Up @@ -18,11 +18,11 @@ class LengthRequiredHttpException extends HttpException
{
/**
* @param string $message The internal exception message
* @param \Exception $previous The previous exception
* @param \Throwable $previous The previous exception
* @param int $code The internal exception code
* @param array $headers
*/
public function __construct(string $message = null, \Exception $previous = null, int $code = 0, array $headers = [])
public function __construct(string $message = null, \Throwable $previous = null, int $code = 0, array $headers = [])
{
parent::__construct(411, $message, $previous, $headers, $code);
}
Expand Down
Expand Up @@ -19,11 +19,11 @@ class MethodNotAllowedHttpException extends HttpException
/**
* @param array $allow An array of allowed methods
* @param string $message The internal exception message
* @param \Exception $previous The previous exception
* @param \Throwable $previous The previous exception
* @param int $code The internal exception code
* @param array $headers
*/
public function __construct(array $allow, string $message = null, \Exception $previous = null, ?int $code = 0, array $headers = [])
public function __construct(array $allow, string $message = null, \Throwable $previous = null, ?int $code = 0, array $headers = [])
{
$headers['Allow'] = strtoupper(implode(', ', $allow));

Expand Down
Expand Up @@ -18,11 +18,11 @@ class NotAcceptableHttpException extends HttpException
{
/**
* @param string $message The internal exception message
* @param \Exception $previous The previous exception
* @param \Throwable $previous The previous exception
* @param int $code The internal exception code
* @param array $headers
*/
public function __construct(string $message = null, \Exception $previous = null, int $code = 0, array $headers = [])
public function __construct(string $message = null, \Throwable $previous = null, int $code = 0, array $headers = [])
{
parent::__construct(406, $message, $previous, $headers, $code);
}
Expand Down
Expand Up @@ -18,11 +18,11 @@ class NotFoundHttpException extends HttpException
{
/**
* @param string $message The internal exception message
* @param \Exception $previous The previous exception
* @param \Throwable $previous The previous exception
* @param int $code The internal exception code
* @param array $headers
*/
public function __construct(string $message = null, \Exception $previous = null, int $code = 0, array $headers = [])
public function __construct(string $message = null, \Throwable $previous = null, int $code = 0, array $headers = [])
{
parent::__construct(404, $message, $previous, $headers, $code);
}
Expand Down
Expand Up @@ -18,11 +18,11 @@ class PreconditionFailedHttpException extends HttpException
{
/**
* @param string $message The internal exception message
* @param \Exception $previous The previous exception
* @param \Throwable $previous The previous exception
* @param int $code The internal exception code
* @param array $headers
*/
public function __construct(string $message = null, \Exception $previous = null, int $code = 0, array $headers = [])
public function __construct(string $message = null, \Throwable $previous = null, int $code = 0, array $headers = [])
{
parent::__construct(412, $message, $previous, $headers, $code);
}
Expand Down
Expand Up @@ -20,11 +20,11 @@ class PreconditionRequiredHttpException extends HttpException
{
/**
* @param string $message The internal exception message
* @param \Exception $previous The previous exception
* @param \Throwable $previous The previous exception
* @param int $code The internal exception code
* @param array $headers
*/
public function __construct(string $message = null, \Exception $previous = null, int $code = 0, array $headers = [])
public function __construct(string $message = null, \Throwable $previous = null, int $code = 0, array $headers = [])
{
parent::__construct(428, $message, $previous, $headers, $code);
}
Expand Down
Expand Up @@ -19,11 +19,11 @@ class ServiceUnavailableHttpException extends HttpException
/**
* @param int|string $retryAfter The number of seconds or HTTP-date after which the request may be retried
* @param string $message The internal exception message
* @param \Exception $previous The previous exception
* @param \Throwable $previous The previous exception
* @param int $code The internal exception code
* @param array $headers
*/
public function __construct($retryAfter = null, string $message = null, \Exception $previous = null, ?int $code = 0, array $headers = [])
public function __construct($retryAfter = null, string $message = null, \Throwable $previous = null, ?int $code = 0, array $headers = [])
{
if ($retryAfter) {
$headers['Retry-After'] = $retryAfter;
Expand Down
Expand Up @@ -21,11 +21,11 @@ class TooManyRequestsHttpException extends HttpException
/**
* @param int|string $retryAfter The number of seconds or HTTP-date after which the request may be retried
* @param string $message The internal exception message
* @param \Exception $previous The previous exception
* @param \Throwable $previous The previous exception
* @param int $code The internal exception code
* @param array $headers
*/
public function __construct($retryAfter = null, string $message = null, \Exception $previous = null, ?int $code = 0, array $headers = [])
public function __construct($retryAfter = null, string $message = null, \Throwable $previous = null, ?int $code = 0, array $headers = [])
{
if ($retryAfter) {
$headers['Retry-After'] = $retryAfter;
Expand Down
Expand Up @@ -19,11 +19,11 @@ class UnauthorizedHttpException extends HttpException
/**
* @param string $challenge WWW-Authenticate challenge string
* @param string $message The internal exception message
* @param \Exception $previous The previous exception
* @param \Throwable $previous The previous exception
* @param int $code The internal exception code
* @param array $headers
*/
public function __construct(string $challenge, string $message = null, \Exception $previous = null, ?int $code = 0, array $headers = [])
public function __construct(string $challenge, string $message = null, \Throwable $previous = null, ?int $code = 0, array $headers = [])
{
$headers['WWW-Authenticate'] = $challenge;

Expand Down
Expand Up @@ -18,11 +18,11 @@ class UnprocessableEntityHttpException extends HttpException
{
/**
* @param string $message The internal exception message
* @param \Exception $previous The previous exception
* @param \Throwable $previous The previous exception
* @param int $code The internal exception code
* @param array $headers
*/
public function __construct(string $message = null, \Exception $previous = null, int $code = 0, array $headers = [])
public function __construct(string $message = null, \Throwable $previous = null, int $code = 0, array $headers = [])
{
parent::__construct(422, $message, $previous, $headers, $code);
}
Expand Down
Expand Up @@ -18,11 +18,11 @@ class UnsupportedMediaTypeHttpException extends HttpException
{
/**
* @param string $message The internal exception message
* @param \Exception $previous The previous exception
* @param \Throwable $previous The previous exception
* @param int $code The internal exception code
* @param array $headers
*/
public function __construct(string $message = null, \Exception $previous = null, int $code = 0, array $headers = [])
public function __construct(string $message = null, \Throwable $previous = null, int $code = 0, array $headers = [])
{
parent::__construct(415, $message, $previous, $headers, $code);
}
Expand Down
Expand Up @@ -6,8 +6,8 @@

class AccessDeniedHttpExceptionTest extends HttpExceptionTest
{
protected function createException()
protected function createException(string $message = null, \Throwable $previous = null, ?int $code = 0, array $headers = [])
{
return new AccessDeniedHttpException();
return new AccessDeniedHttpException($message, $previous, $code, $headers);
}
}
Expand Up @@ -6,8 +6,8 @@

class BadRequestHttpExceptionTest extends HttpExceptionTest
{
protected function createException()
protected function createException(string $message = null, \Throwable $previous = null, ?int $code = 0, array $headers = [])
{
return new BadRequestHttpException();
return new BadRequestHttpException($message, $previous, $code, $headers);
}
}
Expand Up @@ -6,8 +6,8 @@

class ConflictHttpExceptionTest extends HttpExceptionTest
{
protected function createException()
protected function createException(string $message = null, \Throwable $previous = null, ?int $code = 0, array $headers = [])
{
return new ConflictHttpException();
return new ConflictHttpException($message, $previous, $code, $headers);
}
}
Expand Up @@ -6,8 +6,8 @@

class GoneHttpExceptionTest extends HttpExceptionTest
{
protected function createException()
protected function createException(string $message = null, \Throwable $previous = null, ?int $code = 0, array $headers = [])
{
return new GoneHttpException();
return new GoneHttpException($message, $previous, $code, $headers);
}
}
Expand Up @@ -46,8 +46,16 @@ public function testHeadersSetter($headers)
$this->assertSame($headers, $exception->getHeaders());
}

protected function createException()
public function testThrowableIsAllowedForPrevious()
{
return new HttpException(200);
$previous = new class('Error of PHP 7+') extends \Error {
};
$exception = $this->createException(null, $previous);
$this->assertSame($previous, $exception->getPrevious());
}

protected function createException(string $message = null, \Throwable $previous = null, ?int $code = 0, array $headers = [])
{
return new HttpException(200, $message, $previous, $headers, $code);
}
}
Expand Up @@ -6,8 +6,8 @@

class LengthRequiredHttpExceptionTest extends HttpExceptionTest
{
protected function createException()
protected function createException(string $message = null, \Throwable $previous = null, ?int $code = 0, array $headers = [])
{
return new LengthRequiredHttpException();
return new LengthRequiredHttpException($message, $previous, $code, $headers);
}
}
Expand Up @@ -34,4 +34,9 @@ public function testHeadersSetter($headers)
$exception->setHeaders($headers);
$this->assertSame($headers, $exception->getHeaders());
}

protected function createException(string $message = null, \Throwable $previous = null, ?int $code = 0, array $headers = [])
{
return new MethodNotAllowedHttpException(['get'], $message, $previous, $code, $headers);
}
}
Expand Up @@ -6,8 +6,8 @@

class NotAcceptableHttpExceptionTest extends HttpExceptionTest
{
protected function createException()
protected function createException(string $message = null, \Throwable $previous = null, ?int $code = 0, array $headers = [])
{
return new NotAcceptableHttpException();
return new NotAcceptableHttpException($message, $previous, $code, $headers);
}
}
Expand Up @@ -6,8 +6,8 @@

class NotFoundHttpExceptionTest extends HttpExceptionTest
{
protected function createException()
protected function createException(string $message = null, \Throwable $previous = null, ?int $code = 0, array $headers = [])
{
return new NotFoundHttpException();
return new NotFoundHttpException($message, $previous, $code, $headers);
}
}
Expand Up @@ -6,8 +6,8 @@

class PreconditionFailedHttpExceptionTest extends HttpExceptionTest
{
protected function createException()
protected function createException(string $message = null, \Throwable $previous = null, ?int $code = 0, array $headers = [])
{
return new PreconditionFailedHttpException();
return new PreconditionFailedHttpException($message, $previous, $code, $headers);
}
}
Expand Up @@ -6,8 +6,8 @@

class PreconditionRequiredHttpExceptionTest extends HttpExceptionTest
{
protected function createException()
protected function createException(string $message = null, \Throwable $previous = null, ?int $code = 0, array $headers = [])
{
return new PreconditionRequiredHttpException();
return new PreconditionRequiredHttpException($message, $previous, $code, $headers);
}
}
Expand Up @@ -35,8 +35,8 @@ public function testHeadersSetter($headers)
$this->assertSame($headers, $exception->getHeaders());
}

protected function createException()
protected function createException(string $message = null, \Throwable $previous = null, ?int $code = 0, array $headers = [])
{
return new ServiceUnavailableHttpException();
return new ServiceUnavailableHttpException(null, $message, $previous, $code, $headers);
}
}
Expand Up @@ -35,8 +35,8 @@ public function testHeadersSetter($headers)
$this->assertSame($headers, $exception->getHeaders());
}

protected function createException()
protected function createException(string $message = null, \Throwable $previous = null, ?int $code = 0, array $headers = [])
{
return new TooManyRequestsHttpException();
return new TooManyRequestsHttpException(null, $message, $previous, $code, $headers);
}
}
Expand Up @@ -34,4 +34,9 @@ public function testHeadersSetter($headers)
$exception->setHeaders($headers);
$this->assertSame($headers, $exception->getHeaders());
}

protected function createException(string $message = null, \Throwable $previous = null, ?int $code = 0, array $headers = [])
{
return new UnauthorizedHttpException('Challenge', $message, $previous, $code, $headers);
}
}
Expand Up @@ -6,8 +6,8 @@

class UnprocessableEntityHttpExceptionTest extends HttpExceptionTest
{
protected function createException()
protected function createException(string $message = null, \Throwable $previous = null, ?int $code = 0, array $headers = [])
{
return new UnprocessableEntityHttpException();
return new UnprocessableEntityHttpException($message, $previous, $code, $headers);
}
}

0 comments on commit e9e2f21

Please sign in to comment.