Fix some \Throwable support remaining issues

This commit is contained in:
Thomas Calvet 2019-11-12 17:49:54 +01:00 committed by Nicolas Grekas
parent 7cee181e08
commit 47bd32e16f
29 changed files with 109 additions and 32 deletions

View File

@ -42,8 +42,10 @@ class TwigDataCollector extends DataCollector implements LateDataCollectorInterf
/**
* {@inheritdoc}
*
* @param \Throwable|null $exception
*/
public function collect(Request $request, Response $response, \Exception $exception = null)
public function collect(Request $request, Response $response/*, \Throwable $exception = null*/)
{
}

View File

@ -60,8 +60,10 @@ class SecurityDataCollector extends DataCollector implements LateDataCollectorIn
/**
* {@inheritdoc}
*
* @param \Throwable|null $exception
*/
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

@ -41,8 +41,10 @@ class CacheDataCollector extends DataCollector implements LateDataCollectorInter
/**
* {@inheritdoc}
*
* @param \Throwable|null $exception
*/
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": "<3.4",
"symfony/http-kernel": "<4.4",
"symfony/var-dumper": "<4.4"
},
"autoload": {

View File

@ -11,6 +11,7 @@
namespace Symfony\Component\ErrorHandler\Exception;
use Symfony\Component\Debug\Exception\FatalThrowableError;
use Symfony\Component\Debug\Exception\FlattenException as LegacyFlattenException;
use Symfony\Component\HttpFoundation\Exception\RequestExceptionInterface;
use Symfony\Component\HttpFoundation\Response;
@ -70,7 +71,7 @@ class FlattenException extends LegacyFlattenException
$e->setStatusCode($statusCode);
$e->setHeaders($headers);
$e->setTraceFromThrowable($exception);
$e->setClass(\get_class($exception));
$e->setClass($exception instanceof FatalThrowableError ? $exception->getOriginalClassName() : \get_class($exception));
$e->setFile($exception->getFile());
$e->setLine($exception->getLine());

View File

@ -12,6 +12,7 @@
namespace Symfony\Component\ErrorHandler\Tests\Exception;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Debug\Exception\FatalThrowableError;
use Symfony\Component\ErrorHandler\Exception\FlattenException;
use Symfony\Component\HttpFoundation\Exception\SuspiciousOperationException;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
@ -129,6 +130,19 @@ class FlattenExceptionTest extends TestCase
$this->assertInstanceOf($flattened->getClass(), $exception, 'The class is set to the class of the original exception');
}
/**
* @group legacy
*/
public function testWrappedThrowable()
{
$exception = new FatalThrowableError(new \DivisionByZeroError('Ouch', 42));
$flattened = FlattenException::create($exception);
$this->assertSame('Ouch', $flattened->getMessage(), 'The message is copied from the original error.');
$this->assertSame(42, $flattened->getCode(), 'The code is copied from the original error.');
$this->assertSame('DivisionByZeroError', $flattened->getClass(), 'The class is set to the class of the original error');
}
public function testThrowable()
{
$error = new \DivisionByZeroError('Ouch', 42);

View File

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

View File

@ -32,7 +32,7 @@
"symfony/config": "^3.4|^4.0|^5.0",
"symfony/console": "^4.3|^5.0",
"symfony/http-foundation": "^3.4|^4.0|^5.0",
"symfony/http-kernel": "^4.3",
"symfony/http-kernel": "^4.4",
"symfony/security-csrf": "^3.4|^4.0|^5.0",
"symfony/translation": "^4.2|^5.0",
"symfony/var-dumper": "^4.3|^5.0"
@ -43,7 +43,7 @@
"symfony/dependency-injection": "<3.4",
"symfony/doctrine-bridge": "<3.4",
"symfony/framework-bundle": "<3.4",
"symfony/http-kernel": "<4.3",
"symfony/http-kernel": "<4.4",
"symfony/intl": "<4.3",
"symfony/translation": "<4.2",
"symfony/twig-bridge": "<3.4.5|<4.0.5,>=4.0"

View File

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

View File

@ -31,10 +31,12 @@
"php-http/httplug": "^1.0|^2.0",
"psr/http-client": "^1.0",
"symfony/dependency-injection": "^4.3|^5.0",
"symfony/http-kernel": "^4.3",
"symfony/http-kernel": "^4.4",
"symfony/process": "^4.2|^5.0",
"symfony/service-contracts": "^1.0|^2",
"symfony/var-dumper": "^4.3|^5.0"
"symfony/service-contracts": "^1.0|^2"
},
"conflict": {
"symfony/http-kernel": "<4.4"
},
"autoload": {
"psr-4": { "Symfony\\Component\\HttpClient\\": "" },

View File

@ -23,7 +23,12 @@ use Symfony\Component\HttpFoundation\Response;
*/
class AjaxDataCollector extends DataCollector
{
public function collect(Request $request, Response $response, \Exception $exception = null)
/**
* {@inheritdoc}
*
* @param \Throwable|null $exception
*/
public function collect(Request $request, Response $response/*, \Throwable $exception = null*/)
{
// all collecting is done client side
}

View File

@ -56,8 +56,10 @@ class ConfigDataCollector extends DataCollector implements LateDataCollectorInte
/**
* {@inheritdoc}
*
* @param \Throwable|null $exception
*/
public function collect(Request $request, Response $response, \Exception $exception = null)
public function collect(Request $request, Response $response/*, \Throwable $exception = null*/)
{
$this->data = [
'app_name' => $this->name,

View File

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

View File

@ -40,8 +40,10 @@ class EventDataCollector extends DataCollector implements LateDataCollectorInter
/**
* {@inheritdoc}
*
* @param \Throwable|null $exception
*/
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

@ -26,9 +26,13 @@ class ExceptionDataCollector extends DataCollector
{
/**
* {@inheritdoc}
*
* @param \Throwable|null $exception
*/
public function collect(Request $request, Response $response, \Exception $exception = null)
public function collect(Request $request, Response $response/*, \Throwable $exception = null*/)
{
$exception = 2 < \func_num_args() ? func_get_arg(2) : null;
if (null !== $exception) {
$this->data = [
'exception' => FlattenException::createFromThrowable($exception),

View File

@ -43,8 +43,10 @@ class LoggerDataCollector extends DataCollector implements LateDataCollectorInte
/**
* {@inheritdoc}
*
* @param \Throwable|null $exception
*/
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

@ -30,8 +30,10 @@ class MemoryDataCollector extends DataCollector implements LateDataCollectorInte
/**
* {@inheritdoc}
*
* @param \Throwable|null $exception
*/
public function collect(Request $request, Response $response, \Exception $exception = null)
public function collect(Request $request, Response $response/*, \Throwable $exception = null*/)
{
$this->updateMemoryUsage();
}

View File

@ -36,8 +36,10 @@ class RequestDataCollector extends DataCollector implements EventSubscriberInter
/**
* {@inheritdoc}
*
* @param \Throwable|null $exception
*/
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,11 @@ class RouterDataCollector extends DataCollector
/**
* {@inheritdoc}
*
* @param \Throwable|null $exception
*
* @final since Symfony 4.4
*/
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

@ -35,8 +35,10 @@ class TimeDataCollector extends DataCollector implements LateDataCollectorInterf
/**
* {@inheritdoc}
*
* @param \Throwable|null $exception
*/
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

@ -12,6 +12,7 @@
namespace Symfony\Component\HttpKernel\Profiler;
use Psr\Log\LoggerInterface;
use Symfony\Component\Debug\Exception\FatalThrowableError;
use Symfony\Component\HttpFoundation\Exception\ConflictingHeadersException;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
@ -167,9 +168,14 @@ class Profiler implements ResetInterface
$response->headers->set('X-Debug-Token', $profile->getToken());
$wrappedException = null;
foreach ($this->collectors as $collector) {
$collector->collect($request, $response, $exception);
if (($e = $exception) instanceof \Error) {
$r = new \ReflectionMethod($collector, 'collect');
$e = 2 >= $r->getNumberOfParameters() || !($p = $r->getParameters()[2])->hasType() || \Exception::class !== $p->getType()->getName() ? $e : ($wrappedException ?? $wrappedException = new FatalThrowableError($e));
}
$collector->collect($request, $response, $e);
// we need to clone for sub-requests
$profile->addCollector(clone $collector);
}

View File

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

View File

@ -31,8 +31,10 @@ final class MessageDataCollector extends DataCollector
/**
* {@inheritdoc}
*
* @param \Throwable|null $exception
*/
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

@ -34,6 +34,7 @@
"symfony/sendgrid-mailer": "^4.4|^5.0"
},
"conflict": {
"symfony/http-kernel": "<4.4",
"symfony/sendgrid-mailer": "<4.4"
},
"autoload": {

View File

@ -34,8 +34,10 @@ class MessengerDataCollector extends DataCollector implements LateDataCollectorI
/**
* {@inheritdoc}
*
* @param \Throwable|null $exception
*/
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

@ -46,8 +46,10 @@ class TranslationDataCollector extends DataCollector implements LateDataCollecto
/**
* {@inheritdoc}
*
* @param \Throwable|null $exception
*/
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

@ -24,10 +24,9 @@
"symfony/config": "^3.4|^4.0|^5.0",
"symfony/console": "^3.4|^4.0|^5.0",
"symfony/dependency-injection": "^3.4|^4.0|^5.0",
"symfony/http-kernel": "^3.4|^4.0",
"symfony/http-kernel": "^4.4",
"symfony/intl": "^3.4|^4.0|^5.0",
"symfony/service-contracts": "^1.1.2|^2",
"symfony/var-dumper": "^3.4|^4.0|^5.0",
"symfony/yaml": "^3.4|^4.0|^5.0",
"symfony/finder": "~2.8|~3.0|~4.0|^5.0",
"psr/log": "~1.0"
@ -35,6 +34,7 @@
"conflict": {
"symfony/config": "<3.4",
"symfony/dependency-injection": "<3.4",
"symfony/http-kernel": "<4.4",
"symfony/yaml": "<3.4"
},
"provide": {

View File

@ -39,8 +39,10 @@ class ValidatorDataCollector extends DataCollector implements LateDataCollectorI
/**
* {@inheritdoc}
*
* @param \Throwable|null $exception
*/
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.
}

View File

@ -24,8 +24,7 @@
"require-dev": {
"symfony/http-client": "^4.3|^5.0",
"symfony/http-foundation": "^4.1|^5.0",
"symfony/http-kernel": "^3.4|^4.0",
"symfony/var-dumper": "^3.4|^4.0|^5.0",
"symfony/http-kernel": "^4.4",
"symfony/intl": "^4.3|^5.0",
"symfony/yaml": "^3.4|^4.0|^5.0",
"symfony/config": "^3.4|^4.0|^5.0",
@ -43,7 +42,7 @@
"doctrine/lexer": "<1.0.2",
"phpunit/phpunit": "<4.8.35|<5.4.3,>=5.0",
"symfony/dependency-injection": "<3.4",
"symfony/http-kernel": "<3.4",
"symfony/http-kernel": "<4.4",
"symfony/intl": "<4.3",
"symfony/translation": ">=5.0",
"symfony/yaml": "<3.4"