EventContext::stop()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/**
4
 * @copyright 2018 Aleksander Stelmaczonek <[email protected]>
5
 * @license   MIT License, see license file distributed with this source code
6
 */
7
8
namespace Koriit\EventDispatcher;
9
10
class EventContext implements EventContextInterface
11
{
12
    /**
13
     * @var bool
14
     */
15
    protected $stopped = false;
16
17
    /**
18
     * @var mixed
19
     */
20
    protected $stopValue;
21
22
    /**
23
     * @var bool
24
     */
25
    protected $ignoreReturnValue = false;
26
27
    /**
28
     * @var array
29
     */
30
    protected $executedListeners = [];
31
32
    /**
33
     * @var array
34
     */
35
    protected $stoppedListeners = [];
36
37
    /**
38
     * @var mixed
39
     */
40
    protected $eventName;
41
42
    public function __construct($eventName)
43
    {
44
        $this->eventName = $eventName;
45
    }
46
47
    public function getEventName()
48
    {
49
        return $this->eventName;
50
    }
51
52
    public function getStoppedListeners()
53
    {
54
        return $this->stoppedListeners;
55
    }
56
57
    public function addStoppedListener($listener)
58
    {
59
        $this->stoppedListeners[] = $listener;
60
    }
61
62
    public function getExecutedListeners()
63
    {
64
        return $this->executedListeners;
65
    }
66
67
    public function addExecutedListener($listener)
68
    {
69
        $this->executedListeners[] = $listener;
70
    }
71
72
    public function isStopped()
73
    {
74
        return $this->stopped;
75
    }
76
77
    public function setStopped($value)
78
    {
79
        $this->stopped = $value;
80
    }
81
82
    public function getStopValue()
83
    {
84
        return $this->stopValue;
85
    }
86
87
    public function ignoreReturnValue($switch)
88
    {
89
        $this->ignoreReturnValue = $switch;
90
    }
91
92
    public function isReturnValueIgnored()
93
    {
94
        return $this->ignoreReturnValue;
95
    }
96
97
    public function stop()
98
    {
99
        $this->stopped = true;
100
    }
101
102
    /**
103
     * Sets the value which stopped the dispatchment chain.
104
     *
105
     * @param mixed $stopValue
106
     *
107
     * @return void
108
     */
109
    public function setStopValue($stopValue)
110
    {
111
        $this->stopValue = $stopValue;
112
    }
113
}
114