Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2d42d18

Browse files
[HttpKernel] rename ExceptionEvent to ErrorEvent and remove the ErrorException wrapper
1 parent 040d93d commit 2d42d18

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

+711
-180
lines changed

src/Symfony/Bundle/FrameworkBundle/Console/Application.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
use Symfony\Component\Console\Output\ConsoleOutputInterface;
2020
use Symfony\Component\Console\Output\OutputInterface;
2121
use Symfony\Component\Console\Style\SymfonyStyle;
22+
use Symfony\Component\Debug\Exception\FatalThrowableError;
2223
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
23-
use Symfony\Component\ErrorHandler\Exception\ErrorException;
2424
use Symfony\Component\HttpKernel\Bundle\Bundle;
2525
use Symfony\Component\HttpKernel\Kernel;
2626
use Symfony\Component\HttpKernel\KernelInterface;
@@ -211,7 +211,7 @@ private function renderRegistrationErrors(InputInterface $input, OutputInterface
211211
$this->doRenderThrowable($error, $output);
212212
} else {
213213
if (!$error instanceof \Exception) {
214-
$error = new ErrorException($error);
214+
$error = new FatalThrowableError($error);
215215
}
216216

217217
$this->doRenderException($error, $output);

src/Symfony/Bundle/FrameworkBundle/EventListener/SuggestMissingPackageSubscriber.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ final class SuggestMissingPackageSubscriber implements EventSubscriberInterface
4646

4747
public function onConsoleError(ConsoleErrorEvent $event): void
4848
{
49-
if (!$event->getError() instanceof CommandNotFoundException) {
49+
if (!$event->getException() instanceof CommandNotFoundException) {
5050
return;
5151
}
5252

@@ -64,14 +64,14 @@ public function onConsoleError(ConsoleErrorEvent $event): void
6464
$exact = false;
6565
}
6666

67-
$error = $event->getError();
67+
$error = $event->getException();
6868

6969
if ($error->getAlternatives() && !$exact) {
7070
return;
7171
}
7272

7373
$message = sprintf("%s\n\nYou may be looking for a command provided by the \"%s\" which is currently not installed. Try running \"composer require %s\".", $error->getMessage(), $suggestion[0], $suggestion[1]);
74-
$event->setError(new CommandNotFoundException($message));
74+
$event->setException(new CommandNotFoundException($message));
7575
}
7676

7777
public static function getSubscribedEvents(): array

src/Symfony/Bundle/FrameworkBundle/Resources/config/services.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
<parameter key="Symfony\Component\HttpKernel\Event\FinishRequestEvent">kernel.finish_request</parameter>
2222
<parameter key="Symfony\Component\HttpKernel\Event\RequestEvent">kernel.request</parameter>
2323
<parameter key="Symfony\Component\HttpKernel\Event\ViewEvent">kernel.view</parameter>
24+
<parameter key="Symfony\Component\HttpKernel\Event\ErrorEvent">kernel.error</parameter>
2425
<parameter key="Symfony\Component\HttpKernel\Event\ExceptionEvent">kernel.exception</parameter>
2526
<parameter key="Symfony\Component\HttpKernel\Event\TerminateEvent">kernel.terminate</parameter>
2627
<parameter key="Symfony\Component\Workflow\Event\GuardEvent">workflow.guard</parameter>

src/Symfony/Bundle/FrameworkBundle/Resources/config/web.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595
<argument type="service" id="error_renderer" />
9696
</service>
9797

98-
<service id="exception_listener" class="Symfony\Component\HttpKernel\EventListener\ExceptionListener">
98+
<service id="exception_listener" class="Symfony\Component\HttpKernel\EventListener\ErrorListener">
9999
<tag name="kernel.event_subscriber" />
100100
<tag name="monolog.logger" channel="request" />
101101
<argument>%kernel.error_controller%</argument>

src/Symfony/Bundle/FrameworkBundle/Tests/Console/ApplicationTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ private function createEventForSuggestingPackages(string $command, array $altern
254254
$subscriber = new SuggestMissingPackageSubscriber();
255255
$subscriber->onConsoleError($event);
256256

257-
return $event->getError()->getMessage();
257+
return $event->getException()->getMessage();
258258
}
259259

260260
private function getKernel(array $bundles, $useDispatcher = false)

src/Symfony/Bundle/FrameworkBundle/Tests/Kernel/ConcreteMicroKernel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load
103103
public static function getSubscribedEvents(): array
104104
{
105105
return [
106-
KernelEvents::EXCEPTION => 'onKernelException',
106+
KernelEvents::ERROR => 'onKernelException',
107107
];
108108
}
109109
}

src/Symfony/Bundle/FrameworkBundle/composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"paragonie/sodium_compat": "^1.8",
3636
"symfony/asset": "^3.4|^4.0|^5.0",
3737
"symfony/browser-kit": "^4.3|^5.0",
38-
"symfony/console": "^4.3.4|^5.0",
38+
"symfony/console": "^4.4|^5.0",
3939
"symfony/css-selector": "^3.4|^4.0|^5.0",
4040
"symfony/dom-crawler": "^4.3|^5.0",
4141
"symfony/dotenv": "^4.3.6|^5.0",
@@ -70,7 +70,7 @@
7070
"phpunit/phpunit": "<4.8.35|<5.4.3,>=5.0",
7171
"symfony/asset": "<3.4",
7272
"symfony/browser-kit": "<4.3",
73-
"symfony/console": "<4.3",
73+
"symfony/console": "<4.4",
7474
"symfony/dotenv": "<4.3.6",
7575
"symfony/dom-crawler": "<4.3",
7676
"symfony/http-client": "<4.4",

src/Symfony/Bundle/TwigBundle/Controller/PreviewErrorController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function previewErrorPageAction(Request $request, $code)
4343

4444
/*
4545
* This Request mimics the parameters set by
46-
* \Symfony\Component\HttpKernel\EventListener\ExceptionListener::duplicateRequest, with
46+
* \Symfony\Component\HttpKernel\EventListener\ErrorListener::duplicateRequest, with
4747
* the additional "showException" flag.
4848
*/
4949

src/Symfony/Component/Console/Application.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,8 @@
4242
use Symfony\Component\Console\Output\OutputInterface;
4343
use Symfony\Component\Console\Style\SymfonyStyle;
4444
use Symfony\Component\Debug\ErrorHandler as LegacyErrorHandler;
45-
use Symfony\Component\Debug\Exception\FatalThrowableError as LegacyFatalThrowableError;
45+
use Symfony\Component\Debug\Exception\FatalThrowableError;
4646
use Symfony\Component\ErrorHandler\ErrorHandler;
47-
use Symfony\Component\ErrorHandler\Exception\ErrorException;
4847
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
4948
use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy;
5049
use Symfony\Contracts\Service\ResetInterface;
@@ -245,7 +244,7 @@ public function doRun(InputInterface $input, OutputInterface $output)
245244
return 0;
246245
}
247246

248-
$e = $event->getError();
247+
$e = $event->getException();
249248
}
250249

251250
throw $e;
@@ -809,7 +808,7 @@ public function renderThrowable(\Throwable $e, OutputInterface $output): void
809808
@trigger_error(sprintf('The "%s::renderException()" method is deprecated since Symfony 4.4, use "renderThrowable()" instead.', __CLASS__), E_USER_DEPRECATED);
810809

811810
if (!$e instanceof \Exception) {
812-
$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()));
811+
$e = class_exists(FatalThrowableError::class) ? new FatalThrowableError($e) : new \ErrorException($e->getMessage(), $e->getCode(), E_ERROR, $e->getFile(), $e->getLine());
813812
}
814813

815814
$this->renderException($e, $output);
@@ -848,7 +847,7 @@ protected function doRenderThrowable(\Throwable $e, OutputInterface $output): vo
848847
@trigger_error(sprintf('The "%s::doRenderException()" method is deprecated since Symfony 4.4, use "doRenderThrowable()" instead.', __CLASS__), E_USER_DEPRECATED);
849848

850849
if (!$e instanceof \Exception) {
851-
$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()));
850+
$e = class_exists(FatalThrowableError::class) ? new FatalThrowableError($e) : new \ErrorException($e->getMessage(), $e->getCode(), E_ERROR, $e->getFile(), $e->getLine());
852851
}
853852

