1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Event Object Class |
4
|
|
|
* |
5
|
|
|
* @package BlueEvent |
6
|
|
|
* @author Michał Adamiak <[email protected]> |
7
|
|
|
* @copyright chajr/bluetree |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace BlueEvent\Event\Base; |
11
|
|
|
|
12
|
|
|
use BlueEvent\Event\Base\Interfaces\EventInterface; |
13
|
|
|
|
14
|
|
|
abstract class Event implements EventInterface |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* store information how many times event object was called |
18
|
|
|
* |
19
|
|
|
* @var int |
20
|
|
|
*/ |
21
|
|
|
protected static $launchCount = 0; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* store information that event propagation is stopped or not |
25
|
|
|
* |
26
|
|
|
* @var bool |
27
|
|
|
*/ |
28
|
|
|
protected $propagationStopped = false; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var array |
32
|
|
|
*/ |
33
|
|
|
protected $eventParameters = []; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var string |
37
|
|
|
*/ |
38
|
|
|
protected $eventName = ''; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* create event instance |
42
|
|
|
* |
43
|
|
|
* @param string $eventName |
44
|
|
|
* @param array $parameters |
45
|
|
|
*/ |
46
|
|
|
public function __construct($eventName, array $parameters) |
47
|
|
|
{ |
48
|
|
|
$this->eventName = $eventName; |
49
|
|
|
$this->eventParameters = $parameters; |
50
|
|
|
|
51
|
|
|
self::$launchCount++; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* return number how many times event was called |
56
|
|
|
* |
57
|
|
|
* @return int |
58
|
|
|
*/ |
59
|
|
|
public static function getLaunchCount() |
60
|
|
|
{ |
61
|
|
|
return self::$launchCount; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* return information that event propagation is stopped or not |
66
|
|
|
* |
67
|
|
|
* @return bool |
68
|
|
|
*/ |
69
|
|
|
public function isPropagationStopped() |
70
|
|
|
{ |
71
|
|
|
return $this->propagationStopped; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* allow to stop event propagation |
76
|
|
|
* |
77
|
|
|
* @return $this |
78
|
|
|
*/ |
79
|
|
|
public function stopPropagation() |
80
|
|
|
{ |
81
|
|
|
$this->propagationStopped = true; |
82
|
|
|
return $this; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @return string |
87
|
|
|
*/ |
88
|
|
|
public function getEventCode() |
89
|
|
|
{ |
90
|
|
|
return $this->eventName; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @return array |
95
|
|
|
*/ |
96
|
|
|
public function getEventParameters() |
97
|
|
|
{ |
98
|
|
|
return $this->eventParameters; |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|