# Coverage for Doctrine_EventListener_Chain

Back to coverage report

1 | <?php
2 | /*
3 | * $Id: Chain.php 2963 2007-10-21 06:23:59Z Jonathan.Wage $
4 | *
5 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
6 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
7 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
8 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
9 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
10 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
11 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
12 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
13 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
14 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
15 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
16 | *
17 | * This software consists of voluntary contributions made by many individuals
18 | * and is licensed under the LGPL. For more information, see
19 | * <http://www.phpdoctrine.org>.
20 | */
21 | Doctrine::autoload('Doctrine_Access');
22 |
23 | /**
24 | * Doctrine_EventListener_Chain
25 | * this class represents a chain of different listeners,
26 | * useful for having multiple listeners listening the events at the same time
27 | *
28 | * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
29 | * @package Doctrine
30 | * @subpackage EventListener
31 | * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
32 | * @link www.phpdoctrine.org
33 | * @since 1.0
34 | * @version $Revision: 2963 $
35 | */
36 | class Doctrine_EventListener_Chain extends Doctrine_Access implements Doctrine_EventListener_Interface
37 | {
38 | /**
39 | * @var array $listeners an array containing all listeners
40 | */
41 | protected $_listeners = array();
42 |
43 | /**
44 | * add
45 | * adds a listener to the chain of listeners
46 | *
47 | * @param object $listener
48 | * @param string $name
49 | * @return void
50 | */
51 | public function add($listener, $name = null)
52 | {
53 | if ( ! ($listener instanceof Doctrine_EventListener_Interface) &&
54 | ! ($listener instanceof Doctrine_Overloadable)) {
55 |
56 | throw new Doctrine_EventListener_Exception("Couldn't add eventlistener. EventListeners should implement either Doctrine_EventListener_Interface or Doctrine_Overloadable");
57 | }
58 | if ($name === null) {
59 | $this->_listeners[] = $listener;
60 | } else {
61 | $this->_listeners[$name] = $listener;
62 | }
63 | }
64 |
65 | /**
66 | * returns a Doctrine_EventListener on success
67 | * and null on failure
68 | *
69 | * @param mixed $key
70 | * @return mixed
71 | */
72 | public function get($key)
73 | {
74 | if ( ! isset($this->_listeners[$key])) {
75 | return null;
76 | }
77 | return $this->_listeners[$key];
78 | }
79 |
80 | /**
81 | * set
82 | *
83 | * @param mixed $key
84 | * @param Doctrine_EventListener $listener
85 | * @return void
86 | */
87 | public function set($key, Doctrine_EventListener $listener)
88 | {
89 | $this->_listeners[$key] = $listener;
90 | }
91 |
92 | /**
93 | * onLoad
94 | * an event invoked when Doctrine_Record is being loaded from database
95 | *
96 | * @param Doctrine_Record $record
97 | * @return void
98 | */
99 | public function onLoad(Doctrine_Record $record)
100 | {
101 | foreach ($this->_listeners as $listener) {
102 | $listener->onLoad($record);
103 | }
104 | }
105 |
106 | /**
107 | * onPreLoad
108 | * an event invoked when Doctrine_Record is being loaded
109 | * from database but not yet initialized
110 | *
111 | * @param Doctrine_Record $record
112 | * @return void
113 | */
114 | public function onPreLoad(Doctrine_Record $record)
115 | {
116 | foreach ($this->_listeners as $listener) {
117 | $listener->onPreLoad($record);
118 | }
119 | }
120 |
121 | /**
122 | * onSleep
123 | * an event invoked when Doctrine_Record is serialized
124 | *
125 | * @param Doctrine_Record $record
126 | * @return void
127 | */
128 | public function onSleep(Doctrine_Record $record)
129 | {
130 | foreach ($this->_listeners as $listener) {
131 | $listener->onSleep($record);
132 | }
133 | }
134 |
135 | /**
136 | * onWakeUp
137 | * an event invoked when Doctrine_Record is unserialized
138 | *
139 | * @param Doctrine_Record $record
140 | * @return void
141 | */
142 | public function onWakeUp(Doctrine_Record $record)
143 | {
144 | foreach ($this->_listeners as $listener) {
145 | $listener->onWakeUp($record);
146 | }
147 | }
148 |
149 | /**
150 | * postClose
151 | * an event invoked after Doctrine_Connection is closed
152 | *
153 | * @param Doctrine_Event $event
154 | * @return void
155 | */
156 | public function postClose(Doctrine_Event $event)
157 | {
158 | foreach ($this->_listeners as $listener) {
159 | $listener->postClose($event);
160 | }
161 | }
162 |
163 | /**
164 | * preClose
165 | * an event invoked before Doctrine_Connection is closed
166 | *
167 | * @param Doctrine_Event $event
168 | * @return void
169 | */
170 | public function preClose(Doctrine_Event $event)
171 | {
172 | foreach ($this->_listeners as $listener) {
173 | $listener->preClose($event);
174 | }
175 | }
176 |
177 | /**
178 | * onOpen
179 | * an event invoked after Doctrine_Connection is opened
180 | *
181 | * @param Doctrine_Connection $connection
182 | * @return void
183 | */
184 | public function onOpen(Doctrine_Connection $connection)
185 | {
186 | foreach ($this->_listeners as $listener) {
187 | $listener->onOpen($connection);
188 | }
189 | }
190 |
191 | /**
192 | * onTransactionCommit
193 | * an event invoked after a Doctrine_Connection transaction is committed
194 | *
195 | * @param Doctrine_Event $event
196 | * @return void
197 | */
198 | public function postTransactionCommit(Doctrine_Event $event)
199 | {
200 | foreach ($this->_listeners as $listener) {
201 | $listener->postTransactionCommit($event);
202 | }
203 | }
204 |
205 | /**
206 | * onPreTransactionCommit
207 | * an event invoked before a Doctrine_Connection transaction is committed
208 | *
209 | * @param Doctrine_Event $event
210 | * @return void
211 | */
212 | public function preTransactionCommit(Doctrine_Event $event)
213 | {
214 | foreach ($this->_listeners as $listener) {
215 | $listener->preTransactionCommit($event);
216 | }
217 | }
218 |
219 | /**
220 | * onTransactionRollback
221 | * an event invoked after a Doctrine_Connection transaction is being rolled back
222 | *
223 | * @param Doctrine_Event $event
224 | * @return void
225 | */
226 | public function postTransactionRollback(Doctrine_Event $event)
227 | {
228 | foreach ($this->_listeners as $listener) {
229 | $listener->postTransactionRollback($event);
230 | }
231 | }
232 |
233 | /**
234 | * onPreTransactionRollback
235 | * an event invoked before a Doctrine_Connection transaction is being rolled back
236 | *
237 | * @param Doctrine_Event $event
238 | * @return void
239 | */
240 | public function preTransactionRollback(Doctrine_Event $event)
241 | {
242 | foreach ($this->_listeners as $listener) {
243 | $listener->preTransactionRollback($event);
244 | }
245 | }
246 |
247 | /**
248 | * onTransactionBegin
249 | * an event invoked after a Doctrine_Connection transaction has been started
250 | *
251 | * @param Doctrine_Event $event
252 | * @return void
253 | */
254 | public function postTransactionBegin(Doctrine_Event $event)
255 | {
256 | foreach ($this->_listeners as $listener) {
257 | $listener->postTransactionBegin($event);
258 | }
259 | }
260 |
261 | /**
262 | * onTransactionBegin
263 | * an event invoked before a Doctrine_Connection transaction is being started
264 | *
265 | * @param Doctrine_Event $event
266 | * @return void
267 | */
268 | public function preTransactionBegin(Doctrine_Event $event)
269 | {
270 | foreach ($this->_listeners as $listener) {
271 | $listener->preTransactionBegin($event);
272 | }
273 | }
274 |
275 | /**
276 | * onCollectionDelete
277 | * an event invoked after a Doctrine_Collection is being deleted
278 | *
279 | * @param Doctrine_Collection $collection
280 | * @return void
281 | */
282 | public function onCollectionDelete(Doctrine_Collection $collection)
283 | {
284 | foreach ($this->_listeners as $listener) {
285 | $listener->onCollectionDelete($collection);
286 | }
287 | }
288 |
289 | /**
290 | * onCollectionDelete
291 | * an event invoked after a Doctrine_Collection is being deleted
292 | *
293 | * @param Doctrine_Collection $collection
294 | * @return void
295 | */
296 | public function onPreCollectionDelete(Doctrine_Collection $collection)
297 | {
298 | foreach ($this->_listeners as $listener) {
299 | $listener->onPreCollectionDelete($collection);
300 | }
301 | }
302 | public function postConnect(Doctrine_Event $event)
303 | {
304 | foreach ($this->_listeners as $listener) {
305 | $listener->postConnect($event);
306 | }
307 | }
308 | public function preConnect(Doctrine_Event $event)
309 | {
310 | foreach ($this->_listeners as $listener) {
311 | $listener->preConnect($event);
312 | }
313 | }
314 | public function preQuery(Doctrine_Event $event)
315 | {
316 | foreach ($this->_listeners as $listener) {
317 | $listener->preQuery($event);
318 | }
319 | }
320 | public function postQuery(Doctrine_Event $event)
321 | {
322 | foreach ($this->_listeners as $listener) {
323 | $listener->postQuery($event);
324 | }
325 | }
326 |
327 | public function prePrepare(Doctrine_Event $event)
328 | {
329 | foreach ($this->_listeners as $listener) {
330 | $listener->prePrepare($event);
331 | }
332 | }
333 | public function postPrepare(Doctrine_Event $event)
334 | {
335 | foreach ($this->_listeners as $listener) {
336 | $listener->postPrepare($event);
337 | }
338 | }
339 |
340 | public function preExec(Doctrine_Event $event)
341 | {
342 | foreach ($this->_listeners as $listener) {
343 | $listener->preExec($event);
344 | }
345 | }
346 | public function postExec(Doctrine_Event $event)
347 | {
348 | foreach ($this->_listeners as $listener) {
349 | $listener->postExec($event);
350 | }
351 | }
352 |
353 | public function preError(Doctrine_Event $event)
354 | {
355 | foreach ($this->_listeners as $listener) {
356 | $listener->preError($event);
357 | }
358 | }
359 | public function postError(Doctrine_Event $event)
360 | {
361 | foreach ($this->_listeners as $listener) {
362 | $listener->postError($event);
363 | }
364 | }
365 |
366 | public function preFetch(Doctrine_Event $event)
367 | {
368 | foreach ($this->_listeners as $listener) {
369 | $listener->preFetch($event);
370 | }
371 | }
372 | public function postFetch(Doctrine_Event $event)
373 | {
374 | foreach ($this->_listeners as $listener) {
375 | $listener->postFetch($event);
376 | }
377 | }
378 |
379 | public function preFetchAll(Doctrine_Event $event)
380 | {
381 | foreach ($this->_listeners as $listener) {
382 | $listener->preFetchAll($event);
383 | }
384 | }
385 |
386 | public function postFetchAll(Doctrine_Event $event)
387 | {
388 | foreach ($this->_listeners as $listener) {
389 | $listener->postFetchAll($event);
390 | }
391 | }
392 |
393 | public function preStmtExecute(Doctrine_Event $event)
394 | {
395 | foreach ($this->_listeners as $listener) {
396 | $listener->preStmtExecute($event);
397 | }
398 | }
399 |
400 | public function postStmtExecute(Doctrine_Event $event)
401 | {
402 | foreach ($this->_listeners as $listener) {
403 | $listener->postStmtExecute($event);
404 | }
405 | }
406 | }