Completed
Push — 15.x ( b45baa...4ca9b4 )
by Tim
02:13
created

SystemLoggerTrait::getSystemLogger()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 4
cts 4
cp 1
rs 9.9
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
/**
4
 * TechDivision\Import\SystemLoggerTrait
5
 *
6
 * NOTICE OF LICENSE
7
 *
8
 * This source file is subject to the Open Software License (OSL 3.0)
9
 * that is available through the world-wide-web at this URL:
10
 * http://opensource.org/licenses/osl-3.0.php
11
 *
12
 * PHP version 5
13
 *
14
 * @author    Tim Wagner <[email protected]>
15
 * @copyright 2016 TechDivision GmbH <[email protected]>
16
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
 * @link      https://github.com/techdivision/import
18
 * @link      http://www.techdivision.com
19
 */
20
21
namespace TechDivision\Import;
22
23
use TechDivision\Import\Utils\LoggerKeys;
24
25
/**
26
 * A trait that provides system logger handling.
27
 *
28
 * @author    Tim Wagner <[email protected]>
29
 * @copyright 2016 TechDivision GmbH <[email protected]>
30
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
31
 * @link      https://github.com/techdivision/import
32
 * @link      http://www.techdivision.com
33
 */
34
trait SystemLoggerTrait
35
{
36
37
    /**
38
     * The array with the system logger instances.
39
     *
40
     * @var array
41
     */
42
    protected $systemLoggers = array();
43
44
    /**
45
     * Return's the logger with the passed name, by default the system logger.
46
     *
47
     * @param string $name The name of the requested system logger
48
     *
49
     * @return \Psr\Log\LoggerInterface The logger instance
50
     * @throws \Exception Is thrown, if the requested logger is NOT available
51
     */
52 82
    public function getSystemLogger($name = LoggerKeys::SYSTEM)
53
    {
54
55
        // query whether or not, the requested logger is available
56 82
        if (isset($this->systemLoggers[$name])) {
57 82
            return $this->systemLoggers[$name];
58
        }
59
60
        // throw an exception if the requested logger is NOT available
61 1
        throw new \Exception(sprintf('The requested logger \'%s\' is not available', $name));
62
    }
63
64
    /**
65
     * Return's the array with the system logger instances.
66
     *
67
     * @return array The logger instance
68
     */
69 1
    public function getSystemLoggers()
70
    {
71 1
        return $this->systemLoggers;
72
    }
73
}
74