1<?php 2 3namespace Silex\Provider; 4 5use Pimple\Container; 6use Pimple\ServiceProviderInterface; 7use Silex\Api\EventListenerProviderInterface; 8use Silex\ExceptionHandler; 9use Symfony\Component\EventDispatcher\EventDispatcherInterface; 10 11class ExceptionHandlerServiceProvider implements ServiceProviderInterface, EventListenerProviderInterface 12{ 13 /** 14 * {@inheritdoc} 15 */ 16 public function register(Container $app) 17 { 18 $app['exception_handler'] = function ($app) { 19 return new ExceptionHandler($app['debug']); 20 }; 21 } 22 23 /** 24 * {@inheritdoc} 25 */ 26 public function subscribe(Container $app, EventDispatcherInterface $dispatcher) 27 { 28 if (isset($app['exception_handler'])) { 29 $dispatcher->addSubscriber($app['exception_handler']); 30 } 31 } 32} 33