8000 feature #30729 [HttpKernel] change $previous argument for HttpExcepti… · symfony/symfony@e9e2f21 · GitHub
[go: up one dir, main page]

Skip to content

Commit e9e2f21

Browse files
committed
feature #30729 [HttpKernel] change $previous argument for HttpException 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
2 parents 30b9617 + 15cb475 commit e9e2f21

32 files changed

+77
-59
lines changed

src/Symfony/Component/HttpKernel/Exception/AccessDeniedHttpException.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ class AccessDeniedHttpException extends HttpException
1919
{
2020
/**
2121
* @param string $message The internal exception message
22-
* @param \Exception $previous The previous exception
22+
* @param \Throwable $previous The previous exception
2323
* @param int $code The internal exception code
2424
* @param array $headers
2525
*/
26-
public function __construct(string $message = null, \Exception $previous = null, int $code = 0, array $headers = [])
26+
public function __construct(string $message = null, \Throwable $previous = null, int $code = 0, array $headers = [])
2727
{
2828
parent::__construct(403, $message, $previous, $headers, $code);
2929
}

src/Symfony/Component/HttpKernel/Exception/BadRequestHttpException.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ class BadRequestHttpException extends HttpException
1818
{
1919
/**
2020
* @param string $message The internal exception message
21-
* @param \Exception $previous The previous exception
21+
* @param \Throwable $previous The previous exception
2222
* @param int $code The internal exception code
2323
* @param array $headers
2424
*/
25-
public function __construct(string $message = null, \Exception $previous = null, int $code = 0, array $headers = [])
25+
public function __construct(string $message = null, \Throwable $previous = null, int $code = 0, array $headers = [])
2626
{
2727
parent::__construct(400, $message, $previous, $headers, $code);
2828
}

src/Symfony/Component/HttpKernel/Exception/ConflictHttpException.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ class ConflictHttpException extends HttpException
1818
{
1919
/**
2020
* @param string $message The internal exception message
21-
* @param \Exception $previous The previous exception
21+
* @param \Throwable $previous The previous exception
2222
* @param int $code The internal exception code
2323
* @param array $headers
2424
*/
25-
public function __construct(string $message = null, \Exception $previous = null, int $code = 0, array $headers = [])
25+
public function __construct(string $message = null, \Throwable $previous = null, int $code = 0, array $headers = [])
2626
{
2727
parent::__construct(409, $message, $previous, $headers, $code);
2828
}

src/Symfony/Component/HttpKernel/Exception/GoneHttpException.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ class GoneHttpException extends HttpException
1818
{
1919
/**
2020
* @param string $message The internal exception message
21-
* @param \Exception $previous The previous exception
21+
* @param \Throwable $previous The previous exception
2222
* @param int $code The internal exception code
2323
* @param array $headers
2424
*/
25-
public function __construct(string $message = null, \Exception $previous = null, int $code = 0, array $headers = [])
25+
public function __construct(string $message = null, \Throwable $previous = null, int $code = 0, array $headers = [])
2626
{
2727
parent::__construct(410, $message, $previous, $headers, $code);
2828
}

src/Symfony/Component/HttpKernel/Exception/HttpException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class HttpException extends \RuntimeException implements HttpExceptionInterface
2121
private $statusCode;
2222
private $headers;
2323

24-
public function __construct(int $statusCode, string $message = null, \Exception $previous = null, array $headers = [], ?int $code = 0)
24+
public function __construct(int $statusCode, string $message = null, \Throwable $previous = null, array $headers = [], ?int $code = 0)
2525
{
2626
$this->statusCode = $statusCode;
2727
$this->headers = $headers;

src/Symfony/Component/HttpKernel/Exception/LengthRequiredHttpException.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ class LengthRequiredHttpException extends HttpException
1818
{
1919
/**
2020
* @param string $message The internal exception message
21-
* @param \Exception $previous The previous exception
21+
* @param \Throwable $previous The previous exception
2222
* @param int $code The internal exception code
2323
* @param array $headers
2424
*/
25-
public function __construct(string $message = null, \Exception $previous = null, int $code = 0, array $headers = [])
25+
public function __construct(string $message = null, \Throwable $previous = null, int $code = 0, array $headers = [])
2626
{
2727
parent::__construct(411, $message, $previous, $headers, $code);
2828
}

src/Symfony/Component/HttpKernel/Exception/MethodNotAllowedHttpException.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ class MethodNotAllowedHttpException extends HttpException
1919
/**
2020
* @param array $allow An array of allowed methods
2121
* @param string $message The internal exception message
22-
* @param \Exception $previous The previous exception
22+
* @param \Throwable $previous The previous exception
2323
* @param int $code The internal exception code
2424
* @param array $headers
2525
*/
26-
public function __construct(array $allow, string $message = null, \Exception $previous = null, ?int $code = 0, array $headers = [])
26+
public function __construct(array $allow, string $message = null, \Throwable $previous = null, ?int $code = 0, array $headers = [])
2727
{
2828
$headers['Allow'] = strtoupper(implode(', ', $allow));
2929

src/Symfony/Component/HttpKernel/Exception/NotAcceptableHttpException.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ class NotAcceptableHttpException extends HttpException
1818
{
1919
/**
2020
* @param string $message The internal exception message
21-
* @param \Exception $previous The previous exception
21+
* @param \Throwable $previous The previous exception
2222
* @param int $code The internal exception code
2323
* @param array $headers
2424
*/
25-
public function __construct(string $message = null, \Exception $previous = null, int $code = 0, array $headers = [])
25+
public function __construct(string $message = null, \Throwable $previous = null, int $code = 0, array $headers = [])
2626
{
2727
parent::__construct(406, $message, $previous, $headers, $code);
2828
}

src/Symfony/Component/HttpKernel/Exception/NotFoundHttpException.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ class NotFoundHttpException extends HttpException
1818
{
1919
/**
2020
* @param string $message The internal exception message
21-
* @param \Exception $previous The previous exception
21+
* @param \Throwable $previous The previous exception
2222
* @param int $code The internal exception code
2323
* @param array $headers
2424
*/
25-
public function __construct(string $message = null, \Exception $previous = null, int $code = 0, array $headers = [])
25+
public function __construct(string $message = null, \Throwable $previous = null, int $code = 0, array $headers = [])
2626
{
2727
parent::__construct(404, $message, $previous, $headers, $code);
2828
}

src/Symfony/Component/HttpKernel/Exception/PreconditionFailedHttpException.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ class PreconditionFailedHttpException extends HttpException
1818
{
1919
/**
2020
* @param string $message The internal exception message
21-
* @param \Exception $previous The previous exception
21+
* @param \Throwable $previous The previous exception
2222
* @param int $code The internal exception code
2323
* @param array $headers
2424
*/
25-
public function __construct(string $message = null, \Exception $previous = null, int $code = 0, array $headers = [])
25+
public function __construct(string $message = null, \Throwable $previous = null, int $code = 0, array $headers = [])
2626
{
2727
parent::__construct(412, $message, $previous, $headers, $code);
2828
}

src/Symfony/Component/HttpKernel/Exception/PreconditionRequiredHttpException.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ class PreconditionRequiredHttpException extends HttpException
2020
{
2121
/**
2222
* @param string $message The internal exception message
23-
* @param \Exception $previous The previous exception
23+
* @param \Throwable $previous The previous exception
2424
* @param int $code The internal exception code
2525
* @param array $headers
2626
*/
27-
public function __construct(string $message = null, \Exception $previous = null, int $code = 0, array $headers = [])
27+
public function __construct(string $message = null, \Throwable $previous = null, int $code = 0, array $headers = [])
2828
{
2929
parent::__construct(428, $message, $previous, $headers, $code);
3030
}

src/Symfony/Component/HttpKernel/Exception/ServiceUnavailableHttpException.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ class ServiceUnavailableHttpException extends HttpException
1919
/**
2020
* @param int|string $retryAfter The number of seconds or HTTP-date after which the request may be retried
2121
* @param string $message The internal exception message
22-
* @param \Exception $previous The previous exception
22+
* @param \Throwable $previous The previous exception
2323
* @param int $code The internal exception code
2424
* @param array $headers
2525
*/
26-
public function __construct($retryAfter = null, string $message = null, \Exception $previous = null, ?int $code = 0, array $headers = [])
26+
public function __construct($retryAfter = null, string $message = null, \Throwable $previous = null, ?int $code = 0, array $headers = [])
2727
{
2828
if ($retryAfter) {
2929
$headers['Retry-After'] = $retryAfter;

src/Symfony/Component/HttpKernel/Exception/TooManyRequestsHttpException.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ class TooManyRequestsHttpException extends HttpException
2121
/**
2222
* @param int|string $retryAfter The number of seconds or HTTP-date after which the request may be retried
2323
* @param string $message The internal exception message
24-
* @param \Exception $previous The previous exception
24+
* @param \Throwable $previous The previous exception
2525
* @param int $code The internal exception code
2626
* @param array $headers
2727
*/
28-
public function __construct($retryAfter = null, string $message = null, \Exception $previous = null, ?int $code = 0, array $headers = [])
28+
public function __construct($retryAfter = null, string $message = null, \Throwable $previous = null, ?int $code = 0, array $headers = [])
2929
{
3030
if ($retryAfter) {
3131
$headers['Retry-After'] = $retryAfter;

src/Symfony/Component/HttpKernel/Exception/UnauthorizedHttpException.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ class UnauthorizedHttpException extends HttpException
1919
/**
2020
* @param string $challenge WWW-Authenticate challenge string
2121
* @param string $message The internal exception message
22-
* @param \Exception $previous The previous exception
22+
* @param \Throwable $previous The previous exception
2323
* @param int $code The internal exception code
2424
* @param array $headers
2525
*/
26-
public function __construct(string $challenge, string $message = null, \Exception $previous = null, ?int $code = 0, array $headers = [])
26+
public function __construct(string $challenge, string $message = null, \Throwable $previous = null, ?int $code = 0, array $headers = [])
27 F438 27
{
2828
$headers['WWW-Authenticate'] = $challenge;
2929

src/Symfony/Component/HttpKernel/Exception/UnprocessableEntityHttpException.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ class UnprocessableEntityHttpException extends HttpException
1818
{
1919
/**
2020
* @param string $message The internal exception message
21-
* @param \Exception $previous The previous exception
21+
* @param \Throwable $previous The previous exception
2222
* @param int $code The internal exception code
2323
* @param array $headers
2424
*/
25-
public function __construct(string $message = null, \Exception $previous = null, int $code = 0, array $headers = [])
25+
public function __construct(string $message = null, \Throwable $previous = null, int $code = 0, array $headers = [])
2626
{
2727
parent::__construct(422, $message, $previous, $headers, $code);
2828
}

src/Symfony/Component/HttpKernel/Exception/UnsupportedMediaTypeHttpException.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ class UnsupportedMediaTypeHttpException extends HttpException
1818
{
1919
/**
2020
* @param string $message The internal exception message
21-
* @param \Exception $previous The previous exception
21+
* @param \Throwable $previous The previous exception
2222
* @param int $code The internal exception code
2323
* @param array $headers
2424
*/
25-
public function __construct(string $message = null, \Exception $previous = null, int $code = 0, array $headers = [])
25+
public function __construct(string $message = null, \Throwable $previous = null, int $code = 0, array $headers = [])
2626
{
2727
parent::__construct(415, $message, $previous, $headers, $code);
2828
}

src/Symfony/Component/HttpKernel/Tests/Exception/AccessDeniedHttpExceptionTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
class AccessDeniedHttpExceptionTest extends HttpExceptionTest
88
{
9-
protected function createException()
9+
protected function createException(string $message = null, \Throwable $previous = null, ?int $code = 0, array $headers = [])
1010
{
11-
return new AccessDeniedHttpException();
11+
return new AccessDeniedHttpException($message, $previous, $code, $headers);
1212
}
1313
}

src/Symfony/Component/HttpKernel/Tests/Exception/BadRequestHttpExceptionTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
class BadRequestHttpExceptionTest extends HttpExceptionTest
88
{
9-
protected function createException()
9+
protected function createException(string $message = null, \Throwable $previous = null, ?int $code = 0, array $headers = [])
1010
{
11-
return new BadRequestHttpException();
11+
return new BadRequestHttpException($message, $previous, $code, $headers);
1212
}
1313
}

src/Symfony/Component/HttpKernel/Tests/Exception/ConflictHttpExceptionTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
class ConflictHttpExceptionTest extends HttpExceptionTest
88
{
9-
protected function createException()
9+
protected function createException(string $message = null, \Throwable $previous = null, ?int $code = 0, array $headers = [])
1010
{
11-
return new ConflictHttpException();
11+
return new ConflictHttpException($message, $previous, $code, $headers);
1212
}
1313
}

src/Symfony/Component/HttpKernel/Tests/Exception/GoneHttpExceptionTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
class GoneHttpExceptionTest extends HttpExceptionTest
88
{
9-
protected function createException()
9+
protected function createException(string $message = null, \Throwable $previous = null, ?int $code = 0, array $headers = [])
1010
{
11-
return new GoneHttpException();
11+
return new GoneHttpException($message, $previous, $code, $headers);
1212
}
1313
}

src/Symfony/Component/HttpKernel/Tests/Exception/HttpExceptionTest.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,16 @@ public function testHeadersSetter($headers)
4646
$this->assertSame($headers, $exception->getHeaders());
4747
}
4848

49-
protected function createException()
49+
public function testThrowableIsAllowedForPrevious()
5050
{
51-
return new HttpException(200);
51+
$previous = new class('Error of PHP 7+') extends \Error {
52+
};
53+
$exception = $this->createException(null, $previous);
54+
$this->assertSame($previous, $exception->getPrevious());
55+
}
56+
57+
protected function createException(string $message = null, \Throwable $previous = null, ?int $code = 0, array $headers = [])
58+
{
59+
return new HttpException(200, $message, $previous, $headers, $code);
5260
}
5361
}

src/Symfony/Component/HttpKernel/Tests/Exception/LengthRequiredHttpExceptionTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
class LengthRequiredHttpExceptionTest extends HttpExceptionTest
88
{
9-
protected function createException()
9+
protected function createException(string $message = null, \Throwable $previous = null, ?int $code = 0, array $headers = [])
1010
{
11-
return new LengthRequiredHttpException();
11+
return new LengthRequiredHttpException($message, $previous, $code, $headers);
1212
}
1313
}

src/Symfony/Component/HttpKernel/Tests/Exception/MethodNotAllowedHttpExceptionTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,9 @@ public function testHeadersSetter($headers)
3434
$exception->setHeaders($headers);
3535
$this->assertSame($headers, $exception->getHeaders());
3636
}
37+
38+
protected function createException(string $message = null, \Throwable $previous = null, ?int $code = 0, array $headers = [])
39+
{
40+
return new MethodNotAllowedHttpException(['get'], $message, $previous, $code, $headers);
41+
}
3742
}

src/Symfony/Component/HttpKernel/Tests/Exception/NotAcceptableHttpExceptionTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
class NotAcceptableHttpExceptionTest extends HttpExceptionTest
88
{
9-
protected function createException()
9+
protected function createException(string $message = null, \Throwable $previous = null, ?int $code = 0, array $headers = [])
1010
{
11-
return new NotAcceptableHttpException();
11+
return new NotAcceptableHttpException($message, $previous, $code, $headers);
1212
}
1313
}

src/Symfony/Component/HttpKernel/Tests/Exception/NotFoundHttpExceptionTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
class NotFoundHttpExceptionTest extends HttpExceptionTest
88
{
9-
protected function createException()
9+
protected function createException(string $message = null, \Throwable $previous = null, ?int $code = 0, array $headers = [])
1010
{
11-
return new NotFoundHttpException();
11+
return new NotFoundHttpException($message, $previous, $code, $headers);
1212
}
1313
}

src/Symfony/Component/HttpKernel/Tests/Exception/PreconditionFailedHttpExceptionTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
class PreconditionFailedHttpExceptionTest extends HttpExceptionTest
88
{
9-
protected function createException()
9+
protected function createException(string $message = null, \Throwable $previous = null, ?int $code = 0, array $headers = [])
1010
{
11-
return new PreconditionFailedHttpException();
11+
return new PreconditionFailedHttpException($message, $previous, $code, $headers);
1212
}
1313
}

src/Symfony/Component/HttpKernel/Tests/Exception/PreconditionRequiredHttpExceptionTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
class PreconditionRequiredHttpExceptionTest extends HttpExceptionTest
88
{
9-
protected function createException()
9+
protected function createException(string $message = null, \Throwable $previous = null, ?int $code = 0, array $headers = [])
1010
{
11-
return new PreconditionRequiredHttpException();
11+
return new PreconditionRequiredHttpException($message, $previous, $code, $headers);
1212
}
1313
}

src/Symfony/Component/HttpKernel/Tests/Exception/ServiceUnavailableHttpExceptionTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ public function testHeadersSetter($headers)
3535
$this->assertSame($headers, $exception->getHeaders());
3636
}
3737

38-
protected function createException()
38+
protected function createException(string $message = null, \Throwable $previous = null, ?int $code = 0, array $headers = [])
3939
{
40-
return new ServiceUnavailableHttpException();
40+
return new ServiceUnavailableHttpException(null, $message, $previous, $code, $headers);
4141
}
4242
}

src/Symfony/Component/HttpKernel/Tests/Exception/TooManyRequestsHttpExceptionTest.php

Lines changed: 2 additions & 2 deletions
741A
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ public function testHeadersSetter($headers)
3535
$this->assertSame($headers, $exception->getHeaders());
3636
}
3737

38-
protected function createException()
38+
protected function createException(string $message = null, \Throwable $previous = null, ?int $code = 0, array $headers = [])
3939
{
40-
return new TooManyRequestsHttpException();
40+
return new TooManyRequestsHttpException(null, $message, $previous, $code, $headers);
4141
}
4242
}

src/Symfony/Component/HttpKernel/Tests/Exception/UnauthorizedHttpExceptionTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,9 @@ public function testHeadersSetter($headers)
3434
$exception->setHeaders($headers);
3535
$this->assertSame($headers, $exception->getHeaders());
3636
}
37+
38+
protected function createException(string $message = null, \Throwable $previous = null, ?int $code = 0, array $headers = [])
39+
{
40+
return new UnauthorizedHttpException('Challenge', $message, $previous, $code, $headers);
41+
}
3742
}

src/Symfony/Component/HttpKernel/Tests/Exception/UnprocessableEntityHttpExceptionTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
class UnprocessableEntityHttpExceptionTest extends HttpExceptionTest
88
{
9-
protected function createException()
9+
protected function createException(string $message = null, \Throwable $previous = null, ?int $code = 0, array $headers = [])
1010
{
11-
return new UnprocessableEntityHttpException();
11+
return new UnprocessableEntityHttpException($message, $previous, $code, $headers);
1212
}
1313
}

0 commit comments

Comments
 (0)
0