What happens now if two events return two different sets a data for an event?
Lets say cms:onGetCustomerGroupId returns array(1) and another function returns array(2). Which value is it? According to the events it would be $groups_id = array( array(1), array(2) ); Should you merge the arrays in the events?
Heres the untested priority add on:
class Phpr_Events extends Phpr_Extension
{
public $_eventList = array();
public function addEvent($Name)
{
$args = func_get_args();
$handler = extractFunctionArg($args, 1);
$priority = (int)extractFunctionArg($args, 2);
if( $priority == 0 )
$priority = 100;
if (!isset($this->_eventList[$Name]))
$this->_eventList[$Name] = array();
$this->_eventList[$Name][] = array('handler'=>$handler, 'priority'=>$priority);
}
public function fireEvent($Name)
{
if (!isset($this->_eventList[$Name]))
return array();
$Params = func_get_args();
// array_shift($Params);
array_shift($Params);
// array_unshift($Params, $baseObject);
$result = array();
//sort the event list by priority
uasort($this->_eventList[$Name], array($this, 'cmp'));
foreach ($this->_eventList[$Name] as $event)
$result[] = callFunction($event['handler'], $Params);
return $result;
}
private function cmp($a, $B)
{
if ($a['priority'] == $b['priority']) {
return 0;
}
return ($a['priority'] < $b['priority']) ? -1 : 1;
}

Help
This topic is locked














