Remove \Throwable support deprecation layer

This commit is contained in:
Thomas Calvet 2019-11-05 21:53:45 +01:00 committed by Nicolas Grekas
parent 8e6cc015ff
commit ffcfdb42a7
34 changed files with 67 additions and 113 deletions

View File

@ -39,6 +39,8 @@ Console
* Removed the `setVerticalBorderChar()` method in favor of the `setVerticalBorderChars()` method in `TableStyle`.
* Removed the `getVerticalBorderChar()` method in favor of the `getBorderChars()` method in `TableStyle`.
* Removed support for returning `null` from `Command::execute()`, return `0` instead
* Renamed `Application::renderException()` and `Application::doRenderException()`
to `renderThrowable()` and `doRenderThrowable()` respectively.
* The `ProcessHelper::run()` method takes the command as an array of arguments.
Before:

View File

@ -52,10 +52,8 @@ class DoctrineDataCollector extends DataCollector
/**
* {@inheritdoc}
*
* @param \Throwable|null $exception
*/
public function collect(Request $request, Response $response/*, \Throwable $exception = null*/)
public function collect(Request $request, Response $response, \Throwable $exception = null)
{
$queries = [];
foreach ($this->loggers as $name => $logger) {

View File

@ -26,7 +26,7 @@ use Twig\Profiler\Profile;
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @final since Symfony 4.4
* @final
*/
class TwigDataCollector extends DataCollector implements LateDataCollectorInterface
{
@ -43,7 +43,7 @@ class TwigDataCollector extends DataCollector implements LateDataCollectorInterf
/**
* {@inheritdoc}
*/
public function collect(Request $request, Response $response, \Exception $exception = null)
public function collect(Request $request, Response $response, \Throwable $exception = null)
{
}

View File

@ -51,6 +51,7 @@
"symfony/console": "<4.4",
"symfony/form": "<5.0",
"symfony/http-foundation": "<4.4",
"symfony/http-kernel": "<4.4",
"symfony/translation": "<5.0",
"symfony/workflow": "<4.4"
},

View File

@ -20,7 +20,7 @@ use Symfony\Component\HttpKernel\DataCollector\RouterDataCollector as BaseRouter
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @final since Symfony 4.4
* @final
*/
class RouterDataCollector extends BaseRouterDataCollector
{

View File

@ -33,7 +33,7 @@ use Symfony\Component\VarDumper\Cloner\Data;
/**
* @author Fabien Potencier <fabien@symfony.com>
*
* @final since Symfony 4.4
* @final
*/
class SecurityDataCollector extends DataCollector implements LateDataCollectorInterface
{
@ -59,7 +59,7 @@ class SecurityDataCollector extends DataCollector implements LateDataCollectorIn
/**
* {@inheritdoc}
*/
public function collect(Request $request, Response $response, \Exception $exception = null)
public function collect(Request $request, Response $response, \Throwable $exception = null)
{
if (null === $this->tokenStorage) {
$this->data = [

View File

@ -22,7 +22,7 @@ use Symfony\Component\HttpKernel\DataCollector\LateDataCollectorInterface;
* @author Aaron Scherer <aequasi@gmail.com>
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
*
* @final since Symfony 4.4
* @final
*/
class CacheDataCollector extends DataCollector implements LateDataCollectorInterface
{
@ -39,7 +39,7 @@ class CacheDataCollector extends DataCollector implements LateDataCollectorInter
/**
* {@inheritdoc}
*/
public function collect(Request $request, Response $response, \Exception $exception = null)
public function collect(Request $request, Response $response, \Throwable $exception = null)
{
$empty = ['calls' => [], 'config' => [], 'options' => [], 'statistics' => []];
$this->data = ['instances' => $empty, 'total' => $empty];

View File

@ -41,6 +41,7 @@
"conflict": {
"doctrine/dbal": "<2.5",
"symfony/dependency-injection": "<4.4",
"symfony/http-kernel": "<4.4",
"symfony/var-dumper": "<4.4"
},
"autoload": {

View File

@ -42,7 +42,6 @@ use Symfony\Component\Console\Output\ConsoleOutputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\ErrorHandler\ErrorHandler;
use Symfony\Component\ErrorHandler\Exception\ErrorException;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
use Symfony\Contracts\Service\ResetInterface;
@ -758,79 +757,19 @@ class Application implements ResetInterface
return $abbrevs;
}
/**
* Renders a caught exception.
*
* @deprecated since Symfony 4.4, use "renderThrowable()" instead
*/
public function renderException(\Exception $e, OutputInterface $output)
{
@trigger_error(sprintf('The "%s::renderException()" method is deprecated since Symfony 4.4, use "renderThrowable()" instead.', __CLASS__), E_USER_DEPRECATED);
$output->writeln('', OutputInterface::VERBOSITY_QUIET);
$this->doRenderException($e, $output);
$this->finishRenderThrowableOrException($output);
}
public function renderThrowable(\Throwable $e, OutputInterface $output): void
{
if (__CLASS__ !== \get_class($this) && __CLASS__ === (new \ReflectionMethod($this, 'renderThrowable'))->getDeclaringClass()->getName() && __CLASS__ !== (new \ReflectionMethod($this, 'renderException'))->getDeclaringClass()->getName()) {
@trigger_error(sprintf('The "%s::renderException()" method is deprecated since Symfony 4.4, use "renderThrowable()" instead.', __CLASS__), E_USER_DEPRECATED);
if (!$e instanceof \Exception) {
$e = class_exists(ErrorException::class) ? new ErrorException($e) : new \ErrorException($e->getMessage(), $e->getCode(), E_ERROR, $e->getFile(), $e->getLine());
}
$this->renderException($e, $output);
return;
}
$output->writeln('', OutputInterface::VERBOSITY_QUIET);
$this->doRenderThrowable($e, $output);
$this->finishRenderThrowableOrException($output);
}
private function finishRenderThrowableOrException(OutputInterface $output): void
{
if (null !== $this->runningCommand) {
$output->writeln(sprintf('<info>%s</info>', sprintf($this->runningCommand->getSynopsis(), $this->getName())), OutputInterface::VERBOSITY_QUIET);
$output->writeln('', OutputInterface::VERBOSITY_QUIET);
}
}
/**
* @deprecated since Symfony 4.4, use "doRenderThrowable()" instead
*/
protected function doRenderException(\Exception $e, OutputInterface $output)
{
@trigger_error(sprintf('The "%s::doRenderException()" method is deprecated since Symfony 4.4, use "doRenderThrowable()" instead.', __CLASS__), E_USER_DEPRECATED);
$this->doActuallyRenderThrowable($e, $output);
}
protected function doRenderThrowable(\Throwable $e, OutputInterface $output): void
{
if (__CLASS__ !== \get_class($this) && __CLASS__ === (new \ReflectionMethod($this, 'doRenderThrowable'))->getDeclaringClass()->getName() && __CLASS__ !== (new \ReflectionMethod($this, 'doRenderException'))->getDeclaringClass()->getName()) {
@trigger_error(sprintf('The "%s::doRenderException()" method is deprecated since Symfony 4.4, use "doRenderThrowable()" instead.', __CLASS__), E_USER_DEPRECATED);
if (!$e instanceof \Exception) {
$e = class_exists(ErrorException::class) ? new ErrorException($e) : new \ErrorException($e->getMessage(), $e->getCode(), E_ERROR, $e->getFile(), $e->getLine());
}
$this->doRenderException($e, $output);
return;
}
$this->doActuallyRenderThrowable($e, $output);
}
private function doActuallyRenderThrowable(\Throwable $e, OutputInterface $output): void
{
do {
$message = trim($e->getMessage());

View File

@ -12,8 +12,10 @@ CHANGELOG
* removed `TableStyle::getVerticalBorderChar()` method in favor of `TableStyle::getBorderChars()`
* removed support for returning `null` from `Command::execute()`, return `0` instead
* `ProcessHelper::run()` accepts only `array|Symfony\Component\Process\Process` for its `command` argument
* `Application::setDispatcher` accepts only `Symfony\Contracts\EventDispatcher\EventDispatcherInterface`
for its `dispatcher` argument
* `Application::setDispatcher` accepts only `Symfony\Contracts\EventDispatcher\EventDispatcherInterface`
for its `dispatcher` argument
* renamed `Application::renderException()` and `Application::doRenderException()`
to `renderThrowable()` and `doRenderThrowable()` respectively.
4.4.0
-----

View File

@ -81,7 +81,7 @@ class FormDataCollector extends DataCollector implements FormDataCollectorInterf
/**
* Does nothing. The data is collected during the form event listeners.
*/
public function collect(Request $request, Response $response, \Exception $exception = null)
public function collect(Request $request, Response $response, \Throwable $exception = null)
{
}

View File

@ -34,7 +34,7 @@ final class HttpClientDataCollector extends DataCollector
/**
* {@inheritdoc}
*/
public function collect(Request $request, Response $response, \Exception $exception = null)
public function collect(Request $request, Response $response, \Throwable $exception = null)
{
$this->initData();

View File

@ -36,6 +36,9 @@
"symfony/service-contracts": "^1.0|^2",
"symfony/var-dumper": "^4.4|^5.0"
},
"conflict": {
"symfony/http-kernel": "<4.4"
},
"autoload": {
"psr-4": { "Symfony\\Component\\HttpClient\\": "" },
"exclude-from-classmap": [

View File

@ -19,11 +19,11 @@ use Symfony\Component\HttpFoundation\Response;
*
* @author Bart van den Burg <bart@burgov.nl>
*
* @final since Symfony 4.4
* @final
*/
class AjaxDataCollector extends DataCollector
{
public function collect(Request $request, Response $response, \Exception $exception = null)
public function collect(Request $request, Response $response, \Throwable $exception = null)
{
// all collecting is done client side
}

View File

@ -20,7 +20,7 @@ use Symfony\Component\VarDumper\Caster\LinkStub;
/**
* @author Fabien Potencier <fabien@symfony.com>
*
* @final since Symfony 4.4
* @final
*/
class ConfigDataCollector extends DataCollector implements LateDataCollectorInterface
{
@ -46,7 +46,7 @@ class ConfigDataCollector extends DataCollector implements LateDataCollectorInte
/**
* {@inheritdoc}
*/
public function collect(Request $request, Response $response, \Exception $exception = null)
public function collect(Request $request, Response $response, \Throwable $exception = null)
{
$this->data = [
'token' => $response->headers->get('X-Debug-Token'),

View File

@ -24,10 +24,8 @@ interface DataCollectorInterface extends ResetInterface
{
/**
* Collects data for the given Request and Response.
*
* @param \Throwable|null $exception
*/
public function collect(Request $request, Response $response/*, \Throwable $exception = null*/);
public function collect(Request $request, Response $response, \Throwable $exception = null);
/**
* Returns the name of the collector.

View File

@ -98,7 +98,7 @@ class DumpDataCollector extends DataCollector implements DataDumperInterface
}
}
public function collect(Request $request, Response $response, \Exception $exception = null)
public function collect(Request $request, Response $response, \Throwable $exception = null)
{
if (!$this->dataCount) {
$this->data = [];

View File

@ -23,7 +23,7 @@ use Symfony\Contracts\Service\ResetInterface;
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @final since Symfony 4.4
* @final
*/
class EventDataCollector extends DataCollector implements LateDataCollectorInterface
{
@ -40,7 +40,7 @@ class EventDataCollector extends DataCollector implements LateDataCollectorInter
/**
* {@inheritdoc}
*/
public function collect(Request $request, Response $response, \Exception $exception = null)
public function collect(Request $request, Response $response, \Throwable $exception = null)
{
$this->currentRequest = $this->requestStack && $this->requestStack->getMasterRequest() !== $request ? $request : null;
$this->data = [

View File

@ -20,14 +20,14 @@ use Symfony\Component\HttpFoundation\Response;
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @final since Symfony 4.4
* @final
*/
class ExceptionDataCollector extends DataCollector
{
/**
* {@inheritdoc}
*/
public function collect(Request $request, Response $response, \Exception $exception = null)
public function collect(Request $request, Response $response, \Throwable $exception = null)
{
if (null !== $exception) {
$this->data = [

View File

@ -22,7 +22,7 @@ use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @final since Symfony 4.4
* @final
*/
class LoggerDataCollector extends DataCollector implements LateDataCollectorInterface
{
@ -44,7 +44,7 @@ class LoggerDataCollector extends DataCollector implements LateDataCollectorInte
/**
* {@inheritdoc}
*/
public function collect(Request $request, Response $response, \Exception $exception = null)
public function collect(Request $request, Response $response, \Throwable $exception = null)
{
$this->currentRequest = $this->requestStack && $this->requestStack->getMasterRequest() !== $request ? $request : null;
}

View File

@ -19,7 +19,7 @@ use Symfony\Component\HttpFoundation\Response;
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @final since Symfony 4.4
* @final
*/
class MemoryDataCollector extends DataCollector implements LateDataCollectorInterface
{
@ -31,7 +31,7 @@ class MemoryDataCollector extends DataCollector implements LateDataCollectorInte
/**
* {@inheritdoc}
*/
public function collect(Request $request, Response $response, \Exception $exception = null)
public function collect(Request $request, Response $response, \Throwable $exception = null)
{
$this->updateMemoryUsage();
}

View File

@ -23,7 +23,7 @@ use Symfony\Component\HttpKernel\KernelEvents;
/**
* @author Fabien Potencier <fabien@symfony.com>
*
* @final since Symfony 4.4
* @final
*/
class RequestDataCollector extends DataCollector implements EventSubscriberInterface, LateDataCollectorInterface
{
@ -37,7 +37,7 @@ class RequestDataCollector extends DataCollector implements EventSubscriberInter
/**
* {@inheritdoc}
*/
public function collect(Request $request, Response $response, \Exception $exception = null)
public function collect(Request $request, Response $response, \Throwable $exception = null)
{
// attributes are serialized and as they can be anything, they need to be converted to strings.
$attributes = [];

View File

@ -34,9 +34,9 @@ class RouterDataCollector extends DataCollector
/**
* {@inheritdoc}
*
* @final since Symfony 4.4
* @final
*/
public function collect(Request $request, Response $response, \Exception $exception = null)
public function collect(Request $request, Response $response, \Throwable $exception = null)
{
if ($response instanceof RedirectResponse) {
$this->data['redirect'] = true;

View File

@ -20,7 +20,7 @@ use Symfony\Component\Stopwatch\StopwatchEvent;
/**
* @author Fabien Potencier <fabien@symfony.com>
*
* @final since Symfony 4.4
* @final
*/
class TimeDataCollector extends DataCollector implements LateDataCollectorInterface
{
@ -36,7 +36,7 @@ class TimeDataCollector extends DataCollector implements LateDataCollectorInterf
/**
* {@inheritdoc}
*/
public function collect(Request $request, Response $response, \Exception $exception = null)
public function collect(Request $request, Response $response, \Throwable $exception = null)
{
if (null !== $this->kernel) {
$startTime = $this->kernel->getStartTime();

View File

@ -132,14 +132,10 @@ class Profiler implements ResetInterface
/**
* Collects data for the given Response.
*
* @param \Throwable|null $exception
*
* @return Profile|null A Profile instance or null if the profiler is disabled
*/
public function collect(Request $request, Response $response/*, \Throwable $exception = null*/)
public function collect(Request $request, Response $response, \Throwable $exception = null)
{
$exception = 2 < \func_num_args() ? func_get_arg(2) : null;
if (false === $this->enabled) {
return null;
}

View File

@ -24,7 +24,7 @@ class CloneVarDataCollector extends DataCollector
$this->varToClone = $varToClone;
}
public function collect(Request $request, Response $response, \Exception $exception = null)
public function collect(Request $request, Response $response, \Throwable $exception = null)
{
$this->data = $this->cloneVar($this->varToClone);
}

View File

@ -48,9 +48,17 @@
},
"conflict": {
"symfony/browser-kit": "<4.4",
"symfony/cache": "<5.0",
"symfony/config": "<5.0",
"symfony/form": "<5.0",
"symfony/dependency-injection": "<4.4",
"symfony/translation": "<4.4",
"symfony/doctrine-bridge": "<5.0",
"symfony/http-client": "<5.0",
"symfony/mailer": "<5.0",
"symfony/messenger": "<5.0",
"symfony/translation": "<5.0",
"symfony/twig-bridge": "<5.0",
"symfony/validator": "<5.0",
"symfony/var-dumper": "<4.4",
"twig/twig": "<2.4"
},

View File

@ -32,7 +32,7 @@ final class MessageDataCollector extends DataCollector
/**
* {@inheritdoc}
*/
public function collect(Request $request, Response $response, \Exception $exception = null)
public function collect(Request $request, Response $response, \Throwable $exception = null)
{
$this->data['events'] = $this->events;
}

View File

@ -33,6 +33,9 @@
"symfony/postmark-mailer": "^4.4|^5.0",
"symfony/sendgrid-mailer": "^4.4|^5.0"
},
"conflict": {
"symfony/http-kernel": "<4.4"
},
"autoload": {
"psr-4": { "Symfony\\Component\\Mailer\\": "" },
"exclude-from-classmap": [

View File

@ -21,7 +21,7 @@ use Symfony\Component\VarDumper\Caster\ClassStub;
/**
* @author Samuel Roze <samuel.roze@gmail.com>
*
* @final since Symfony 4.4
* @final
*/
class MessengerDataCollector extends DataCollector implements LateDataCollectorInterface
{
@ -35,7 +35,7 @@ class MessengerDataCollector extends DataCollector implements LateDataCollectorI
/**
* {@inheritdoc}
*/
public function collect(Request $request, Response $response, \Exception $exception = null)
public function collect(Request $request, Response $response, \Throwable $exception = null)
{
// Noop. Everything is collected live by the traceable buses & cloned as late as possible.
}

View File

@ -22,7 +22,7 @@ use Symfony\Component\Notifier\EventListener\NotificationLoggerListener;
*
* @experimental in 5.0
*/
class NotificationDataCollector extends DataCollector
final class NotificationDataCollector extends DataCollector
{
private $logger;
@ -34,7 +34,7 @@ class NotificationDataCollector extends DataCollector
/**
* {@inheritdoc}
*/
public function collect(Request $request, Response $response, \Exception $exception = null)
public function collect(Request $request, Response $response, \Throwable $exception = null)
{
$this->data['events'] = $this->logger->getEvents();
}

View File

@ -18,6 +18,9 @@
"require": {
"php": "^7.2.9"
},
"conflict": {
"symfony/http-kernel": "<4.4"
},
"autoload": {
"psr-4": { "Symfony\\Component\\Notifier\\": "" },
"exclude-from-classmap": [

View File

@ -20,7 +20,7 @@ use Symfony\Component\Translation\DataCollectorTranslator;
/**
* @author Abdellatif Ait boudad <a.aitboudad@gmail.com>
*
* @final since Symfony 4.4
* @final
*/
class TranslationDataCollector extends DataCollector implements LateDataCollectorInterface
{
@ -47,7 +47,7 @@ class TranslationDataCollector extends DataCollector implements LateDataCollecto
/**
* {@inheritdoc}
*/
public function collect(Request $request, Response $response, \Exception $exception = null)
public function collect(Request $request, Response $response, \Throwable $exception = null)
{
$this->data['locale'] = $this->translator->getLocale();
$this->data['fallback_locales'] = $this->translator->getFallbackLocales();

View File

@ -25,7 +25,7 @@ use Symfony\Component\VarDumper\Cloner\Stub;
/**
* @author Maxime Steinhausser <maxime.steinhausser@gmail.com>
*
* @final since Symfony 4.4
* @final
*/
class ValidatorDataCollector extends DataCollector implements LateDataCollectorInterface
{
@ -40,7 +40,7 @@ class ValidatorDataCollector extends DataCollector implements LateDataCollectorI
/**
* {@inheritdoc}
*/
public function collect(Request $request, Response $response, \Exception $exception = null)
public function collect(Request $request, Response $response, \Throwable $exception = null)
{
// Everything is collected once, on kernel terminate.
}