854853
$this->doRenderException($e, $output);
@@ -1034,7 +1033,7 @@ protected function doRunCommand(Command $command, InputInterface $input, OutputI
10341033
} catch (\Throwable $e) {
10351034
$event = new ConsoleErrorEvent($input, $output, $e, $command);
10361035
$this->dispatcher->dispatch($event, ConsoleEvents::ERROR);
1037-
$e = $event->getError();
1036+
$e = $event->getException();
10381037

10391038
if (0 === $exitCode = $event->getExitCode()) {
10401039
$e = null;

src/Symfony/Component/Console/Event/ConsoleErrorEvent.php

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,37 +22,57 @@
2222
*/
2323
final class ConsoleErrorEvent extends ConsoleEvent
2424
{
25-
private $error;
25+
private $exception;
2626
private $exitCode;
2727

28-
public function __construct(InputInterface $input, OutputInterface $output, \Throwable $error, Command $command = null)
28+
public function __construct(InputInterface $input, OutputInterface $output, \Throwable $exception, Command $command = null)
2929
{
3030
parent::__construct($command, $input, $output);
3131

32-
$this->error = $error;
32+
$this->exception = $exception;
3333
}
3434

35+
public function getException(): \Throwable
36+
{
37+
return $this->exception;
38+
}
39+
40+
public function setException(\Throwable $exception): void
41+
{
42+
$this->exception = $exception;
43+
}
44+
45+
/**
46+
* @deprecated since Symfony 4.4, use getException() instead
47+
*/
3548
public function getError(): \Throwable
3649
{
37-
return $this->error;
50+
@trigger_error(sprintf('The "%s()" method is deprecated since Symfony 4.4, use "getException()" instead.', __METHOD__), E_USER_DEPRECATED);
51+
52+
return $this->exception;
3853
}
3954

40-
public function setError(\Throwable $error): void
55+
/**
56+
* @deprecated since Symfony 4.4, use setException() instead
57+
*/
58+
public function setError(\Throwable $exception): void
4159
{
42-
$this->error = $error;
60+
@trigger_error(sprintf('The "%s()" method is deprecated since Symfony 4.4, use "setException()" instead.', __METHOD__), E_USER_DEPRECATED);
61+
62+
$this->exception = $exception;
4363
}
4464

4565
public function setExitCode(int $exitCode): void
4666
{
4767
$this->exitCode = $exitCode;
4868

49-
$r = new \ReflectionProperty($this->error, 'code');
69+
$r = new \ReflectionProperty($this->exception, 'code');
5070
$r->setAccessible(true);
51-
$r->setValue($this->error, $this->exitCode);
71+
$r->setValue($this->exception, $this->exitCode);
5272
}
5373

5474
public function getExitCode(): int
5575
{
56-
return null !== $this->exitCode ? $this->exitCode : (\is_int($this->error->getCode()) && 0 !== $this->error->getCode() ? $this->error->getCode() : 1);
76+
return null !== $this->exitCode ? $this->exitCode : (\is_int($this->exception->getCode()) && 0 !== $this->exception->getCode() ? $this->exception->getCode() : 1);
5777
}
5878
}

src/Symfony/Component/Console/EventListener/ErrorListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function onConsoleError(ConsoleErrorEvent $event)
3737
return;
3838
}
3939

40-
$error = $event->getError();
40+
$error = $event->getException();
4141

4242
if (!$inputString = $this->getInputString($event)) {
4343
$this->logger->error('An error occurred while using the console. Message: "{message}"', ['exception' => $error, 'message' => $error->getMessage()]);

src/Symfony/Component/Console/Tests/ApplicationTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1438,7 +1438,7 @@ public function testConsoleErrorEventIsTriggeredOnCommandNotFound()
14381438
$dispatcher = new EventDispatcher();
14391439
$dispatcher->addListener('console.error', function (ConsoleErrorEvent $event) {
14401440
$this->assertNull($event->getCommand());
1441-
$this->assertInstanceOf(CommandNotFoundException::class, $event->getError());
1441+
$this->assertInstanceOf(CommandNotFoundException::class, $event->getException());
14421442
$event->getOutput()->write('silenced command not found');
14431443
});
14441444

@@ -1727,7 +1727,7 @@ protected function getDispatcher($skipCommand = false)
17271727
$dispatcher->addListener('console.error', function (ConsoleErrorEvent $event) {
17281728
$event->getOutput()->write('error.');
17291729

1730-
$event->setError(new \LogicException('error.', $event->getExitCode(), $event->getError()));
1730+
$event->setException(new \LogicException('error.', $event->getExitCode(), $event->getException()));
17311731
});
17321732

17331733
return $dispatcher;

src/Symfony/Component/Debug/Exception/FatalErrorException.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111

1212
namespace Symfony\Component\Debug\Exception;
1313

14-
@trigger_error(sprintf('The "%s" class is deprecated since Symfony 4.4, use "%s" instead.', FatalErrorException::class, \Symfony\Component\ErrorHandler\Exception\ErrorException::class), E_USER_DEPRECATED);
14+
@trigger_error(sprintf('The "%s" class is deprecated since Symfony 4.4, use "%s" instead.', FatalErrorException::class, \Symfony\Component\ErrorHandler\Error\FatalError::class), E_USER_DEPRECATED);
1515

1616
/**
1717
* Fatal Error Exception.
1818
*
1919
* @author Konstanton Myakshin <[email protected]>
2020
*
21-
* @deprecated since Symfony 4.4, use Symfony\Component\ErrorHandler\Exception\ErrorException instead.
21+
* @deprecated since Symfony 4.4, use Symfony\Component\ErrorHandler\Error\FatalError instead.
2222
*/
2323
class FatalErrorException extends \ErrorException
2424
{

src/Symfony/Component/Debug/Exception/FatalThrowableError.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,12 @@
1111

1212
namespace Symfony\Component\Debug\Exception;
1313

14-
@trigger_error(sprintf('The "%s" class is deprecated since Symfony 4.4, use "%s" instead.', FatalThrowableError::class, \Symfony\Component\ErrorHandler\Exception\ErrorException::class), E_USER_DEPRECATED);
14+
@trigger_error(sprintf('The "%s" class is deprecated since Symfony 4.4.', FatalThrowableError::class), E_USER_DEPRECATED);
1515

1616
/**
1717
* Fatal Throwable Error.
1818
*
1919
* @author Nicolas Grekas <[email protected]>
20-
*
21-
* @deprecated since Symfony 4.4, use Symfony\Component\ErrorHandler\Exception\ErrorException instead.
2220
*/
2321
class FatalThrowableError extends FatalErrorException
2422
{

src/Symfony/Component/ErrorHandler/Exception/ErrorException.php

Lines changed: 0 additions & 42 deletions
This file was deleted.

src/Symfony/Component/ErrorRenderer/Exception/FlattenException.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
namespace Symfony\Component\ErrorRenderer\Exception;
1313

1414
use Symfony\Component\Debug\Exception\FlattenException as LegacyFlattenException;
15-
use Symfony\Component\ErrorHandler\Exception\ErrorException;
1615
use Symfony\Component\HttpFoundation\Exception\RequestExceptionInterface;
1716
use Symfony\Component\HttpFoundation\Response;
1817
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
@@ -70,7 +69,7 @@ public static function createFromThrowable(\Throwable $exception, int $statusCod
7069
$e->setStatusCode($statusCode);
7170
$e->setHeaders($headers);
7271
$e->setTraceFromThrowable($exception);
73-
$e->setClass($exception instanceof ErrorException ? $exception->getOriginalClassName() : \get_class($exception));
72+
$e->setClass(\get_class($exception));
7473
$e->setFile($exception->getFile());
7574
$e->setLine($exception->getLine());
7675

src/Symfony/Component/ErrorRenderer/Tests/Exception/FlattenExceptionTest.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
namespace Symfony\Component\ErrorRenderer\Tests\Exception;
1313

1414
use PHPUnit\Framework\TestCase;
15-
use Symfony\Component\ErrorHandler\Exception\ErrorException;
1615
use Symfony\Component\ErrorRenderer\Exception\FlattenException;
1716
use Symfony\Component\HttpFoundation\Exception\SuspiciousOperationException;
1817
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
@@ -130,16 +129,6 @@ public function testFlattenHttpException(\Throwable $exception)
130129
$this->assertInstanceOf($flattened->getClass(), $exception, 'The class is set to the class of the original exception');
131130
}
132131

133-
public function testWrappedThrowable()
134-
{
135-
$exception = new ErrorException(new \DivisionByZeroError('Ouch', 42));
136-
$flattened = FlattenException::createFromThrowable($exception);
137-
138-
$this->assertSame('Ouch', $flattened->getMessage(), 'The message is copied from the original error.');
139-
$this->assertSame(42, $flattened->getCode(), 'The code is copied from the original error.');
140-
$this->assertSame('DivisionByZeroError', $flattened->getClass(), 'The class is set to the class of the original error');
141-
}
142-
143132
public function testThrowable()
144133
{
145134
$error = new \DivisionByZeroError('Ouch', 42);

src/Symfony/Component/HttpKernel/Controller/ErrorController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function preview(Request $request, int $code): Response
5252

5353
/*
5454
* This Request mimics the parameters set by
55-
* \Symfony\Component\HttpKernel\EventListener\ExceptionListener::duplicateRequest, with
55+
* \Symfony\Component\HttpKernel\EventListener\ErrorListener::duplicateRequest, with
5656
* the additional "showException" flag.
5757
*/
5858
$subRequest = $request->duplicate(null, null, [

0 commit comments

Comments
 (0)