compared with
Version 14 by Alvar Vilu
on Dec 23, 2009 03:15.

Key
This line was removed.
This word was removed. This word was added.
This line was added.

Changes (48)

View Page History

{code}

require_once 'Zend/Event/Dispatcher.php'; 'AVlib/Event/Dispatcher.php';

class example_event extends Zend_Event
{

const EXAMPLE = 'example_example';

public $example_var;

public function __construct ( $type, $bubbles = false, $cancelable = false, $example_var ) {


}

public function cloneEvent ( $eventPhase, $target, $currentTarget ) {
$evt = parent::cloneEvent ( $eventPhase, $target, $currentTarget );
}
}

class disp1 extends Zend_Event_Dispatcher
{

function __construct ( ) {

}
}

public function listener ( Zend_Event $event ) {

}
}

class disp2 extends Zend_Event_Dispatcher
{

public function __construct ( ) {
$evt = new example_event ( example_event::EXAMPLE, true, false, 'will be catched every time' );
}
}

$d = new disp1 ( );





{code}

||UC-01||

{code}



require_once 'AVlib/Event/Dispatcher.php';

class evt_custom_dispatcher implements Zend_Event_Dispatcher_Interface
{

/**
* @var Zend_Event_Dispatcher
*/
protected $dispatcher;

public function __construct ( ) {

$this->dispatcher = new Zend_Event_Dispatcher ( $this );

}

public function addEventListener ( $type, $listener, $useCapture = false, $priority = 0, $useWeakReference = false ) {

return $this->dispatcher->addEventListener ( $type, $listener, $useCapture, $priority, $useWeakReference );
}

public function removeEventListener ( $type, $listener, $useCapture = false ) {

return $this->dispatcher->removeEventListener ( $type, $listener, $useCapture );
}

public function removeEventListeners ( $type = null ) {

return $this->dispatcher->removeEventListeners ( $type );
}

public function dispatchEvent ( Zend_Event $event ) {

return $this->dispatcher->dispatchEvent ( $event );
}

public function hasEventListener ( $type ) {

return $this->dispatcher->hasEventListener ( $type );
}

public function willEventTrigger ( $type ) {

return $this->dispatcher->willEventTrigger ( $type );
}

}

{code}
{zone-data}

{code}


{code}



/**
* @see Zend_Event_Phase
*/
require_once 'Zend/Event/Phase.php'; 'AVlib/Event/Phase.php';

/**

/**
* Will event bullbles bubbles back to (main)
*
* @var bool

default:
require_once 'Zend/Event/Exception.php'; 'AVlib/Event/Exception.php';
throw new Zend_Event_Exception ( 'Event parameter not readable: ' . $name );
}
*/
public function __set ( $name, $value ) {
require_once 'Zend/Event/Exception.php'; 'AVlib/Event/Exception.php';
throw new Zend_Event_Exception ( 'Event parameter not writable: ' . $name );
}

}

{code}



{code}

/**
* @see Zend_Exception
*/
require_once 'Zend/Exception.php'; 'AVlib/Exception.php';

/**
class Zend_Event_Exception extends Zend_Exception
{}

{code}

{code}




/**
* @see Zend_Event_Dispatcher_Interface
*/
require_once 'Zend/Event/Dispatcher/Interface.php'; 'AVlib/Event/Dispatcher/Interface.php';

/**
* @see Zend_Event_Phase
*/
require_once 'Zend/Event/Phase.php'; 'AVlib/Event/Phase.php';

/**
* @see Zend_Event
*/
require_once 'Zend/Event.php'; 'AVlib/Event.php';

/**

/**
* A object that's used to dispatch events,
* can be $this on obj that interface Zend_Event_Dispatcher_Interface.
*
* @var Zend_Event_Dispatcher
*/
private $dispatchObj = null;

public function __construct ( $dispatchObj = null ) {

$this->dispatchObj = $dispatchObj;

}

final private function _getDispatchObj ( ) {

if ( null === $this->dispatchObj )
$this->dispatchObj = $this;

return $this->dispatchObj;
}

/**
* Add new event listener to spesific type.
* If use capture is enabled then event will flow from (main) to target
* The higher the priority number - event will sorted to first.
* If two or more same priority level events added then first one will be dispatched.
*
* @param string $type
* @param string|array $listener
final public function addEventListener ( $type, $listener, $useCapture = false, $priority = 0, $useWeakReference = false ) {

$objHash = spl_object_hash ( $this->_getDispatchObj ( ) );
$useCapture = ( bool ) $useCapture;
$priority = ( int ) $priority;
final public function removeEventListener ( $type, $listener, $useCapture = false ) {

$objHash = spl_object_hash ( $this->_getDispatchObj ( ) );
$useCapture = ( bool ) $useCapture;

final public function removeEventListeners ( $type = null ) {

$objHash = spl_object_hash ( $this->_getDispatchObj ( ) );

if ( null === $type ) {

//Put 'at target' phase to dispatchTree.
$objHash = spl_object_hash ( $this->_getDispatchObj ( ) );
if ( isset ( self::$_listeners[ $event->type ][ $objHash ][ false ] ) ) {

$dispatchTree[ ] = array (
$this->_getDispatchObj ( ),
Zend_Event_Phase::AT_TARGET,
self::$_listeners[ $event->type ][ $objHash ][ false ]
foreach ( debug_backtrace ( ) as $branch ) {

if ( ! isset ( $branch[ 'object' ] ) or ! ( $branch[ 'object' ] instanceof Zend_Event_Dispatcher_Interface ) )
break;

if ( $branch[ 'object' ] === $this or $branch[ 'object' ] === $this->_getDispatchObj ( ) )
continue;

foreach ( $dispatcher[ 2 ] as $listener ) {

$evt = $event->cloneEvent ( $dispatcher[ 1 ], $this->_getDispatchObj ( ), $dispatcher[ 0 ] );

if ( false === call_user_func ( $listener[ 1 ], $evt ) ) {
require_once 'Zend/Event/Dispatcher/Exception.php'; 'AVlib/Event/Dispatcher/Exception.php';
throw new Zend_Event_Dispatcher_Exception ( 'Call to event listener failed' );
}

} catch ( Exception $e ) {
require_once 'Zend/Event/Dispatcher/Exception.php'; 'AVlib/Event/Dispatcher/Exception.php';
throw new Zend_Event_Dispatcher_Exception ( 'Event dispatching failed', 0, $e );
}
final public function hasEventListener ( $type ) {

return isset ( self::$_listeners[ $type ][ spl_object_hash ( $this->_getDispatchObj ( ) ) ] );
}


}

{code}

{code}



/**
* @see Zend_Event_Exception
*/
require_once 'Zend/Event/Exception.php'; 'AVlib/Event/Exception.php';

/**
class Zend_Event_Dispatcher_Exception extends Zend_Event_Exception
{}

{code}

{code}



interface Zend_Event_Dispatcher_Interface
{

}

{code}

{code}



/**
* @author Alvar Vilu <alvar.vilu@msn.com>

}

{code}
{zone-data}