Commit e905680f authored by doctrine's avatar doctrine

New component: Doctrine_EventListener_Chain

parent 5471e9e2
...@@ -118,8 +118,12 @@ abstract class Doctrine_Configurable { ...@@ -118,8 +118,12 @@ abstract class Doctrine_Configurable {
* @param Doctrine_EventListener $listener * @param Doctrine_EventListener $listener
* @return void * @return void
*/ */
final public function setEventListener(Doctrine_EventListener $listener) { final public function setEventListener($listener) {
$i = Doctrine::ATTR_LISTENER; $i = Doctrine::ATTR_LISTENER;
if( ! ($listener instanceof Doctrine_EventListener) &&
! ($listener instanceof Doctrine_EventListener_Chain))
throw new Doctrine_Exception("EventListener must extend Doctrine_EventListener or Doctrine_EventListener_Chain");
$this->attributes[$i] = $listener; $this->attributes[$i] = $listener;
} }
/** /**
......
<?php
class Doctrine_EvenListener_Chain extends Doctrine_Access {
/**
* @var array $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;
}
/**
* this method should only be called internally by
* doctrine, since it doesn't do any method existence checking
*
* @param method $method
* @param array $args
*/
public function __call($method, $args) {
foreach($this->listeners as $listener) {
$listener->$method($args[0]);
}
}
}
?>
...@@ -16,6 +16,7 @@ class Doctrine_DebugMessage { ...@@ -16,6 +16,7 @@ class Doctrine_DebugMessage {
} }
} }
class Doctrine_EventListener_Debugger extends Doctrine_EventListener { class Doctrine_EventListener_Debugger extends Doctrine_EventListener {
const EVENT_LOAD = 1; const EVENT_LOAD = 1;
const EVENT_PRELOAD = 2; const EVENT_PRELOAD = 2;
const EVENT_SLEEP = 3; const EVENT_SLEEP = 3;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment