Completed
Push — master ( 673fc6...a88edb )
by Oleg
03:40
created

LoggerDriver::isSupportedLevel()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 2
eloc 2
nc 2
nop 1
1
<?php /** MicroLoggerDriverInterface */
2
3
namespace Micro\Logger\Drivers;
4
5
use Micro\Base\Exception;
6
use Micro\Logger\Adapter;
7
8
/**
9
 * Base loggerDriver class file.
10
 *
11
 * Interface for loggers
12
 *
13
 * @author Oleg Lunegov <[email protected]>
14
 * @link https://github.com/linpax/microphp-framework
15
 * @copyright Copyright (c) 2013 Oleg Lunegov
16
 * @license https://github.com/linpax/microphp-framework/blob/master/LICENSE
17
 * @package Micro
18
 * @subpackage Logger\Driver
19
 * @version 1.0
20
 * @since 1.0
21
 */
22
abstract class LoggerDriver implements Adapter
23
{
24
    /** @var array $supportedLevels supported log levels */
25
    protected $supportedLevels = [];
26
27
28
    /**
29
     * Constructor is a initialize logger
30
     *
31
     * @access public
32
     *
33
     * @param array $params configuration params
34
     *
35
     * @throws Exception
36
     * @result void
37
     */
38
    public function __construct(array $params = [])
39
    {
40
        $levels = explode(',', str_replace(' ', '', strtolower($params['levels'])));
41
42
        foreach ($levels AS $level) {
43
            if (in_array($level, Logger::$supportedLevels, true)) {
44
                $this->supportedLevels[] = $level;
45
            }
46
        }
47
    }
48
49
    /**
50
     * Check support level
51
     *
52
     * @access public
53
     *
54
     * @param integer $level level number
55
     *
56
     * @return bool
57
     */
58
    public function isSupportedLevel($level)
59
    {
60
        return in_array($level, $this->supportedLevels, false) === false ?: true;
61
    }
62
}
63