From cbe6270c16caf20d04443412ad8e53cc6cb8685a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Agust=C3=ADn=20Pacheco=20Di=20Santi?= <61388677+APachecoDiSanti@users.noreply.github.com> Date: Sat, 21 Mar 2020 13:52:12 -0300 Subject: [PATCH] Replace ExceptionListener uses with ErrorListener --- create_framework/dependency_injection.rst | 4 ++-- create_framework/http_kernel_httpkernel_class.rst | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/create_framework/dependency_injection.rst b/create_framework/dependency_injection.rst index 385ce02caee..b38241e3ce2 100644 --- a/create_framework/dependency_injection.rst +++ b/create_framework/dependency_injection.rst @@ -27,7 +27,7 @@ to it:: $argumentResolver = new HttpKernel\Controller\ArgumentResolver(); $dispatcher = new EventDispatcher(); - $dispatcher->addSubscriber(new HttpKernel\EventListener\ExceptionListener( + $dispatcher->addSubscriber(new HttpKernel\EventListener\ErrorListener( 'Calendar\Controller\ErrorController::exception' )); $dispatcher->addSubscriber(new HttpKernel\EventListener\RouterListener($matcher, $requestStack)); @@ -124,7 +124,7 @@ Create a new file to host the dependency injection container configuration:: $containerBuilder->register('listener.response', HttpKernel\EventListener\ResponseListener::class) ->setArguments(['UTF-8']) ; - $containerBuilder->register('listener.exception', HttpKernel\EventListener\ExceptionListener::class) + $containerBuilder->register('listener.exception', HttpKernel\EventListener\ErrorListener::class) ->setArguments(['Calendar\Controller\ErrorController::exception']) ; $containerBuilder->register('dispatcher', EventDispatcher\EventDispatcher::class) diff --git a/create_framework/http_kernel_httpkernel_class.rst b/create_framework/http_kernel_httpkernel_class.rst index 96bda4df692..1cf76830abd 100644 --- a/create_framework/http_kernel_httpkernel_class.rst +++ b/create_framework/http_kernel_httpkernel_class.rst @@ -66,7 +66,7 @@ framework: it matches the incoming request and populates the request attributes with route parameters. Our code is now much more concise and surprisingly more robust and more -powerful than ever. For instance, use the built-in ``ExceptionListener`` to +powerful than ever. For instance, use the built-in ``ErrorListener`` to make your error management configurable:: $errorHandler = function (Symfony\Component\ErrorHandler\Exception\FlattenException $exception) { @@ -74,14 +74,14 @@ make your error management configurable:: return new Response($msg, $exception->getStatusCode()); }; - $dispatcher->addSubscriber(new HttpKernel\EventListener\ExceptionListener($errorHandler)); + $dispatcher->addSubscriber(new HttpKernel\EventListener\ErrorListener($errorHandler)); -``ExceptionListener`` gives you a ``FlattenException`` instance instead of the +``ErrorListener`` gives you a ``FlattenException`` instance instead of the thrown ``Exception`` or ``Error`` instance to ease exception manipulation and display. It can take any valid controller as an exception handler, so you can create an ErrorController class instead of using a Closure:: - $listener = new HttpKernel\EventListener\ExceptionListener( + $listener = new HttpKernel\EventListener\ErrorListener( 'Calendar\Controller\ErrorController::exception' ); $dispatcher->addSubscriber($listener);