RedirectTarget::getTargets()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
/**
3
 * Health monitoring for Yii2 applications
4
 *
5
 * @link      https://github.com/hiqdev/yii2-monitoring
6
 * @package   yii2-monitoring
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\yii2\monitoring\targets;
12
13
use hiqdev\yii2\monitoring\Module;
14
use yii\log\Target;
15
16
/**
17
 * RedirectTarget redirects output to listed targets.
18
 */
19
class RedirectTarget extends \yii\log\Target
20
{
21
    protected $targets = [];
22
23
    public function setTargets($list)
24
    {
25
        $this->targets = $list;
26
    }
27
28
    public function getTargets()
29
    {
30
        return $this->targets;
31
    }
32
33
    public function export()
34
    {
35
        foreach ($this->getTargets() as $name) {
36
            $target = $this->getTarget($name);
37
            $target->messages = array_merge($target->messages, $this->messages);
38
            $target->export();
39
            $target->messages = [];
40
        }
41
    }
42
43
    /**
44
     * @param $name
45
     * @return Target
46
     */
47
    public function getTarget($name)
48
    {
49
        return $this->getModule()->getTarget($name);
50
    }
51
52
    public function getModule()
53
    {
54
        return Module::getInstance();
55
    }
56
57
    protected function getContextMessage()
58
    {
59
        return '';
60
    }
61
}
62