8000 Deprecate things that prevent \Throwable from bubbling down · symfony/symfony@f179713 · GitHub
[go: up one dir, main page]

Skip to content

Commit f179713

Browse files
committed
Deprecate things that prevent \Throwable from bubbling down
1 parent 43739db commit f179713

40 files changed

+379
-76
lines changed

src/Symfony/Bridge/Doctrine/DataCollector/DoctrineDataCollector.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,21 @@ public function addLogger($name, DebugStack $logger)
5454

5555
/**
5656
* {@inheritdoc}
57+
*
58+
* @param \Throwable|null $exception
5759
*/
58-
public function collect(Request $request, Response $response, \Exception $exception = null)
60+
public function collect(Request $request, Response $response/*, \Throwable $exception = null*/)
5961
{
62+
if (__CLASS__ !== \get_class($this) && __CLASS__ !== ($methodRefl = new \ReflectionMethod($this, __FUNCTION__))->getDeclaringClass()->getName() && !$this instanceof \PHPUnit\Framework\MockObject\MockObject && !$this instanceof \Prophecy\Prophecy\ProphecySubjectInterface) {
63+
if ($methodRefl->getNumberOfParameters() < 3 || !($paramRefl = $methodRefl->getParameters()[2])->allowsNull() || !\in_array($typeName = $paramRefl->getType()->getName(), [\Exception::class, \Throwable::class])) {
64+
throw new \TypeError(sprintf('The "%s::collect()" method requires a "\Throwable $exception = null" as its third parameter.', \get_class($this)));
65+
}
66+
67+
if (\Throwable::class !== $typeName) {
68+
@trigger_error(sprintf('The "%s::collect()" method third parameter signature will be "\Throwable $exception = null" in Symfony 5.0.', \get_class($this)));
69+
}
70+
}
71+
6072
$queries = [];
6173
foreach ($this->loggers as $name => $logger) {
6274
$queries[$name] = $this->sanitizeQueries($name, $logger->queries);

src/Symfony/Bridge/Doctrine/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"symfony/config": "^4.2|^5.0",
2929
"symfony/dependency-injection": "^3.4|^4.0|^5.0",
3030
"symfony/form": "^4.4|^5.0",
31-
"symfony/http-kernel": "^3.4|^4.0|^5.0",
31+
"symfony/http-kernel": "^4.4|^5.0",
3232
"symfony/messenger": "^4.3|^5.0",
3333
"symfony/property-access": "^3.4|^4.0|^5.0",
3434
"symfony/property-info": "^3.4|^4.0|^5.0",

src/Symfony/Bridge/Twig/DataCollector/TwigDataCollector.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,20 @@ public function __construct(Profile $profile, Environment $twig = null)
4040

4141
/**
4242
* {@inheritdoc}
43+
*
44+
* @param \Throwable|null $exception
4345
*/
44-
public function collect(Request $request, Response $response, \Exception $exception = null)
46+
public function collect(Request $request, Response $response/*, \Throwable $exception = null*/)
4547
{
48+
if (__CLASS__ !== \get_class($this) && __CLASS__ !== ($methodRefl = new \ReflectionMethod($this, __FUNCTION__))->getDeclaringClass()->getName() && !$this instanceof \PHPUnit\Framework\MockObject\MockObject && !$this instanceof \Prophecy\Prophecy\ProphecySubjectInterface) {
49+
if ($methodRefl->getNumberOfParameters() < 3 || !($paramRefl = $methodRefl->getParameters()[2])->allowsNull() || !\in_array($typeName = $paramRefl->getType()->getName(), [\Exception::class, \Throwable::class])) {
50+
throw new \TypeError(sprintf('The "%s::collect()" method requires a "\Throwable $exception = null" as its third parameter.', \get_class($this)));
51+
}
52+
53+
if (\Throwable::class !== $typeName) {
54+
@trigger_error(sprintf('The "%s::collect()" method third parameter signature will be "\Throwable $exception = null" in Symfony 5.0.', \get_class($this)));
55+
}
56+
}
4657
}
4758

4859
/**

src/Symfony/Bridge/Twig/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"symfony/finder": "^3.4|^4.0|^5.0",
2828
"symfony/form": "^4.4|^5.0",
2929
"symfony/http-foundation": "^4.3|^5.0",
30-
"symfony/http-kernel": "^3.4|^4.0|^5.0",
30+
"symfony/http-kernel": "^4.4|^5.0",
3131
"symfony/mime": "^4.3|^5.0",
3232
"symfony/polyfill-intl-icu": "~1.0",
3333
"symfony/routing": "^3.4|^4.0|^5.0",

src/Symfony/Bundle/SecurityBundle/DataCollector/SecurityDataCollector.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,21 @@ public function __construct(TokenStorageInterface $tokenStorage = null, RoleHier
5757

5858
/**
5959
* {@inheritdoc}
60+
*
61+
* @param \Throwable|null $exception
6062
*/
61-
public function collect(Request $request, Response $response, \Exception $exception = null)
63+
public function collect(Request $request, Response $response/*, \Throwable $exception = null*/)
6264
{
65+
if (__CLASS__ !== \get_class($this) && __CLASS__ !== ($methodRefl = new \ReflectionMethod($this, __FUNCTION__))->getDeclaringClass()->getName() && !$this instanceof \PHPUnit\Framework\MockObject\MockObject && !$this instanceof \Prophecy\Prophecy\ProphecySubjectInterface) {
66+
if ($methodRefl->getNumberOfParameters() < 3 || !($paramRefl = $methodRefl->getParameters()[2])->allowsNull() || !\in_array($typeName = $paramRefl->getType()->getName(), [\Exception::class, \Throwable::class])) {
67+
throw new \TypeError(sprintf('The "%s::collect()" method requires a "\Throwable $exception = null" as its third parameter.', \get_class($this)));
68+
}
69+
70+
if (\Throwable::class !== $typeName) {
71+
@trigger_error(sprintf('The "%s::collect()" method third parameter signature will be "\Throwable $exception = null" in Symfony 5.0.', \get_class($this)));
72+
}
73+
}
74+
6375
if (null === $this->tokenStorage) {
6476
$this->data = [
6577
'enabled' => false,

src/Symfony/Component/Cache/DataCollector/CacheDataCollector.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,21 @@ public function addInstance($name, TraceableAdapter $instance)
3939

4040
/**
4141
* {@inheritdoc}
42+
*
43+
* @param \Throwable|null $exception
4244
*/
43-
public function collect(Request $request, Response $response, \Exception $exception = null)
45+
public function collect(Request $request, Response $response/*, \Throwable $exception = null*/)
4446
{
47+
if (__CLASS__ !== \get_class($this) && __CLASS__ !== ($methodRefl = new \ReflectionMethod($this, __FUNCTION__))->getDeclaringClass()->getName() && !$this instanceof \PHPUnit\Framework\MockObject\MockObject && !$this instanceof \Prophecy\Prophecy\ProphecySubjectInterface) {
48+
if ($methodRefl->getNumberOfParameters() < 3 || !($paramRefl = $methodRefl->getParameters()[2])->allowsNull() || !\in_array($typeName = $paramRefl->getType()->getName(), [\Exception::class, \Throwable::class])) {
49+
throw new \TypeError(sprintf('The "%s::collect()" method requires a "\Throwable $exception = null" as its third parameter.', \get_class($this)));
50+
}
51+
52+
if (\Throwable::class !== $typeName) {
53+
@trigger_error(sprintf('The "%s::collect()" method third parameter signature will be "\Throwable $exception = null" in Symfony 5.0.', \get_class($this)));
54+
}
55+
}
56+
4557
$empty = ['calls' => [], 'config' => [], 'options' => [], 'statistics' => []];
4658
$this->data = ['instances' => $empty, 'total' => $empty];
4759
foreach ($this->instances as $name => $instance) {

src/Symfony/Component/Console/Application.php

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,9 @@ public function run(InputInterface $input = null, OutputInterface $output = null
132132
$e = class_exists(FatalThrowableError::class) ? new FatalThrowableError($e) : (class_exists(LegacyFatalThrowableError::class) ? new LegacyFatalThrowableError($e) : new \ErrorException($e->getMessage(), $e->getCode(), E_ERROR, $e->getFile(), $e->getLine()));
133133
}
134134
if ($output instanceof ConsoleOutputInterface) {
135-
$this->renderException($e, $output->getErrorOutput());
135+
$this->renderThrowable($e, $output->getErrorOutput());
136136
} else {
137-
$this->renderException($e, $output);
137+
$this->renderThrowable($e, $output);
138138
}
139139
};
140140
if ($phpHandler = set_exception_handler($renderException)) {
@@ -768,20 +768,39 @@ public static function getAbbreviations($names)
768768

769769
/**
770770
* Renders a caught exception.
771+
*
772+
* @deprecated since Symfony 4.4, use "renderThrowable()" instead
771773
*/
772774
public function renderException(\Exception $e, OutputInterface $output)
775+
{
776+
@trigger_error(sprintf('The "%s::renderException()" method is deprecated since Symfony 4.4, use "renderThrowable()" instead.', \get_class($this)));
777+
778+
$this->renderThrowable($e, $output);
779+
}
780+
781+
public function renderThrowable(\Throwable $e, OutputInterface $output): void
773782
{
774783
$output->writeln('', OutputInterface::VERBOSITY_QUIET);
775784

776-
$this->doRenderException($e, $output);
785+
$this->doRenderThrowable($e, $output);
777786

778787
if (null !== $this->runningCommand) {
779788
$output->writeln(sprintf('<info>%s</info>', sprintf($this->runningCommand->getSynopsis(), $this->getName())), OutputInterface::VERBOSITY_QUIET);
780789
$output->writeln('', OutputInterface::VERBOSITY_QUIET);
781790
}
782791
}
783792

793+
/**
794+
* @deprecated since Symfony 4.4, use "doRenderThrowable()" instead
795+
*/
784796
protected function doRenderException(\Exception $e, OutputInterface $output)
797+
{
798+
@trigger_error(sprintf('The "%s::doRenderException()" method is deprecated since Symfony 4.4, use "doRenderThrowable()" instead.', \get_class($this)));
799+
800+
$this->doRenderThrowable($e, $output);
801+
}
802+
803+
protected function doRenderThrowable(\Throwable $e, OutputInterface $output): void
785804
{
786805
do {
787806
$message = trim($e->getMessage());

src/Symfony/Component/Form/Extension/DataCollector/FormDataCollector.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,20 @@ public function __construct(FormDataExtractorInterface $dataExtractor)
8080

8181
/**
8282
* Does nothing. The data is collected during the form event listeners.
83+
*
84+
* @param \Throwable|null $exception
8385
*/
84-
public function collect(Request $request, Response $response, \Exception $exception = null)
86+
public function collect(Request $request, Response $response/*, \Throwable $exception = null*/)
8587
{
88+
if (__CLASS__ !== \get_class($this) && __CLASS__ !== ($methodRefl = new \ReflectionMethod($this, __FUNCTION__))->getDeclaringClass()->getName() && !$this instanceof \PHPUnit\Framework\MockObject\MockObject && !$this instanceof \Prophecy\Prophecy\ProphecySubjectInterface) {
89+
if ($methodRefl->getNumberOfParameters() < 3 || !($paramRefl = $methodRefl->getParameters()[2])->allowsNull() || !\in_array($typeName = $paramRefl->getType()->getName(), [\Exception::class, \Throwable::class])) {
90+
throw new \TypeError(sprintf('The "%s::collect()" method requires a "\Throwable $exception = null" as its third parameter.', \get_class($this)));
91+
}
92+
93+
if (\Throwable::class !== $typeName) {
94+
@trigger_error(sprintf('The "%s::collect()" method third parameter signature will be "\Throwable $exception = null" in Symfony 5.0.', \get_class($this)));
95+
}
96+
}
8697
}
8798

8899
public function reset()

src/Symfony/Component/Form/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"symfony/config": "^3.4|^4.0|^5.0",
3333
"symfony/console": "^4.3|^5.0",
3434
"symfony/http-foundation": "^3.4|^4.0|^5.0",
35-
"symfony/http-kernel": "^4.3|^5.0",
35+
"symfony/http-kernel": "^4.4|^5.0",
3636
"symfony/security-csrf": "^3.4|^4.0|^5.0",
3737
"symfony/translation": "^4.2|^5.0",
3838
"symfony/var-dumper": "^4.3|^5.0"

src/Symfony/Component/HttpKernel/DataCollector/AjaxDataCollector.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,22 @@
2121
*/
2222
class AjaxDataCollector extends DataCollector
2323
{
24-
public function collect(Request $request, Response $response, \Exception $exception = null)
24+
/**
25+
* {@inheritdoc}
26+
*
27+
* @param \Throwable|null $exception
28+
*/
29+
public function collect(Request $request, Response $response/*, \Throwable $exception = null*/)
2530
{
31+
if (__CLASS__ !== \get_class($this) && __CLASS__ !== ($methodRefl = new \ReflectionMethod($this, __FUNCTION__))->getDeclaringClass()->getName() && !$this instanceof \PHPUnit\Framework\MockObject\MockObject && !$this instanceof \Prophecy\Prophecy\ProphecySubjectInterface) {
32+
if ($methodRefl->getNumberOfParameters() < 3 || !($paramRefl = $methodRefl->getParameters()[2])->allowsNull() || !\in_array($typeName = $paramRefl->getType()->getName(), [\Exception::class, \Throwable::class])) {
33+
throw new \TypeError(sprintf('The "%s::collect()" method requires a "\Throwable $exception = null" as its third parameter.', \get_class($this)));
34+
}
35+
36+
if (\Throwable::class !== $typeName) {
37+
@trigger_error(sprintf('The "%s::collect()" method third parameter signature will be "\Throwable $exception = null" in Symfony 5.0.', \get_class($this)));
38+
}
39+
}
2640
// all collecting is done client side
2741
}
2842

src/Symfony/Component/HttpKernel/DataCollector/ConfigDataCollector.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,21 @@ public function setKernel(KernelInterface $kernel = null)
5454

5555
/**
5656
* {@inheritdoc}
57+
*
58+
* @param \Throwable|null $exception
5759
*/
58-
public function collect(Request $request, Response $response, \Exception $exception = null)
60+
public function collect(Request $request, Response $response/*, \Throwable $exception = null*/)
5961
{
62+
if (__CLASS__ !== \get_class($this) && __CLASS__ !== ($methodRefl = new \ReflectionMethod($this, __FUNCTION__))->getDeclaringClass()->getName() && !$this instanceof \PHPUnit\Framework\MockObject\MockObject && !$this instanceof \Prophecy\Prophecy\ProphecySubjectInterface) {
63+
if ($methodRefl->getNumberOfParameters() < 3 || !($paramRefl = $methodRefl->getParameters()[2])->allowsNull() || !\in_array($typeName = $paramRefl->getType()->getName(), [\Exception::class, \Throwable::class])) {
64+
throw new \TypeError(sprintf('The "%s::collect()" method requires a "\Throwable $exception = null" as its third parameter.', \get_class($this)));
65+
}
66+
67+
if (\Throwable::class !== $typeName) {
68+
@trigger_error(sprintf('The "%s::collect()" method third parameter signature will be "\Throwable $exception = null" in Symfony 5.0.', \get_class($this)));
69+
}
70+
}
71+
6072
$this->data = [
6173
'app_name' => $this->name,
6274
'app_version' => $this->version,

src/Symfony/Component/HttpKernel/DataCollector/DataCollectorInterface.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ interface DataCollectorInterface extends ResetInterface
2424
{
2525
/**
2626
* Collects data for the given Request and Response.
27+
*
28+
* @param \Throwable|null $exception
2729
*/
28-
public function collect(Request $request, Response $response, \Exception $exception = null);
30+
public function collect(Request $request, Response $response/*, \Throwable $exception = null*/);
2931

3032
/**
3133
* Returns the name of the collector.

src/Symfony/Component/HttpKernel/DataCollector/DumpDataCollector.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,23 @@ public function dump(Data $data)
9898
}
9999
}
100100

101-
public function collect(Request $request, Response $response, \Exception $exception = null)
101+
/**
102+
* {@inheritdoc}
103+
*
104+
* @param \Throwable|null $exception
105+
*/
106+
public function collect(Request $request, Response $response/*, \Throwable $exception = null*/)
102107
{
108+
if (__CLASS__ !== \get_class($this) && __CLASS__ !== ($methodRefl = new \ReflectionMethod($this, __FUNCTION__))->getDeclaringClass()->getName() && !$this instanceof \PHPUnit\Framework\MockObject\MockObject && !$this instanceof \Prophecy\Prophecy\ProphecySubjectInterface) {
109+
if ($methodRefl->getNumberOfParameters() < 3 || !($paramRefl = $methodRefl->getParameters()[2])->allowsNull() || !\in_array($typeName = $paramRefl->getType()->getName(), [\Exception::class, \Throwable::class])) {
110+
throw new \TypeError(sprintf('The "%s::collect()" method requires a "\Throwable $exception = null" as its third parameter.', \get_class($this)));
111+
}
112+
113+
if (\Throwable::class !== $typeName) {
114+
@trigger_error(sprintf('The "%s::collect()" method third parameter signature will be "\Throwable $exception = null" in Symfony 5.0.', \get_class($this)));
115+
}
116+
}
117+
103118
if (!$this->dataCount) {
104119
$this->data = [];
105120
}

src/Symfony/Component/HttpKernel/DataCollector/EventDataCollector.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,21 @@ public function __construct(EventDispatcherInterface $dispatcher = null, Request
3838

3939
/**
4040
* {@inheritdoc}
41+
*
42+
* @param \Throwable|null $exception
4143
*/
42-
public function collect(Request $request, Response $response, \Exception $exception = null)
44+
public function collect(Request $request, Response $response/*, \Throwable $exception = null*/)
4345
{
46+
if (__CLASS__ !== \get_class($this) && __CLASS__ !== ($methodRefl = new \ReflectionMethod($this, __FUNCTION__))->getDeclaringClass()->getName() && !$this instanceof \PHPUnit\Framework\MockObject\MockObject && !$this instanceof \Prophecy\Prophecy\ProphecySubjectInterface) {
47+
if ($methodRefl->getNumberOfParameters() < 3 || !($paramRefl = $methodRefl->getParameters()[2])->allowsNull() || !\in_array($typeName = $paramRefl->getType()->getName(), [\Exception::class, \Throwable::class])) {
48+
throw new \TypeError(sprintf('The "%s::collect()" method requires a "\Throwable $exception = null" as its third parameter.', \get_class($this)));
49+
}
50+
51+
if (\Throwable::class !== $typeName) {
52+
@trigger_error(sprintf('The "%s::collect()" method third parameter signature will be "\Throwable $exception = null" in Symfony 5.0.', \get_class($this)));
53+
}
54+
}
55+
4456
$this->currentRequest = $this->requestStack && $this->requestStack->getMasterRequest() !== $request ? $request : null;
4557
$this->data = [
4658
'called_listeners' => [],

src/Symfony/Component/HttpKernel/DataCollector/ExceptionDataCollector.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,22 @@ class ExceptionDataCollector extends DataCollector
2424
{
2525
/**
2626
* {@inheritdoc}
27+
*
28+
* @param \Throwable|null $exception
2729
*/
28-
public function collect(Request $request, Response $response, \Exception $exception = null)
30+
public function collect(Request $request, Response $response/*, \Throwable $exception = null*/)
2931
{
30-
if (null !== $exception) {
32+
if (__CLASS__ !== \get_class($this) && __CLASS__ !== ($methodRefl = new \ReflectionMethod($this, __FUNCTION__))->getDeclaringClass()->getName() && !$this instanceof \PHPUnit\Framework\MockObject\MockObject && !$this instanceof \Prophecy\Prophecy\ProphecySubjectInterface) {
33+
if ($methodRefl->getNumberOfParameters() < 3 || !($paramRefl = $methodRefl->getParameters()[2])->allowsNull() || !\in_array($typeName = $paramRefl->getType()->getName(), [\Exception::class, \Throwable::class])) {
34+
throw new \TypeError(sprintf('The "%s::collect()" method requires a "\Throwable $exception = null" as its third parameter.', \get_class($this)));
35+
}
36+
37+
if (\Throwable::class !== $typeName) {
38+
@trigger_error(sprintf('The "%s::collect()" method third parameter signature will be "\Throwable $exception = null" in Symfony 5.0.', \get_class($this)));
39+
}
40+
}
41+
42+
if (\func_num_args() > 2 && null !== $exception = func_get_arg(2)) {
3143
$this->data = [
3244
'exception' => FlattenException::createFromThrowable($exception),
3345
];

src/Symfony/Component/HttpKernel/DataCollector/LoggerDataCollector.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,21 @@ public function __construct($logger = null, string $containerPathPrefix = null,
4141

4242
/**
4343
* {@inheritdoc}
44+
*
45+
* @param \Throwable|null $exception
4446
*/
45-
public function collect(Request $request, Response $response, \Exception $exception = null)
47+
public function collect(Request $request, Response $response/*, \Throwable $exception = null*/)
4648
{
49+
if (__CLASS__ !== \get_class($this) && __CLASS__ !== ($methodRefl = new \ReflectionMethod($this, __FUNCTION__))->getDeclaringClass()->getName() && !$this instanceof \PHPUnit\Framework\MockObject\MockObject && !$this instanceof \Prophecy\Prophecy\ProphecySubjectInterface) {
50+
if ($methodRefl->getNumberOfParameters() < 3 || !($paramRefl = $methodRefl->getParameters()[2])->allowsNull() || !\in_array($typeName = $paramRefl->getType()->getName(), [\Exception::class, \Throwable::class])) {
51+
throw new \TypeError(sprintf('The "%s::collect()" method requires a "\Throwable $exception = null" as its third parameter.', \get_class($this)));
52+
}
53+
54+
if (\Throwable::class !== $typeName) {
55+
@trigger_error(sprintf('The "%s::collect()" method third parameter signature will be "\Throwable $exception = null" in Symfony 5.0.', \get_class($this)));
56+
}
57+
}
58+
4759
$this->currentRequest = $this->requestStack && $this->requestStack->getMasterRequest() !== $request ? $request : null;
4860
}
4961

0 commit comments

Comments
 (0)
0