Commit 7b095c09 authored by Fabien Potencier's avatar Fabien Potencier

feature #1247 decoupled the exception handler from HttpKernelServiceProvider (fabpot)

This PR was merged into the 2.0.x-dev branch.

Discussion
----------

decoupled the exception handler from HttpKernelServiceProvider

Commits
-------

83d90041 decoupled the exception handler from HttpKernelServiceProvider
parents a95bd168 83d90041
......@@ -30,6 +30,7 @@ use Symfony\Component\HttpFoundation\JsonResponse;
use Silex\Api\BootableProviderInterface;
use Silex\Api\EventListenerProviderInterface;
use Silex\Api\ControllerProviderInterface;
use Silex\Provider\ExceptionHandlerServiceProvider;
use Silex\Provider\RoutingServiceProvider;
use Silex\Provider\HttpKernelServiceProvider;
......@@ -67,6 +68,7 @@ class Application extends Container implements HttpKernelInterface, TerminableIn
$this->register(new HttpKernelServiceProvider());
$this->register(new RoutingServiceProvider());
$this->register(new ExceptionHandlerServiceProvider());
foreach ($values as $key => $value) {
$this[$key] = $value;
......
......@@ -19,7 +19,7 @@ use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
use Symfony\Component\HttpKernel\KernelEvents;
/**
* Defaults exception handler.
* Default exception handler.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
......
<?php
namespace Silex\Provider;
use Pimple\Container;
use Pimple\ServiceProviderInterface;
use Silex\Api\EventListenerProviderInterface;
use Silex\ExceptionHandler;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
class ExceptionHandlerServiceProvider implements ServiceProviderInterface, EventListenerProviderInterface
{
/**
* {@inheritdoc}
*/
public function register(Container $app)
{
$app['exception_handler'] = function ($app) {
return new ExceptionHandler($app['debug']);
};
}
/**
* {@inheritdoc}
*/
public function subscribe(Container $app, EventDispatcherInterface $dispatcher)
{
if (isset($app['exception_handler'])) {
$dispatcher->addSubscriber($app['exception_handler']);
}
}
}
......@@ -10,7 +10,6 @@ use Silex\ControllerResolver;
use Silex\EventListener\ConverterListener;
use Silex\EventListener\MiddlewareListener;
use Silex\EventListener\StringToResponseListener;
use Silex\ExceptionHandler;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\RequestStack;
......@@ -24,10 +23,6 @@ class HttpKernelServiceProvider implements ServiceProviderInterface, EventListen
*/
public function register(Container $app)
{
$app['exception_handler'] = function ($app) {
return new ExceptionHandler($app['debug']);
};
$app['resolver'] = function ($app) {
return new ControllerResolver($app, $app['logger']);
};
......@@ -47,7 +42,6 @@ class HttpKernelServiceProvider implements ServiceProviderInterface, EventListen
$app['callback_resolver'] = function ($app) {
return new CallbackResolver($app);
};
}
/**
......@@ -55,10 +49,6 @@ class HttpKernelServiceProvider implements ServiceProviderInterface, EventListen
*/
public function subscribe(Container $app, EventDispatcherInterface $dispatcher)
{
if (isset($app['exception_handler'])) {
$dispatcher->addSubscriber($app['exception_handler']);
}
$dispatcher->addSubscriber(new ResponseListener($app['charset']));
$dispatcher->addSubscriber(new MiddlewareListener($app));
$dispatcher->addSubscriber(new ConverterListener($app['routes'], $app['callback_resolver']));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment