-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEvent.php
102 lines (87 loc) · 2.26 KB
/
Event.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
/*
* SimpleDispatcher is a package that provides trivial and fast way
* of dispatching events for PHP projects.
*
* @author Maciej Garycki <[email protected]>
* @copyrights Maciej Garycki
*/
namespace Puzzle\SimpleDispatcher;
/**
* Basic Event
*
* @author Maciej Garycki <[email protected]>
* @company Puzzle Design
* @copyrights Maciej Garycki 2013
*/
class Event implements EventInterface {
private $propagation_stopped = false;
protected $name = null;
protected $params = array();
/**
*
* @param string $name Mandatory event name
*/
public function __construct($name, array $params = array()) {
$this->name = $name;
$this->params = $params;
}
/**
* Stops the event's propagation, it will no more be dispatched
* by any further listeners.
*
* @return Event Returns this for chaining.
*/
public function stopPropagation () {
$this->propagation_stopped = true;
return $this;
}
/**
* Defines weather or not a Event::stopPropagation()
* method has been called on this object
*
* @return bool
*/
public function isPropagationStopped () {
return $this->propagation_stopped;
}
/**
* Provides event name
*
* @return string
*/
public function getName () {
return $this->name;
}
/**
* Provide previously set parameter for given name
*
* @param string $name
* @throws \InvalidArgumentException
* @return mixed
*/
public function getParameter ($name) {
if (!isset($this->params[$name])) {
throw new \InvalidArgumentException('Parameter \'' . $name . '\' has not been set in this event!');
}
return $this->params[$name];
}
/**
* Sets a value for parameter of given name
*
* @param string $name
* @param mixed $value
*/
public function setParameter ($name, $value) {
$this->params[$name] = $value;
}
/**
* Defines if parameter exists within the event
*
* @param string $name
* @return bool
*/
public function hasParameter ($name) {
return isset($this->params[$name]);
}
}