Completed
Push — master ( b01c18...6c15ba )
by Hong
06:44
created

CollectorAwareTrait::addCollectors()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
/**
3
 * Phossa Project
4
 *
5
 * PHP version 5.4
6
 *
7
 * @category  Library
8
 * @package   Phossa2\Route
9
 * @copyright Copyright (c) 2016 phossa.com
10
 * @license   http://mit-license.org/ MIT License
11
 * @link      http://www.phossa.com/
12
 */
13
/*# declare(strict_types=1); */
14
15
namespace Phossa2\Route\Traits;
16
17
use Phossa2\Route\Message\Message;
18
use Phossa2\Shared\Debug\DebuggableInterface;
19
use Phossa2\Route\Interfaces\CollectorInterface;
20
use Phossa2\Route\Interfaces\CollectorAwareInterface;
21
22
/**
23
 * CollectorAwareTrait
24
 *
25
 * Implementation of CollectorAwareInterface
26
 *
27
 * @package Phossa2\Route
28
 * @author  Hong Zhang <[email protected]>
29
 * @see     CollectorAwareInterface
30
 * @version 2.1.0
31
 * @since   2.0.0 added
32
 * @since   2.1.0 added `addCollectors()`
33
 */
34
trait CollectorAwareTrait
35
{
36
    /**
37
     * collector pool
38
     *
39
     * @var    CollectorInterface[]
40
     * @access protected
41
     */
42
    protected $collectors = [];
43
44
    /**
45
     * {@inheritDoc}
46
     */
47
    public function addCollector(CollectorInterface $collector)
48
    {
49
        // debugging
50
        if ($this instanceof DebuggableInterface && $this->isDebugging()) {
51
            $this->debug(
52
                Message::get(Message::RTE_COLLECTOR_ADD, get_class($collector))
53
            );
54
            $this->delegateDebugger($collector);
55
        }
56
57
        $this->collectors[] = $collector;
58
        return $this;
59
    }
60
61
    /**
62
     * {@inheritDoc}
63
     */
64
    public function addCollectors(array $collectors)
65
    {
66
        foreach ($collectors as $coll) {
67
            $this->addCollector($coll);
68
        }
69
        return $this;
70
    }
71
72
    /**
73
     * {@inheritDoc}
74
     */
75
    public function getCollectors()/*# : array */
76
    {
77
        return $this->collectors;
78
    }
79
}
80