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

Skip to content

Commit 73e9009

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

Some content is hidden

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

47 files changed

+736
-181
lines changed

UPGRADE-4.4.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Console
1414
* Deprecated returning `null` from `Command::execute()`, return `0` instead
1515
* Deprecated the `Application::renderException()` and `Application::doRenderException()` methods,
1616
use `renderThrowable()` and `doRenderThrowable()` instead.
17+
* Deprecated `ConsoleErrorEvent::getError()/setError()`, use `getException()/setException()` instead
1718

1819
Debug
1920
-----
@@ -154,6 +155,12 @@ HttpKernel
154155
* Marked the `RouterDataCollector::collect()` method as `@final`.
155156
* The `DataCollectorInterface::collect()` and `Profiler::collect()` methods third parameter signature
156157
will be `\Throwable $exception = null` instead of `\Exception $exception = null` in Symfony 5.0.
158+
* Deprecated class `ExceptionEvent`, use `ErrorEvent` instead
159+
* Deprecated class `ExceptionListener`, use `ErrorListener` instead
160+
* Deprecated constant `KernelEvents::EXCEPTION`, use `KernelEvents::ERROR` instead
161+
* Deprecated event `kernel.exception`, listen to `kernel.error` instead
162+
* Deprecated method `ProfilerListener::onKernelException()`, use `onKernelError()` instead
163+
* Deprecated method `RouterListener::onKernelException()`, use `onKernelError()` instead
157164

158165
Lock
159166
----
@@ -212,6 +219,7 @@ Security
212219
* The `LdapUserProvider` class has been deprecated, use `Symfony\Component\Ldap\Security\LdapUserProvider` instead.
213220
* Implementations of `PasswordEncoderInterface` and `UserPasswordEncoderInterface` should add a new `needsRehash()` method
214221
* Deprecated returning a non-boolean value when implementing `Guard\AuthenticatorInterface::checkCredentials()`. Please explicitly return `false` to indicate invalid credentials.
222+
* Deprecated method `ExceptionListener::onKernelException()`, use `onKernelError()` instead
215223
* Deprecated passing more than one attribute to `AccessDecisionManager::decide()` and `AuthorizationChecker::isGranted()` (and indirectly the `is_granted()` Twig and ExpressionLanguage function)
216224

217225
**Before**

UPGRADE-5.0.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ Console
3939
* Removed the `setVerticalBorderChar()` method in favor of the `setVerticalBorderChars()` method in `TableStyle`.
4040
* Removed the `getVerticalBorderChar()` method in favor of the `getBorderChars()` method in `TableStyle`.
4141
* Removed support for returning `null` from `Command::execute()`, return `0` instead
42+
* Removed `ConsoleErrorEvent::getError()/setError()`, use `getException()/setException()` instead
4243
* The `ProcessHelper::run()` method takes the command as an array of arguments.
4344

4445
Before:
@@ -290,6 +291,12 @@ HttpKernel
290291
* Removed `TranslatorListener` in favor of `LocaleAwareListener`
291292
* The `DebugHandlersListener` class has been made `final`
292293
* Removed `SaveSessionListener` in favor of `AbstractSessionListener`
294+
* Removed class `ExceptionEvent`, use `ErrorEvent` instead
295+
* Removed class `ExceptionListener`, use `ErrorListener` instead
296+
* Removed constant `KernelEvents::EXCEPTION`, use `KernelEvents::ERROR` instead
297+
* Removed event `kernel.exception`, listen to `kernel.error` instead
298+
* Removed method `ProfilerListener::onKernelException()`, use `onKernelError()` instead
299+
* Removed method `RouterListener::onKernelException()`, use `onKernelError()` instead
293300
* Added new Bundle directory convention consistent with standard skeletons:
294301

295302
```
@@ -470,6 +477,7 @@ Security
470477
* Classes implementing the `TokenInterface` must implement the two new methods
471478
`__serialize` and `__unserialize`
472479
* Implementations of `Guard\AuthenticatorInterface::checkCredentials()` must return a boolean value now. Please explicitly return `false` to indicate invalid credentials.
480+
* Removed method `ExceptionListener::onKernelException()`, use `onKernelError()` instead
473481

474482
SecurityBundle
475483
--------------

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/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ CHANGELOG
1414
* Deprecated the `Application::renderException()` and `Application::doRenderException()` methods,
1515
use `renderThrowable()` and `doRenderThrowable()` instead.
1616
* added support for the `NO_COLOR` env var (https://no-color.org/)
17+
* deprecated `ConsoleErrorEvent::getError()/setError()`, use `getException()/setException()` instead
1718

1819
4.3.0
1920
-----

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.

0 commit comments

Comments
 (0)