Completed
Push — master ( 7c429e...75748b )
by Michael
03:23
created

LogWiring   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 4
Bugs 1 Features 0
Metric Value
wmc 3
c 4
b 1
f 0
lcom 0
cbo 2
dl 0
loc 49
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B wire() 0 41 3
1
<?php
2
/**
3
 * Contains class LogWiring.
4
 *
5
 * PHP version 5.5
6
 *
7
 * LICENSE:
8
 * This file is part of Yet Another Php Eve Api Library also know as Yapeal
9
 * which can be used to access the Eve Online API data and place it into a
10
 * database.
11
 * Copyright (C) 2016 Michael Cummings
12
 *
13
 * This program is free software: you can redistribute it and/or modify it
14
 * under the terms of the GNU Lesser General Public License as published by the
15
 * Free Software Foundation, either version 3 of the License, or (at your
16
 * option) any later version.
17
 *
18
 * This program is distributed in the hope that it will be useful, but WITHOUT
19
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
21
 * for more details.
22
 *
23
 * You should have received a copy of the GNU Lesser General Public License
24
 * along with this program. If not, see
25
 * <http://www.gnu.org/licenses/>.
26
 *
27
 * You should be able to find a copy of this license in the LICENSE.md file. A
28
 * copy of the GNU GPL should also be available in the GNU-GPL.md file.
29
 *
30
 * @copyright 2016 Michael Cummings
31
 * @license   LGPL-3.0+
32
 * @author    Michael Cummings <[email protected]>
33
 */
34
namespace Yapeal\Configuration;
35
36
use Monolog\Formatter\LineFormatter;
37
use Yapeal\Container\ContainerInterface;
38
39
/**
40
 * Class LogWiring.
41
 */
42
class LogWiring implements WiringInterface
43
{
44
    /**
45
     * @param ContainerInterface $dic
46
     *
47
     * @return self Fluent interface.
48
     */
49
    public function wire(ContainerInterface $dic)
50
    {
51
        if (empty($dic['Yapeal.Log.Logger'])) {
52
            $dic['Yapeal.Log.Logger'] = function () use ($dic) {
53
                $group = [];
54
                $lineFormatter = new LineFormatter();
55
                $lineFormatter->includeStacktraces();
56
                $lineFormatter->allowInlineLineBreaks();
57
                /**
58
                 * @var \Monolog\Handler\StreamHandler $handler
59
                 */
60
                if (PHP_SAPI === 'cli') {
61
                    $handler = new $dic['Yapeal.Log.Handlers.stream'](
62
                        'php://stderr', 100
63
                    );
64
                    $handler->setFormatter($lineFormatter);
65
                    $group[] = $handler;
66
                }
67
                $handler = new $dic['Yapeal.Log.Handlers.stream'](
68
                    $dic['Yapeal.Log.dir'] . $dic['Yapeal.Log.fileName'], 100
69
                );
70
                $handler->setFormatter($lineFormatter);
71
                $group[] = $handler;
72
                return new $dic['Yapeal.Log.class'](
73
                    $dic['Yapeal.Log.channel'], [
74
                        new $dic['Yapeal.Log.Handlers.fingersCrossed'](new $dic['Yapeal.Log.Handlers.group']($group),
75
                            (int)$dic['Yapeal.Log.threshold'], (int)$dic['Yapeal.Log.bufferSize'], true, false)
76
                    ]
77
                );
78
            };
79
        }
80
        /**
81
         * @var \Yapeal\Event\MediatorInterface $mediator
82
         */
83
        $mediator = $dic['Yapeal.Event.Mediator'];
84
        $mediator->addServiceSubscriberByEventList(
85
            'Yapeal.Log.Logger',
86
            ['Yapeal.Log.log' => ['logEvent', 'last']]
87
        );
88
        return $this;
89
    }
90
}
91