New component: Doctrine_EventListener_Chain
This commit is contained in:
parent
5471e9e2ad
commit
e905680f9b
@ -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;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
52
Doctrine/EventListener/Chain.php
Normal file
52
Doctrine/EventListener/Chain.php
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
<?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 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
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;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user