Completed
Push — master ( 759854...e46a01 )
by Martin
13:10 queued 03:41
created

Logger::workflow()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 1
1
<?php
2
3
namespace Yep\WorkflowLogger;
4
5
use Yep\WorkflowLogger\Formatter\FormatterInterface;
6
7
/**
8
 * Class Logger
9
 *
10
 * @package Yep\WorkflowLogger
11
 * @author  Martin Zeman (Zemistr) <[email protected]>
12
 */
13
class Logger extends \Monolog\Logger implements LoggerInterface
14
{
15
    /**
16
     * Detailed workflow debug information
17
     */
18
    const WORKFLOW = 111;
19
20
    /**
21
     * @var FormatterInterface
22
     */
23
    protected $workflowFormatter;
24
25
    /**
26
     * Logging levels from syslog protocol defined in RFC 5424
27
     *
28
     * @var array $levels Logging levels
29
     */
30
    protected static $levels = [
31
      self::WORKFLOW => 'WORKFLOW',
32
    ];
33
34
    /**
35
     * Logger constructor.
36
     *
37
     * @param string             $name
38
     * @param FormatterInterface $formatter
39
     * @param array              $handlers
40
     * @param array              $processors
41
     */
42
    public function __construct(
43
      $name,
44
      FormatterInterface $formatter,
45
      $handlers = [],
46
      $processors = []
47
    ) {
48
        parent::__construct($name, $handlers, $processors);
49
        self::$levels += parent::$levels;
50
        $this->workflowFormatter = $formatter;
51
    }
52
53
    /**
54
     * @return \DateTimeZone
55
     */
56
    protected function timezoneFactory()
57
    {
58
        if (static::$timezone) {
59
            return static::$timezone;
60
        }
61
62
        $timezone = date_default_timezone_get() ?: 'UTC';
63
64
        return static::$timezone = new \DateTimeZone($timezone);
65
    }
66
67
    /**
68
     * @param string $name
69
     * @return Workflow
70
     */
71
    public function workflow($name)
72
    {
73
        return new Workflow(
74
          $this,
75
          $this->workflowFormatter,
76
          $this->timezoneFactory(),
77
          $name,
78
          static::WORKFLOW
79
        );
80
    }
81
}
82