1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Fwk |
4
|
|
|
* |
5
|
|
|
* Copyright (c) 2011-2012, Julien Ballestracci <[email protected]>. |
6
|
|
|
* All rights reserved. |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
* |
11
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
12
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
13
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
14
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
15
|
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
16
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
17
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
18
|
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
19
|
|
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
20
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
21
|
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
22
|
|
|
* POSSIBILITY OF SUCH DAMAGE. |
23
|
|
|
* |
24
|
|
|
* PHP Version 5.3 |
25
|
|
|
* |
26
|
|
|
* @category EventDispatcher |
27
|
|
|
* @package Fwk\Events |
28
|
|
|
* @author Julien Ballestracci <[email protected]> |
29
|
|
|
* @copyright 2011-2014 Julien Ballestracci <[email protected]> |
30
|
|
|
* @license http://www.opensource.org/licenses/bsd-license.php BSD License |
31
|
|
|
* @link http://www.nitronet.org/fwk |
32
|
|
|
*/ |
33
|
|
|
namespace Fwk\Events; |
34
|
|
|
|
35
|
|
|
use \ArrayObject; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Event |
39
|
|
|
* |
40
|
|
|
* This class represents an Event to be triggered into an EventDispatcher |
41
|
|
|
* |
42
|
|
|
* @category Event |
43
|
|
|
* @package Fwk\Events |
44
|
|
|
* @author Julien Ballestracci <[email protected]> |
45
|
|
|
* @license http://www.opensource.org/licenses/bsd-license.php BSD License |
46
|
|
|
* @link http://www.nitronet.org/fwk |
47
|
|
|
*/ |
48
|
|
|
class Event extends ArrayObject |
49
|
|
|
{ |
50
|
|
|
/** |
51
|
|
|
* This event's name |
52
|
|
|
* @var string |
53
|
|
|
*/ |
54
|
|
|
protected $name; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Tells if this event has been processed |
58
|
|
|
* @var boolean |
59
|
|
|
*/ |
60
|
|
|
protected $processed = false; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Stop propagation ? |
64
|
|
|
* @var boolean |
65
|
|
|
*/ |
66
|
|
|
protected $stopped = false; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Creates the event and attach some data |
70
|
|
|
* |
71
|
|
|
* @param string $name Event name |
72
|
|
|
* @param array $data Event data |
73
|
|
|
* |
74
|
|
|
* @return void |
|
|
|
|
75
|
|
|
*/ |
76
|
10 |
|
public function __construct($name, $data = array()) |
77
|
|
|
{ |
78
|
10 |
|
parent::__construct($data); |
79
|
10 |
|
$this->setFlags(\ArrayObject::ARRAY_AS_PROPS); |
80
|
10 |
|
$this->name = $name; |
81
|
10 |
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Returns this event name |
85
|
|
|
* |
86
|
|
|
* @return string |
87
|
|
|
*/ |
88
|
7 |
|
public function getName() |
89
|
|
|
{ |
90
|
7 |
|
return $this->name; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Returns the data |
95
|
|
|
* |
96
|
|
|
* @return array |
97
|
|
|
*/ |
98
|
1 |
|
public function getData() |
99
|
|
|
{ |
100
|
1 |
|
return $this->getArrayCopy(); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Sets the processed flag |
105
|
|
|
* |
106
|
|
|
* @param boolean $processed Processed or not |
107
|
|
|
* |
108
|
|
|
* @return Event |
109
|
|
|
*/ |
110
|
6 |
|
public function setProcessed($processed) |
111
|
|
|
{ |
112
|
6 |
|
$this->processed = (boolean)$processed; |
113
|
|
|
|
114
|
6 |
|
return $this; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Stops event propagation |
119
|
|
|
* |
120
|
|
|
* @return void |
121
|
|
|
*/ |
122
|
1 |
|
public function stop() |
123
|
|
|
{ |
124
|
1 |
|
$this->stopped = true; |
125
|
1 |
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Tells if the event is stopped |
129
|
|
|
* |
130
|
|
|
* @return boolean |
131
|
|
|
*/ |
132
|
5 |
|
public function isStopped() |
133
|
|
|
{ |
134
|
5 |
|
return $this->stopped; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* Tells if this event is processed |
139
|
|
|
* |
140
|
|
|
* @return boolean |
141
|
|
|
*/ |
142
|
3 |
|
public function isProcessed() |
143
|
|
|
{ |
144
|
3 |
|
return $this->processed; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* Retrieve the $key parameter |
149
|
|
|
* |
150
|
|
|
* @param string $key Parameter name |
151
|
|
|
* |
152
|
|
|
* @return mixed |
153
|
|
|
*/ |
154
|
1 |
|
public function __get($key) |
155
|
|
|
{ |
156
|
1 |
|
return $this->offsetGet($key); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* Sets a parameter for this event |
161
|
|
|
* |
162
|
|
|
* @param string $key Parameter name |
163
|
|
|
* @param mixed $value Parameter value |
164
|
|
|
* |
165
|
|
|
* @return void |
166
|
|
|
*/ |
167
|
1 |
|
public function __set($key, $value) |
168
|
|
|
{ |
169
|
1 |
|
return $this->offsetSet($key, $value); |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* Tells if the $key parameter is defined for this event |
174
|
|
|
* |
175
|
|
|
* @param string $key Parameter name |
176
|
|
|
* |
177
|
|
|
* @return boolean |
178
|
|
|
*/ |
179
|
1 |
|
public function __isset($key) |
|
|
|
|
180
|
|
|
{ |
181
|
1 |
|
return $this->offsetExists($key); |
182
|
|
|
} |
183
|
|
|
} |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.