예제 #1
0
 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);
 }
예제 #2
0
 public function onAction(Event $event)
 {
     $params = $event->getParameters();
     $params = implode(', ', $params);
     echo "exec: SampleListener::onAction({$params})";
 }
예제 #3
0
 public function onAfterLogin(Event $event)
 {
     $params = implode(', ', $event->getParameters());
     echo "executed Sample2Listener::onAfterLogin({$params})";
 }
예제 #4
0
function onAfterLogin(Event $event)
{
    $params = $event->getParameters();
    $params = implode(', ', $params);
    echo 'executed after login, with params: ' . $params;
}