Completed
Pull Request — master (#6)
by Timo
06:41
created

MonitorTrait::setClientSession()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 2
Metric Value
c 3
b 0
f 2
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
    /**
40
     * @param ClientSession $session
41
     */
42
    protected function setClientSession(ClientSession $session)
43
    {
44
        $this->session = $session;
45
    }
46
47
48
    /**
49
     * Start the monitor.
50
     *
51
     * @return bool
52
     */
53
    public function start()
54
    {
55
        $this->isRunning = true;
56
        $this->emit('start', [$this->getList()]);
57
58
        return true;
59
    }
60
61
    /**
62
     * Stop the monitor.
63
     * Returns boolean wether the monitor could be started.
64
     *
65
     * @return bool
66
     */
67
    public function stop()
68
    {
69
        if (!$this->isRunning()) {
70
            return false;
71
        }
72
        $this->isRunning = false;
73
        $this->emit('stop', [$this]);
74
75
        return true;
76
    }
77
78
    protected function getList()
79
    {
80
        return [];
81
    }
82
83
    /**
84
     * Get the monitor's WAMP client session.
85
     *
86
     * @return ClientSession
87
     */
88
    public function getServerSession()
89
    {
90
        return $this->session;
91
    }
92
93
    /**
94
     * Get the monitor's running state.
95
     *
96
     * @return bool
97
     */
98
    public function isRunning()
99
    {
100
        return $this->isRunning;
101
    }
102
}
103