|
Revision 2337, 1.3 kB
(checked in by Shadowhand, 4 months ago)
|
Updated Calendar:
- Added Easter as a supported holiday
- Optimized Calendar_Event->notify() a bit
Also, minor tweaks to Event_Subject and Event_Observer
|
- Property svn:eol-style set to
LF
- Property copyright set to
Copyright (c) 2007-2008 Kohana Team
- Property svn:keywords set to
Id
|
| Line | |
|---|
| 1 |
<?php defined('SYSPATH') or die('No direct script access.'); |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
abstract class Event_Subject implements SplSubject { |
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
protected $listeners = array(); |
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
* Attach an observer to the object. |
|---|
| 19 |
* |
|---|
| 20 |
* @chainable |
|---|
| 21 |
* @param object Event_Observer |
|---|
| 22 |
* @return object |
|---|
| 23 |
*/ |
|---|
| 24 |
public function attach(SplObserver $obj) |
|---|
| 25 |
{ |
|---|
| 26 |
if ( ! ($obj instanceof Event_Observer)) |
|---|
| 27 |
throw new Kohana_Exception('eventable.invalid_observer', get_class($obj), get_class($this)); |
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
$this->listeners[spl_object_hash($obj)] = $obj; |
|---|
| 31 |
|
|---|
| 32 |
return $this; |
|---|
| 33 |
} |
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
* Detach an observer from the object. |
|---|
| 37 |
* |
|---|
| 38 |
* @chainable |
|---|
| 39 |
* @param object Event_Observer |
|---|
| 40 |
* @return object |
|---|
| 41 |
*/ |
|---|
| 42 |
public function detach(SplObserver $obj) |
|---|
| 43 |
{ |
|---|
| 44 |
|
|---|
| 45 |
unset($this->listeners[spl_object_hash($obj)]); |
|---|
| 46 |
|
|---|
| 47 |
return $this; |
|---|
| 48 |
} |
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
* Notify all attached observers of a new message. |
|---|
| 52 |
* |
|---|
| 53 |
* @chainable |
|---|
| 54 |
* @param mixed message string, object, or array |
|---|
| 55 |
* @return object |
|---|
| 56 |
*/ |
|---|
| 57 |
public function notify($message) |
|---|
| 58 |
{ |
|---|
| 59 |
foreach ($this->listeners as $obj) |
|---|
| 60 |
{ |
|---|
| 61 |
$obj->notify($message); |
|---|
| 62 |
} |
|---|
| 63 |
|
|---|
| 64 |
return $this; |
|---|
| 65 |
} |
|---|
| 66 |
|
|---|
| 67 |
} |
|---|