Completed
Push — master ( 8af72d...6a45d4 )
by Timo
04:44 queued 01:52
created

MonitorTrait::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 1
Metric Value
c 2
b 1
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Tidal\WampWatch;
4
5
/*
6
 * Copyright 2016 Timo Michna.
7
 *
8
 * For the full copyright and license information, please view the LICENSE file
9
 * that was distributed with this source code.
10
 */
11
12
use Evenement\EventEmitterTrait;
13
use Tidal\WampWatch\ClientSessionInterface as ClientSession;
14
15
/**
16
 * Description of MonitorTrait.
17
 *
18
 * @author Timo
19
 */
20
trait MonitorTrait
21
{
22
    use EventEmitterTrait;
23
24
    /**
25
     * The monitor's WAMP client session.
26
     *
27
     * @var ClientSession
28
     */
29
    protected $session;
30
31
    /**
32
     * Wether the monitor is running.
33
     *
34
     * @var bool
35
     */
36
    protected $isRunning = false;
37
38
    /**
39
     * @param ClientSession $session
40
     */
41
    protected function setClientSession(ClientSession $session)
42
    {
43
        $this->session = $session;
44
    }
45
46
    /**
47
     * Start the monitor.
48
     *
49
     * @return bool
50
     */
51
    public function start()
52
    {
53
        $this->isRunning = true;
54
        $this->emit('start', [$this->getList()]);
55
56
        return true;
57
    }
58
59
    /**
60
     * Stop the monitor.
61
     * Returns boolean wether the monitor could be started.
62
     *
63
     * @return bool
64
     */
65
    public function stop()
66
    {
67
        if (!$this->isRunning()) {
68
            return false;
69
        }
70
        $this->isRunning = false;
71
        $this->emit('stop', [$this]);
72
73
        return true;
74
    }
75
76
    protected function getList()
77
    {
78
        return [];
79
    }
80
81
    /**
82
     * Get the monitor's WAMP client session.
83
     *
84
     * @return ClientSession
85
     */
86
    public function getServerSession()
87
    {
88
        return $this->session;
89
    }
90
91
    /**
92
     * Get the monitor's running state.
93
     *
94
     * @return bool
95
     */
96
    public function isRunning()
97
    {
98
        return $this->isRunning;
99
    }
100
}
101