Completed
Push — master ( 8919db...5c5244 )
by Derek Stephen
05:58 queued 01:43
created

LogPackage::getEntityPath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php declare(strict_types=1);
2
3
namespace Bone\Log;
4
5
use Barnacle\Container;
6
use Barnacle\RegistrationInterface;
7
use Psr\Log\LoggerInterface;
8
9
class LogPackage implements RegistrationInterface
10
{
11
    /**
12
     * @param Container $c
13
     * @return array
14
     * @throws \Exception
15
     */
16
    public function addToContainer(Container $c)
17
    {
18
        if ($c->has('display_errors')) {
19
            ini_set('display_errors', (string) $c->get('display_errors'));
20
        }
21
22
        if ($c->has('error_reporting')) {
23
            error_reporting($c->get('error_reporting'));
24
        }
25
26
        if ($c->has('error_log')) {
27
            $errorLog = $c->get('error_log');
28
            if (!file_exists($errorLog)) {
29
                file_put_contents($errorLog, '');
30
                chmod($errorLog, 0775);
31
            }
32
            ini_set($c->get('error_log'), $errorLog);
33
        }
34
35
        if ($c->has('log')) {
36
            $c[LoggerInterface::class] = $c->factory(function (Container $c) {
37
                $config = $c->get('log');
38
                $loggerFactory = new LoggerFactory();
39
40
                return $loggerFactory->createLoggers($config);
41
            });
42
        }
43
    }
44
}
45