PHP Classes

Universal PHP Event System: Manage events with the Observer/Publisher patterns

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 279 All time: 7,628 This week: 49Up
Version License PHP version Categories
falcraft-event 1.0MIT/X Consortium ...5.3PHP 5, Language, Design Patterns
Description 

Author

This package can manage events with the Observer and Publisher design patterns.

It provides generic base classes that should be extended to create objects that observe and process events of interest, as well objects that define events to be processed by the observer classes.

Events can be processed by multiple observers and observers can listed to different types of events.

Picture of Asher Wolfstein
  Performance   Level  
Innovation award
Innovation award
Nominee: 5x

 

Example

<?php

require_once( __DIR__ . '/../../Event/Actor.php' );
require_once(
__DIR__ . '/../../Event/Filter.php' );
require_once(
__DIR__ . '/../../Event/Handler.php' );
require_once(
__DIR__ . '/../../Event/GenericEvent.php' );
require_once(
__DIR__ . '/../../Patterns/Publisher.php' );

use
Falcraft\Event;
use
Falcraft\Patterns;

echo
"Falcraft\\Event\\Actor.php Test\n";
echo
"-----------------------------\n\n";

echo
"Basic Instantiation -- \n\n";

$success = true;

$handler = $filter = $event1 = $event2 = $publisher = $actor = null;

try {
    echo
" Instantiate Handler With Closure -> ";
   
$handler = new Event\Handler(
       
null,
        function(
$e){echo "Inside Closure";},
       
null,
       
Event\Handler::DEFAULT_PRIORITY,
        array(
'strict' => true)
    );
   
    echo
$handler ? "Success!\n" : "Failure...\n";
   
    echo
" Instantiate Filter (filter => tag1) -> ";
   
$filter = new Event\Filter();
   
$filter->setState(array('tags' => array('tag1',),));
   
    echo
$filter ? "Success!\n" : "Failure...\n";
   
    echo
" Instantiate Generic Events (Event1 => tag1) -> ";
   
$event1 = new Event\GenericEvent(
       
null,
       
null,
       
null,
       
null,
       
null,
        array(
'tag1')
    );
   
   
$event2 = new Event\GenericEvent(null, null, null, null);
   
    echo (
$event1 && $event2) ? "Success!\n" : "Failure...\n";
   
    echo
" Instantiate Publisher -> ";
   
$publisher = new Patterns\Publisher();
   
    echo
$publisher ? "Success!\n" : "Failure...\n";
   
    echo
" Instantiate Actor ( filter, handler, publisher ) -> ";
   
$actor = new Event\Actor($filter, $handler, $publisher);
   
    echo
$actor ? "Success!\n" : "Failure...\n";
   
} catch (\
Exception $e) {
   
$success = false;
}

if (!
$success) {
    echo
"EXCEPTION RAISED\n";
}

echo
"\nBasic Operations -- \n\n";

$success = true;

try {
    echo
" Fire Event1 -> ";
   
$publisher->setState($event1);
} catch (\
Exception $e) {
   
$success = false;
}

if (!
$success) {
    echo
"EXCEPTION RAISED\n";
}

$success = true;

try {
    echo
"\n Fire Event2 -> ";
   
$publisher->setState($event2);
} catch (\
Exception $e) {
   
$success = false;
}

if (!
$success) {
    echo
"EXCEPTION RAISED\n";
}

echo
"\n";


  Files folder image Files (28)  
File Role Description
Files folder imageFalcraft (1 file, 3 directories)

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
Downloadfalcraft-event-2015-10-19.zip 44KB
Downloadfalcraft-event-2015-10-19.tar.gz 25KB
Install with ComposerInstall with Composer
Needed packages  
Class DownloadWhy it is needed Dependency
PHP Configuration Trait Download .zip .tar.gz For configuring the objects Required
Abstract Data Types Download .zip .tar.gz Makes up part of objects (like Map) Required
 Version Control Unique User Downloads Download Rankings  
 0%
Total:279
This week:0
All time:7,628
This week:49Up