Skip to content

Commit ee0b458

Browse files
committed
Deprecate things that prevent \Throwable from bubbling down
1 parent 8c25592 commit ee0b458

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', 'Throwable'])) {
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' !== $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', 'Throwable'])) {
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' !== $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', 'Throwable'])) {
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' !== $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', 'Throwable'])) {
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' !== $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', 'Throwable'])) {
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' !== $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', 'Throwable'])) {
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' !== $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

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy