LoggerServiceProvider::createLogger()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 5
rs 10
ccs 4
cts 4
cp 1
crap 1
1
<?php
2
3
namespace Nip\Logger;
4
5
use Monolog\Logger as Monolog;
6
use Nip\Container\ServiceProviders\Providers\AbstractSignatureServiceProvider;
7
use Nip\Container\ServiceProviders\Providers\BootableServiceProviderInterface;
8
use Nip\Debug\ErrorHandler;
9
use Psr\Log\LoggerInterface as PsrLoggerInterface;
10
11
/**
12
 * Class LoggerServiceProvider
13
 * @package Nip\Logger
14
 */
15
class LoggerServiceProvider extends AbstractSignatureServiceProvider implements BootableServiceProviderInterface
16
{
17
    /**
18
     * @inheritdoc
19
     */
20
    public function provides()
21
    {
22
        return ['log', PsrLoggerInterface::class];
23
    }
24
25
    /**
26
     * @inheritdoc
27
     */
28 1
    public function register()
29
    {
30 1
        $this->registerLog();
31 1
    }
32
33 1
    protected function registerLog()
34
    {
35
        $this->getContainer()->share('log', function () {
36 1
            return $this->createLogger();
37 1
        });
38 1
        $this->getContainer()->alias('log', PsrLoggerInterface::class);
39 1
    }
40
41
    /**
42
     * Create the logger.
43
     *
44
     * @return Manager
45
     */
46 1
    protected function createLogger()
47
    {
48 1
        $manager =  $this->getContainer()->get(Manager::class);
49 1
        $manager->setContainer($this->getContainer());
50 1
        return $manager;
51
    }
52
53
    public function boot()
54
    {
55
        $this->getContainer()->get(ErrorHandler::class)
56
            ->setDefaultLogger($this->getContainer()->get(PsrLoggerInterface::class));
57
    }
58
}
59