1
0
mirror of synced 2025-02-20 14:13:15 +03:00

New component: Doctrine_EventListener_Chain

This commit is contained in:
doctrine 2006-07-04 23:05:21 +00:00
parent 5471e9e2ad
commit e905680f9b
3 changed files with 58 additions and 1 deletions

View File

@ -118,8 +118,12 @@ abstract class Doctrine_Configurable {
* @param Doctrine_EventListener $listener
* @return void
*/
final public function setEventListener(Doctrine_EventListener $listener) {
final public function setEventListener($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;
}
/**

View 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]);
}
}
}
?>

View File

@ -16,6 +16,7 @@ class Doctrine_DebugMessage {
}
}
class Doctrine_EventListener_Debugger extends Doctrine_EventListener {
const EVENT_LOAD = 1;
const EVENT_PRELOAD = 2;
const EVENT_SLEEP = 3;