Skip to content
This repository has been archived by the owner on Jul 4, 2018. It is now read-only.

Commit

Permalink
decoupled the exception handler from HttpKernelServiceProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Sep 7, 2015
1 parent e6d86cb commit 83d9004
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 11 deletions.
2 changes: 2 additions & 0 deletions src/Silex/Application.php
Expand Up @@ -30,6 +30,7 @@
use Silex\Api\BootableProviderInterface;
use Silex\Api\EventListenerProviderInterface;
use Silex\Api\ControllerProviderInterface;
use Silex\Provider\ExceptionHandlerServiceProvider;
use Silex\Provider\RoutingServiceProvider;
use Silex\Provider\HttpKernelServiceProvider;

Expand Down Expand Up @@ -67,6 +68,7 @@ public function __construct(array $values = array())

$this->register(new HttpKernelServiceProvider());
$this->register(new RoutingServiceProvider());
$this->register(new ExceptionHandlerServiceProvider());

foreach ($values as $key => $value) {
$this[$key] = $value;
Expand Down
2 changes: 1 addition & 1 deletion src/Silex/ExceptionHandler.php
Expand Up @@ -17,7 +17,7 @@
use Symfony\Component\HttpKernel\KernelEvents;

/**
* Defaults exception handler.
* Default exception handler.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
Expand Down
32 changes: 32 additions & 0 deletions src/Silex/Provider/ExceptionHandlerServiceProvider.php
@@ -0,0 +1,32 @@
<?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 changes: 0 additions & 10 deletions src/Silex/Provider/HttpKernelServiceProvider.php
Expand Up @@ -10,7 +10,6 @@
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;
Expand All @@ -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']);
};
Expand All @@ -47,18 +42,13 @@ public function register(Container $app)
$app['callback_resolver'] = function ($app) {
return new CallbackResolver($app);
};

}

/**
* {@inheritdoc}
*/
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']));
Expand Down

0 comments on commit 83d9004

Please sign in to comment.