DebugServiceProvider::provides()   A
last analyzed

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 Nip\Debug\ErrorHandler;
8
use Psr\Log\LoggerInterface;
9
use Symfony\Component\ErrorHandler\BufferingLogger;
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 ['error-handler', ErrorHandler::class, \Nip\Debug\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
            return ErrorHandler::register(null, false);
46
        });
47
48
        $this->getContainer()->alias('error-handler', ErrorHandler::class);
49
        $this->getContainer()->alias('error-handler', \Nip\Debug\ErrorHandler::class);
50
    }
51
52
    public function boot()
53
    {
54
        ErrorHandler::register($this->getContainer()->get(ErrorHandler::class), true);
55
    }
56
}
57