Test Setup Failed
Push — master ( c4d24d...9082b2 )
by Gabriel
13:27
created

DebugServiceProvider::provides()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Nip\Debug;
4
5
use Nip\Container\ServiceProviders\Providers\AbstractSignatureServiceProvider;
6
use Nip\Container\ServiceProviders\Providers\BootableServiceProviderInterface;
7
use Psr\Log\LoggerInterface;
8
use Symfony\Component\ErrorHandler\BufferingLogger;
9
use Nip\Debug\ErrorHandler;
10
11
/**
12
 * Class LoggerServiceProvider
13
 * @package Nip\Logger
14
 */
15
class DebugServiceProvider extends AbstractSignatureServiceProvider implements BootableServiceProviderInterface
16
{
17
18
    /**
19
     * @inheritdoc
20
     */
21
    public function provides()
22
    {
23
        return ['debug', 'error-handler', ErrorHandler::class];
24
    }
25
26
    /**
27
     * @inheritdoc
28
     */
29
    public function register()
30
    {
31
        $this->registerDebug();
32
        $this->registerErrorHandler();
33
    }
34
35
    public function registerDebug()
36
    {
37
        $this->getContainer()->share('debug', function () {
38
            return new Debug();
39
        });
40
    }
41
42
    public function registerErrorHandler()
43
    {
44
        $this->getContainer()->share('error-handler', function () {
45
            $logger = $this->getContainer()->has(LoggerInterface::class)
46
                ? $this->getContainer()->get(LoggerInterface::class)
47
                : new BufferingLogger();
48
49
            return new ErrorHandler($logger);
50
        });
51
52
        $this->getContainer()->alias('error-handler', ErrorHandler::class);
53
    }
54
55
    public function boot()
56
    {
57
        ErrorHandler::register($this->getContainer()->get(ErrorHandler::class), true);
58
    }
59
}
60