PHP Classes

File: test.php

Recommend this page to a friend!
  Classes of Kiril Savchev   PHP Event Aggregator   test.php   Download  
File: test.php
Role: Example script
Content type: text/plain
Description: Test examples
Class: PHP Event Aggregator
Manager and listener of registered events
Author: By
Last change:
Date: 9 years ago
Size: 821 bytes
 

Contents

Class file image Download
<?php

require_once 'EventAggregator.php';

/**
 * Use this class to attach methods to events
 *
 */
class TestClass {
    static function
test() { var_dump(__CLASS__); }
    static function
test2($a,$b,$c='a') {
       
var_dump($a,$b,$c);
        echo
$GLOBALS['Event']->getCurrentEvent();
    }
}

// Instantiate the event aggregator:
$Event = EventAggregator::getInstance();

// Attach some callbacks to custom event 'testEvent':
$Event->on('testEvent',array('TestClass','test'));
$Event->on('testEvent',array('TestClass','test2'),2);

// Call the event:
$Event->testEvent(__FILE__,__LINE__,true);

// These commented lines do the same as the above - fires the event 'testEvent' with params __FILE__, __LINE__ and true
// $Event->trigger('testEvent',array(__FILE__,__LINE__,true));
// $Event->fire('testEvent',__FILE__,__LINE__,true);

?>