Event_Dispatcher::setNotificationClass PHP Method

setNotificationClass() public method

You may call this method on an object to change it for a single dispatcher or statically, to set the default for all dispatchers that will be created.
public setNotificationClass ( $class ) : boolean
return boolean
    public function setNotificationClass($class)
    {
        if (isset($this) && is_a($this, 'Event_Dispatcher')) {
            $this->_notificationClass = $class;
            return true;
        }
        $GLOBALS['_Event_Dispatcher']['NotificationClass'] = $class;
        return true;
    }

Usage Example

Esempio n. 1
0
        $this->_dispatcher->post($this, 'onFoo', 'Some Info...');
    }
}
function receiver(&$notification)
{
    echo 'received notification: ';
    echo get_class($notification);
    echo '<br />';
}
/**
 * custom notification class
 *
 * @package    Event_Dispatcher
 * @subpackage Examples
 * @author     Stephan Schmidt <*****@*****.**>
 */
class MyNotification extends Event_Notification
{
}
$dispatcher =& Event_Dispatcher::getInstance();
$dispatcher->setNotificationClass('MyNotification');
$sender =& new sender($dispatcher);
$dispatcher->addObserver('receiver');
echo 'sender->foo()<br />';
$sender->foo();
Event_Dispatcher::setNotificationClass('MyNotification');
$dispatcher2 =& Event_Dispatcher::getInstance();
$sender2 =& new sender($dispatcher2);
$dispatcher2->addObserver('receiver');
echo '<br />sender2->foo()<br />';
$sender2->foo();