Re: Issues with Event_Dispatcher

From: Date: Wed, 13 Apr 2005 04:43:50 +0000
Subject: Re: Issues with Event_Dispatcher
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-18715@lists.php.net to get a copy of this message
On 13/04/2005, at 2:25 PM, Dan Rossi wrote:
Ok first things first the example on the pear site is wrong, its referencing a getUserName method which doesnt exist :)
Ok i worked out your post dispatcher was sending $this->_user which is NULL where it should be $this ?? :) Here is my code , I found an issue even seperating each event into its own class even when adding an observer to onLogout its executing the onLogin method of the class until i set an onLogout to the observer, it turned off once i setup a filter to onLogin, but it means i still have to have a seperate class foreach event right ? <? require_once 'Event/Dispatcher.php'; class Auth { var $_dispatcher = null; var $_user; function Auth(&$dispatcher) { $this->_dispatcher = &$dispatcher; } function login($username, $password) { //$this->_dispatcher->post($this, 'onLogin'); $this->_dispatcher->post($this, 'onLogout'); } } function logAuth(&$notification) { $user = &$notification->getNotificationObject(); //$username = $user->getUsername(); error_log($username logged in., 3, '/tmp/auth.log'); } class Login { function onLogin($notification) { $user = &$notification->getNotificationObject(); //Var_Dump($user); echo login; } function onLogout($notification) { $user = &$notification->getNotificationObject(); //Var_Dump($user); echo logout; } } class Logout { function onLogout($notification) { $user = &$notification->getNotificationObject(); //Var_Dump($user); echo logout; } } $dispatcher = &Event_Dispatcher::getInstance(); // catch all onLogin events to write a logfile ///$dispatcher->addObserver('logAuth', 'onLogin'); is on, global filter $dispatcher->addObserver(array('Login','onLogin')); turns off with filter $dispatcher->addObserver(array('Login','onLogin'),'onLogin'); //$dispatcher->addObserver(array('Logout','onLogout')); //$dispatcher->addObserver(array('Login','onLogout')); $auth = &new Auth($dispatcher); // simulate login $auth->login($_GET['user'], $_GET['pass']);

« previous php.pear.general (#18715) next »