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

Skip to content

Commit 5146ad0

Browse files
committed
Deprecate things that prevent \Throwable from bubbling down
1 parent 0472dbf commit 5146ad0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+281
-51
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
* DoctrineDataCollector.
2424
*
2525
* @author Fabien Potencier <fabien@symfony.com>
26+
*
27+
* @final since Symfony 4.4
2628
*/
2729
class DoctrineDataCollector extends DataCollector
2830
{

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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
* TwigDataCollector.
2626
*
2727
* @author Fabien Potencier <fabien@symfony.com>
28+
*
29+
* @final since Symfony 4.4
2830
*/
2931
class TwigDataCollector extends DataCollector implements LateDataCollectorInterface
3032
{

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",
< 10000 div aria-hidden="true" class="position-absolute top-0 d-flex user-select-none DiffLineTableCellParts-module__comment-indicator--eI0hb">
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/FrameworkBundle/DataCollector/RouterDataCollector.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
* RouterDataCollector.
2020
*
2121
* @author Fabien Potencier <fabien@symfony.com>
22+
*
23+
* @final since Symfony 4.4
2224
*/
2325
class RouterDataCollector extends BaseRouterDataCollector
2426
{

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

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

3535
/**
3636
* @author Fabien Potencier <fabien@symfony.com>
37+
*
38+
* @final since Symfony 4.4
3739
*/
3840
class SecurityDataCollector extends DataCollector implements LateDataCollectorInterface
3941
{

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
/**
2222
* @author Aaron Scherer <aequasi@gmail.com>
2323
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
24+
*
25+
* @final since Symfony 4.4
2426
*/
2527
class CacheDataCollector extends DataCollector implements LateDataCollectorInterface
2628
{
@@ -39,6 +41,8 @@ public function addInstance($name, TraceableAdapter $instance)
3941

4042
/**
4143
* {@inheritdoc}
44+
*
45+
* @param \Throwable|null $exception
4246
*/
4347
public function collect(Request $request, Response $response, \Exception $exception = null)
4448
{

src/Symfony/Component/Console/Application.php

Lines changed: 122 additions & 2 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(ErrorException::class) ? new ErrorException($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)) {
@@ -792,9 +792,13 @@ public static function getAbbreviations($names)
792792

793793
/**
794794
* Renders a caught exception.
795+
*
796+
* @deprecated since Symfony 4.4, use "renderThrowable()" instead
795797
*/
796798
public function renderException(\Exception $e, OutputInterface $output)
797799
{
800+
@trigger_error(sprintf('The "%s::renderException()" method is deprecated since Symfony 4.4, use "renderThrowable()" instead.', __CLASS__));
801+
798802
$output->writeln('', OutputInterface::VERBOSITY_QUIET);
799803

800804
$this->doRenderException($e, $output);
@@ -805,8 +809,124 @@ public function renderException(\Exception $e, OutputInterface $output)
805809
}
806810
}
807811

812+
public function renderThrowable(\Throwable $e, OutputInterface $output): void
813+
{
814+
if (__CLASS__ !== \get_class($this) && __CLASS__ !== (new \ReflectionMethod($this, 'renderException'))->getDeclaringClass()->getName()) {
815+
@trigger_error(sprintf('The "%s::renderException()" method is deprecated since Symfony 4.4, use "renderThrowable()" instead.', __CLASS__));
816+
817+
if (!$e instanceof \Exception) {
818+
$e = new ErrorException($e);
819+
}
820+
821+
$this->renderException($e, $output);
822+
823+
return;
824+
}
825+
826+
$output->writeln('', OutputInterface::VERBOSITY_QUIET);
827+
828+
$this->doRenderThrowable($e, $output);
829+
830+
if (null !== $this->runningCommand) {
831+
$output->writeln(sprintf('<info>%s</info>', sprintf($this->runningCommand->getSynopsis(), $this->getName())), OutputInterface::VERBOSITY_QUIET);
832+
$output->writeln('', OutputInterface::VERBOSITY_QUIET);
833+
}
834+
}
835+
836+
/**
837+
* @deprecated since Symfony 4.4, use "doRenderThrowable()" instead
838+
*/
808839
protected function doRenderException(\Exception $e, OutputInterface $output)
809840
{
841+
@trigger_error(sprintf('The "%s::doRenderException()" method is deprecated since Symfony 4.4, use "doRenderThrowable()" instead.', __CLASS__));
842+
843+
do {
844+
$message = trim($e->getMessage());
845+
if ('' === $message || OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) {
846+
$class = \get_class($e);
847+
$class = 'c' === $class[0] && 0 === strpos($class, "class@anonymous\0") ? get_parent_class($class).'@anonymous' : $class;
848+
$title = sprintf(' [%s%s] ', $class, 0 !== ($code = $e->getCode()) ? ' ('.$code.')' : '');
849+
$len = Helper::strlen($title);
850+
} else {
851+
$len = 0;
852+
}
853+
854+
if (false !== strpos($message, "class@anonymous\0")) {
855+
$message = preg_replace_callback('/class@anonymous\x00.*?\.php0x?[0-9a-fA-F]++/', function ($m) {
856+
return class_exists($m[0], false) ? get_parent_class($m[0]).'@anonymous' : $m[0];
857+
}, $message);
858+
}
859+
860+
$width = $this->terminal->getWidth() ? $this->terminal->getWidth() - 1 : PHP_INT_MAX;
861+
$lines = [];
862+
foreach ('' !== $message ? preg_split('/\r?\n/', $message) : [] as $line) {
863+
foreach ($this->splitStringByWidth($line, $width - 4) as $line) {
864+
// pre-format lines to get the right string length
865+
$lineLength = Helper::strlen($line) + 4;
866+
$lines[] = [$line, $lineLength];
867+
868+
$len = max($lineLength, $len);
869+
}
870+
}
871+
872+
$messages = [];
873+
if (!$e instanceof ExceptionInterface || OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) {
874+
$messages[] = sprintf('<comment>%s</comment>', OutputFormatter::escape(sprintf('In %s line %s:', basename($e->getFile()) ?: 'n/a', $e->getLine() ?: 'n/a')));
875+
}
876+
$messages[] = $emptyLine = sprintf('<error>%s</error>', str_repeat(' ', $len));
877+
if ('' === $message || OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) {
878+
$messages[] = sprintf('<error>%s%s</error>', $title, str_repeat(' ', max(0, $len - Helper::strlen($title))));
879+
}
880+
foreach ($lines as $line) {
881+
$messages[] = sprintf('<error> %s %s</error>', OutputFormatter::escape($line[0]), str_repeat(' ', $len - $line[1]));
882+
}
883+
$messages[] = $emptyLine;
884+
$messages[] = '';
885+
886+
$output->writeln($messages, OutputInterface::VERBOSITY_QUIET);
887+
888+
if (OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) {
889+
$output->writeln('<comment>Exception trace:</comment>', OutputInterface::VERBOSITY_QUIET);
890+
891+
// exception related properties
892+
$trace = $e->getTrace();
893+
894+
array_unshift($trace, [
895+
'function' => '',
896+
'file' => $e->getFile() ?: 'n/a',
897+
'line' => $e->getLine() ?: 'n/a',
898+
'args' => [],
899+
]);
900+
901+
for ($i = 0, $count = \count($trace); $i < $count; ++$i) {
902+
$class = isset($trace[$i]['class']) ? $trace[$i]['class'] : '';
903+
$type = isset($trace[$i]['type']) ? $trace[$i]['type'] : '';
904+
$function = isset($trace[$i]['function']) ? $trace[$i]['function'] : '';
905+
$file = isset($trace[$i]['file']) ? $trace[$i]['file'] : 'n/a';
906+
$line = isset($trace[$i]['line']) ? $trace[$i]['line'] : 'n/a';
907+
908+
$output->writeln(sprintf(' %s%s at <info>%s:%s</info>', $class, $function ? $type.$function.'()' : '', $file, $line), OutputInterface::VERBOSITY_QUIET);
909+
}
910+
911+
$output->writeln('', OutputInterface::VERBOSITY_QUIET);
912+
}
913+
} while ($e = $e->getPrevious());
914+
}
915+
916+
protected function doRenderThrowable(\Throwable $e, OutputInterface $output): void
917+
{
918+
if (__CLASS__ !== \get_class($this) && __CLASS__ !== (new \ReflectionMethod($this, 'doRenderException'))->getDeclaringClass()->getName()) {
919+
@trigger_error(sprintf('The "%s::doRenderException()" method is deprecated since Symfony 4.4, use "doRenderThrowable()" instead.', __CLASS__));
920+
921+
if (!$e instanceof \Exception) {
922+
$e = new ErrorException($e);
923+
}
924+
925+
$this->doRenderException($e, $output);
926+
927+
return;
928+
}
929+
810930
do {
811931
$message = trim($e->getMessage());
812932
if ('' === $message || OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) {

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/HttpClient/DataCollector/HttpClientDataCollector.php

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

1919
/**
2020
* @author Jérémy Romey <jeremy@free-agent.fr>
21+
*
22+
* @final since Symfony 4.4
2123
*/
2224
final class HttpClientDataCollector extends DataCollector
2325
{

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,14 @@
1818
* AjaxDataCollector.
1919
*
2020
* @author Bart van den Burg <bart@burgov.nl>
21+
*
22+
* @final since Symfony 4.4
2123
*/
2224
class AjaxDataCollector extends DataCollector
2325
{
26+
/**
27+
* {@inheritdoc}
28+
*/
2429
public function collect(Request $request, Response $response, \Exception $exception = null)
2530
{
2631
// all collecting is done client side

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

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

2020
/**
2121
* @author Fabien Potencier <fabien@symfony.com>
22+
*
23+
* @final since Symfony 4.4
2224
*/
2325
class ConfigDataCollector extends DataCollector implements LateDataCollectorInterface
2426
{

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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ public function dump(Data $data)
9898
}
9999
}
100100

101+
/**
102+
* {@inheritdoc}
103+
*/
101104
public function collect(Request $request, Response $response, \Exception $exception = null)
102105
{
103106
if (!$this->dataCount) {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
* EventDataCollector.
2424
*
2525
* @author Fabien Potencier <fabien@symfony.com>
26+
*
27+
* @final since Symfony 4.4
2628
*/
2729
class EventDataCollector extends DataCollector implements LateDataCollectorInterface
2830
{

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
* ExceptionDataCollector.
2020
*
2121
* @author Fabien Potencier <fabien@symfony.com>
22+
*
23+
* @final since Symfony 4.4
2224
*/
2325
class ExceptionDataCollector extends DataCollector
2426
{
@@ -27,7 +29,7 @@ class ExceptionDataCollector extends DataCollector
2729
*/
2830
public function collect(Request $request, Response $response, \Exception $exception = null)
2931
{
30-
if (null !== $exception) {
32+
if (\func_num_args() > 2 && null !== $exception = func_get_arg(2)) {
3133
$this->data = [
3234
'exception' => FlattenException::createFromThrowable($exception),
3335
];

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
* LogDataCollector.
2222
*
2323
* @author Fabien Potencier <fabien@symfony.com>
24+
*
25+
* @final since Symfony 4.4
2426
*/
2527
class LoggerDataCollector extends DataCollector implements LateDataCollectorInterface
2628
{

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
* MemoryDataCollector.
1919
*
2020
* @author Fabien Potencier <fabien@symfony.com>
21+
*
22+
* @final since Symfony 4.4
2123
*/
2224
class MemoryDataCollector extends DataCollector implements LateDataCollectorInterface
2325
{

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

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

2323
/**
2424
* @author Fabien Potencier <fabien@symfony.com>
25+
*
26+
* @final since Symfony 4.4
2527
*/
2628
class RequestDataCollector extends DataCollector implements EventSubscriberInterface, LateDataCollectorInterface
2729
{

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

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

1919
/**
2020
* @author Fabien Potencier <fabien@symfony.com>
21+
*
22+
* @internal since Symfony 4.4
2123
*/
2224
class RouterDataCollector extends DataCollector
2325
{

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

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

2020
/**
2121
* @author Fabien Potencier <fabien@symfony.com>
22+
*
23+
* @final since Symfony 4.4
2224
*/
2325
class TimeDataCollector extends DataCollector implements LateDataCollectorInterface
2426
{

0 commit comments

Comments
 (0)
0