WhoopsServiceProvider::subscribe()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 2
1
<?php
2
/**
3
 * Whoops - php errors for cool kids
4
 * @author Filipe Dobreira <http://github.com/filp>
5
 */
6
7
namespace WhoopsSilex;
8
9
use Pimple\Container;
10
use Pimple\ServiceProviderInterface;
11
use Silex\Application;
12
use Silex\Api\EventListenerProviderInterface;
13
use Silex\ExceptionListenerWrapper;
14
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
15
use Symfony\Component\HttpKernel\KernelEvents;
16
use WhoopsPimple\WhoopsServiceProvider as PimpleWhoopsServiceProvider;
17
use WhoopsSilex\SilexApplicationHandler;
18
use WhoopsSilex\RequestHandler;
19
20
class WhoopsServiceProvider implements ServiceProviderInterface, EventListenerProviderInterface
21
{
22
    public function register(Container $container)
23
    {
24
        $container->register(new PimpleWhoopsServiceProvider);
25
        $container['whoops']->pushHandler(new RequestHandler($container));
26
        if ($container instanceof Application) {
27
            $container['whoops']->pushHandler(new SilexApplicationHandler($container));
28
        }
29
    }
30
31
    public function subscribe(Container $container, EventDispatcherInterface $dispatcher)
32
    {
33
        if ($container instanceof Application) {
34
            $dispatcher->addListener(
35
                KernelEvents::EXCEPTION,
36
                new ExceptionListenerWrapper($container, $container['whoops.exception_handler']),
37
                -1
38
            );
39
        }
40
    }
41
}
42