public function testCompleteCallingClassFunc() { $dispatcher = new EventDispatcher(); $dispatcher->addListener('system.before_login', 'onBeforeLogin'); $dispatcher->addListener('system.before_login', array(new SampleListener(), 'onAction')); $dispatcher->addListener('system.after_login', 'onAfterLogin'); $event = new Event(); $event->setParameters(array('param1' => 'value1', 'param2' => 'value2')); // result of onBeforeLogin callback func. $expected = 'executed before login'; // result of SampleListener::onAction() callback func. $expected .= 'exec: SampleListener::onAction(value1, value2)'; ob_start(); $dispatcher->dispatch('system.before_login', $event); $obtained1 = ob_get_contents(); ob_end_clean(); ob_start(); $dispatcher->dispatch('system.after_login', new Event(array(1, 2, 3))); $obtained2 = ob_get_contents(); ob_end_clean(); $this->assertEquals($expected, $obtained1); $this->assertEquals('executed after login, with params: 1, 2, 3', $obtained2); }
public function onAction(Event $event) { $params = $event->getParameters(); $params = implode(', ', $params); echo "exec: SampleListener::onAction({$params})"; }
public function onAfterLogin(Event $event) { $params = implode(', ', $event->getParameters()); echo "executed Sample2Listener::onAfterLogin({$params})"; }
function onAfterLogin(Event $event) { $params = $event->getParameters(); $params = implode(', ', $params); echo 'executed after login, with params: ' . $params; }