Completed
Pull Request — master (#89)
by Tim
03:51
created

SystemLoggerTrait::getSystemLoggers()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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