PHP Classes

Event Emitter: Register handlers and dispatch named events

Recommend this page to a friend!
  Info   View files Example   View files View files (2)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 66 This week: 1All time: 10,348 This week: 78Up
Version License PHP version Categories
event-state 1.0Public Domain5PHP 5, Language
Description 

Author

This class can register handlers and dispatch named events.

It can register handlers objects and functions that will be called when a given event is triggered.

The class can also dispatch a given named event by calling all the functions of handler objects that were registered for that event.

This class is a conversion of npm event-state module to PHP.

Picture of Till Wehowski
  Performance   Level  
Name: Till Wehowski <contact>
Classes: 30 packages by
Country: Germany Germany
Age: 45
All time rank: 107269 in Germany Germany
Week rank: 45 Up2 in Germany Germany Up
Innovation award
Innovation award
Nominee: 12x

Example

<?php
namespace webfan\InstallShield\apc;



class
Test
{
   public function
run(){
       echo
'test'.PHP_EOL;
       
       \
frdl\webfan\App::God(false)->apc()
          ->
on('test', 'hello', $this)
       
          ->
trigger('test')
        ;
       
       
   
       
       
/**
        * $fo = new \O;
       $fo->cancel = $clear;
       $fo->add = $addState;
       $fo->events = $eventArray;
       $fo->status = $eventData;
       $fo->stateReady = $stateReady;
       $fo->stateGet = $stateGet;
        */
       
       
$test_state = \frdl\webfan\App::God(false)->apc()
            ->
              
required(array('ready', 'test-event-1', 'ontest', 'foo', 'bar'), array($this, 'fin1'), false)
              
        ;
       
       
// print_r($test_state);
       
    // echo '$test_state->stateReady("foo") expects to be false and is: '.$test_state->stateReady("foo").PHP_EOL;
       
echo 'trigger foo'.PHP_EOL;
// echo '$test_state->stateReady("foo") expects to be false and is: '.$test_state->stateReady("foo").PHP_EOL;
        
\frdl\webfan\App::God(false)->apc()
          ->
on('foo', 'hello', $this)
        
           ->
trigger('foo', array(1,2,3))
          
                      ->
trigger('ready', array(1,2,3))
                                 ->
trigger('test-event-1', array(1,2,3))
                                            ->
trigger('ontest', array(1,2,3))
                                                       ->
trigger('foo', array(1,2,3))
                                                                  ->
trigger('bar', array(1,2,3))
        ;
       
/**
        * should print:
        * test hello world trigger foo hello world hello world fin1 final state 1 reached
        */
       
        // echo '$test_state->stateReady("foo") expects to be false and is: '.$test_state->stateReady("foo").PHP_EOL;
       
   
}
   

    public function
hello(){
        echo
'hello world'.PHP_EOL;
// echo $_SERVER['DOCUMENT_ROOT'].PHP_EOL;
   
}
       

    public function
fin1(){
        echo
'fin1 final state 1 reached'.PHP_EOL;
    }

      
}


  Files folder image Files  
File Role Description
Accessible without login Plain text file EventEmitter Class class file
Accessible without login Plain text file Test.php Example Example

Downloadevent-state-2017-03-23.zip 2KB
Downloadevent-state-2017-03-23.tar.gz 2KB
Install with ComposerInstall with Composer
Needed packages  
Class DownloadWhy it is needed Dependency
$Event.$Iterator Download .zip .tar.gz Base class Required
 Version Control Unique User Downloads Download Rankings  
 0%
Total:66
This week:1
All time:10,348
This week:78Up