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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
Doctrine::autoload('Doctrine_Access');
/**
* Doctrine_EventListener_Chain
* this class represents a chain of different listeners,
* useful for having multiple listeners listening the events at the same time
*
* @author Konsta Vesterinen
* @package Doctrine ORM
* @url www.phpdoctrine.com
* @license LGPL
*/
class Doctrine_EventListener_Chain extends Doctrine_Access implements Doctrine_EventListener_Interface {
/**
* @var array $listeners an array containing all listeners
*/
private $listeners = array();
/**
* add
*
* @param Doctrine_EventListener $listener
* @return void
*/
public function add(Doctrine_EventListener $listener) {
$this->listeners[] = $listener;
}
/**
* returns a Doctrine_EvenListener on success
* and null on failure
*
* @param mixed $key
* @return mixed
*/
public function get($key) {
if( ! isset($this->listeners[$key]))
return null;
return $this->listeners[$key];
}
/**
* set
*
* @param mixed $key
* @param Doctrine_EventListener $listener
* @return void
*/
public function set($key, Doctrine_EventListener $listener) {
$this->listeners[$key] = $listener;
}
/**
* onLoad
* an event invoked when Doctrine_Record is being loaded from database
*
* @param Doctrine_Record $record
* @return void
*/
public function onLoad(Doctrine_Record $record) {
foreach($this->listeners as $listener) {
$listener->onLoad($record);
}
}
/**
* onPreLoad
* an event invoked when Doctrine_Record is being loaded
* from database but not yet initialized
*
* @param Doctrine_Record $record
* @return void
*/
public function onPreLoad(Doctrine_Record $record) {
foreach($this->listeners as $listener) {
$listener->onPreLoad($record);
}
}
/**
* onSleep
* an event invoked when Doctrine_Record is serialized
*
* @param Doctrine_Record $record
* @return void
*/
public function onSleep(Doctrine_Record $record) {
foreach($this->listeners as $listener) {
$listener->onSleep($record);
}
}
/**
* onWakeUp
* an event invoked when Doctrine_Record is unserialized
*
* @param Doctrine_Record $record
* @return void
*/
public function onWakeUp(Doctrine_Record $record) {
foreach($this->listeners as $listener) {
$listener->onWakeUp($record);
}
}
/**
* onUpdate
* an event invoked after Doctrine_Record is updated
*
* @param Doctrine_Record $record
* @return void
*/
public function onUpdate(Doctrine_Record $record) {
foreach($this->listeners as $listener) {
$listener->onUpdate($record);
}
}
/**
* onPreUpdate
* an event invoked before Doctrine_Record is updated
*
* @param Doctrine_Record $record
* @return void
*/
public function onPreUpdate(Doctrine_Record $record) {
foreach($this->listeners as $listener) {
$listener->onPreUpdate($record);
}
}
/**
* onCreate
* an event invoked when a new Doctrine_Record is created
*
* @param Doctrine_Record $record
* @return void
*/
public function onCreate(Doctrine_Record $record) {
foreach($this->listeners as $listener) {
$listener->onCreate($record);
}
}
/**
* onPreCreate
* an event invoked when a new Doctrine_Record
* but not yet initialized
*
* @param Doctrine_Record $record
* @return void
*/
public function onPreCreate(Doctrine_Record $record) {
foreach($this->listeners as $listener) {
$listener->onPreCreate($record);
}
}
/**
* onSave
* an event invoked after a Doctrine_Record is saved (inserted / updated)
*
* @param Doctrine_Record $record
* @return void
*/
public function onSave(Doctrine_Record $record) {
foreach($this->listeners as $listener) {
$listener->onSave($record);
}
}
/**
* onSave
* an event invoked after a Doctrine_Record is saved (inserted / updated)
*
* @param Doctrine_Record $record
* @return void
*/
public function onPreSave(Doctrine_Record $record) {
foreach($this->listeners as $listener) {
$listener->onPreSave($record);
}
}
/**
* onGetProperty
* an event invoked when a property of Doctrine_Record is retrieved
*
* @param Doctrine_Record $record
* @param string $property
* @param mixed $value
* @return mixed
*/
public function onGetProperty(Doctrine_Record $record, $property, $value) {
foreach($this->listeners as $listener) {
$value = $listener->onGetProperty($record, $property, $value);
}
return $value;
}
/**
* onSetProperty
* an event invoked when a property of Doctrine_Record is being set
*
* @param Doctrine_Record $record
* @param string $property
* @param mixed $value
* @return mixed
*/
public function onSetProperty(Doctrine_Record $record, $property, $value) {
foreach($this->listeners as $listener) {
$value = $listener->onSetProperty($record, $property, $value);
}
return $value;
}
/**
* onInsert
* an event invoked after Doctrine_Record is inserted into database
*
* @param Doctrine_Record $record
* @return void
*/
public function onInsert(Doctrine_Record $record) {
foreach($this->listeners as $listener) {
$listener->onInsert($record);
}
}
/**
* onPreInsert
* an event invoked before Doctrine_Record is inserted into database
*
* @param Doctrine_Record $record
* @return void
*/
public function onPreInsert(Doctrine_Record $record) {
foreach($this->listeners as $listener) {
$listener->onPreInsert($record);
}
}
/**
* onDelete
* an event invoked after Doctrine_Record is deleted from database
*
* @param Doctrine_Record $record
* @return void
*/
public function onDelete(Doctrine_Record $record) {
foreach($this->listeners as $listener) {
$listener->onDelete($record);
}
}
/**
* onPreDelete
* an event invoked before Doctrine_Record is deleted from database
*
* @param Doctrine_Record $record
* @return void
*/
public function onPreDelete(Doctrine_Record $record) {
foreach($this->listeners as $listener) {
$listener->onPreDelete($record);
}
}
/**
* onEvict
* an event invoked after Doctrine_Record is evicted from record repository
*
* @param Doctrine_Record $record
* @return void
*/
public function onEvict(Doctrine_Record $record) {
foreach($this->listeners as $listener) {
$listener->onEvict($record);
}
}
/**
* onPreEvict
* an event invoked before Doctrine_Record is evicted from record repository
*
* @param Doctrine_Record $record
* @return void
*/
public function onPreEvict(Doctrine_Record $record) {
foreach($this->listeners as $listener) {
$listener->onPreEvict($record);
}
}
/**
* onClose
* an event invoked after Doctrine_Connection is closed
*
* @param Doctrine_Connection $connection
* @return void
*/
public function onClose(Doctrine_Connection $connection) {
foreach($this->listeners as $listener) {
$listener->onClose($connection);
}
}
/**
* onClose
* an event invoked before Doctrine_Connection is closed
*
* @param Doctrine_Connection $connection
* @return void
*/
public function onPreClose(Doctrine_Connection $connection) {
foreach($this->listeners as $listener) {
$listener->onPreClose($connection);
}
}
/**
* onOpen
* an event invoked after Doctrine_Connection is opened
*
* @param Doctrine_Connection $connection
* @return void
*/
public function onOpen(Doctrine_Connection $connection) {
foreach($this->listeners as $listener) {
$listener->onOpen($connection);
}
}
/**
* onTransactionCommit
* an event invoked after a Doctrine_Connection transaction is committed
*
* @param Doctrine_Connection $connection
* @return void
*/
public function onTransactionCommit(Doctrine_Connection $connection) {
foreach($this->listeners as $listener) {
$listener->onTransactionCommit($connection);
}
}
/**
* onPreTransactionCommit
* an event invoked before a Doctrine_Connection transaction is committed
*
* @param Doctrine_Connection $connection
* @return void
*/
public function onPreTransactionCommit(Doctrine_Connection $connection) {
foreach($this->listeners as $listener) {
$listener->onPreTransactionCommit($connection);
}
}
/**
* onTransactionRollback
* an event invoked after a Doctrine_Connection transaction is being rolled back
*
* @param Doctrine_Connection $connection
* @return void
*/
public function onTransactionRollback(Doctrine_Connection $connection) {
foreach($this->listeners as $listener) {
$listener->onTransactionRollback($connection);
}
}
/**
* onPreTransactionRollback
* an event invoked before a Doctrine_Connection transaction is being rolled back
*
* @param Doctrine_Connection $connection
* @return void
*/
public function onPreTransactionRollback(Doctrine_Connection $connection) {
foreach($this->listeners as $listener) {
$listener->onPreTransactionRollback($connection);
}
}
/**
* onTransactionBegin
* an event invoked after a Doctrine_Connection transaction has been started
*
* @param Doctrine_Connection $connection
* @return void
*/
public function onTransactionBegin(Doctrine_Connection $connection) {
foreach($this->listeners as $listener) {
$listener->onTransactionBegin($connection);
}
}
/**
* onTransactionBegin
* an event invoked before a Doctrine_Connection transaction is being started
*
* @param Doctrine_Connection $connection
* @return void
*/
public function onPreTransactionBegin(Doctrine_Connection $connection) {
foreach($this->listeners as $listener) {
$listener->onPreTransactionBegin($connection);
}
}
/**
* onCollectionDelete
* an event invoked after a Doctrine_Collection is being deleted
*
* @param Doctrine_Collection $collection
* @return void
*/
public function onCollectionDelete(Doctrine_Collection $collection) {
foreach($this->listeners as $listener) {
$listener->onCollectionDelete($record);
}
}
/**
* onCollectionDelete
* an event invoked after a Doctrine_Collection is being deleted
*
* @param Doctrine_Collection $collection
* @return void
*/
public function onPreCollectionDelete(Doctrine_Collection $collection) {
foreach($this->listeners as $listener) {
$listener->onPreCollectionDelete($collection);
}
}
}