blob: 086c8a23117b8f29ec743421f4e3d35ba7575b39 (
plain)
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
|
<?php defined('SYSPATH') OR die('No direct access allowed.');
/**
* Kohana event observer. Uses the SPL observer pattern.
*
* $Id: Event_Observer.php 3769 2008-12-15 00:48:56Z zombor $
*
* @package Core
* @author Kohana Team
* @copyright (c) 2007-2008 Kohana Team
* @license http://kohanaphp.com/license.html
*/
abstract class Event_Observer implements SplObserver {
// Calling object
protected $caller;
/**
* Initializes a new observer and attaches the subject as the caller.
*
* @param object Event_Subject
* @return void
*/
public function __construct(SplSubject $caller)
{
// Update the caller
$this->update($caller);
}
/**
* Updates the observer subject with a new caller.
*
* @chainable
* @param object Event_Subject
* @return object
*/
public function update(SplSubject $caller)
{
if ( ! ($caller instanceof Event_Subject))
throw new Kohana_Exception('event.invalid_subject', get_class($caller), get_class($this));
// Update the caller
$this->caller = $caller;
return $this;
}
/**
* Detaches this observer from the subject.
*
* @chainable
* @return object
*/
public function remove()
{
// Detach this observer from the caller
$this->caller->detach($this);
return $this;
}
/**
* Notify the observer of a new message. This function must be defined in
* all observers and must take exactly one parameter of any type.
*
* @param mixed message string, object, or array
* @return void
*/
abstract public function notify($message);
} // End Event Observer
|