PHP Classes

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

Recommend this page to a friend!
  Info   View files Example   View files View files (28)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 278 This week: 1All time: 7,633 This week: 560Up
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  
Name: Asher Wolfstein <contact>
Classes: 15 packages by
Country: United States United States
Age: 40
All time rank: 1122164 in United States United States
Week rank: 51 Up6 in United States United States Up
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  
File Role Description
Files folder imageFalcraft (1 file, 3 directories)

  Files folder image Files  /  Falcraft  
File Role Description
Files folder imageEvent (8 files, 2 directories)
Files folder imageexamples (1 directory)
Files folder imagePatterns (2 files, 1 directory)
  Accessible without login Plain text file falcraftLoad.php Aux. Script Loader

  Files folder image Files  /  Falcraft  /  Event  
File Role Description
Files folder imageException (2 files)
Files folder imageResource (4 files)
  Plain text file Actor.php Class Bind event to execution
  Plain text file Aggregator.php Class Aggregate Publishers (Observers)
  Plain text file Conduit.php Class Multiple Publishers and Observers
  Plain text file Filter.php Class An event predicate (filter)
  Plain text file GenericEvent.php Class Generic (Suggested) Event Object
  Plain text file Handler.php Class Event Handler
  Plain text file HandlerPriorityQueue.php Class A Priority Queue of Observers
  Plain text file Tracker.php Class Event Manager Class

  Files folder image Files  /  Falcraft  /  Event  /  Exception  
File Role Description
  Plain text file ExceptionInterface.php Class Local Exception Interface
  Plain text file InvalidArgumentException.php Class Local Invalid Argument Exception

  Files folder image Files  /  Falcraft  /  Event  /  Resource  
File Role Description
  Plain text file AbstractEvent.php Class Basic generic suggested event
  Plain text file AwareInterface.php Class Interface for event aware objects
  Plain text file FilterInterface.php Class An event filter (predicate)
  Plain text file TrackerInterface.php Class The interface for an event manager

  Files folder image Files  /  Falcraft  /  examples  
File Role Description
Files folder imageEvent (8 files)

  Files folder image Files  /  Falcraft  /  examples  /  Event  
File Role Description
  Accessible without login Plain text file Actor.php Example Event Actor (Binder) Example
  Accessible without login Plain text file Aggregator.php Example Event Aggregator Example
  Accessible without login Plain text file Conduit.php Example Event Conduit Example
  Accessible without login Plain text file Filter.php Example Event Filter Example
  Accessible without login Plain text file GenericEvent.php Example Generic Event Example
  Accessible without login Plain text file Handler.php Example Handler Example
  Accessible without login Plain text file HandlerPriorityQueue.php Example Handler Priority Queue Example
  Accessible without login Plain text file Tracker.php Example Tracker Example

  Files folder image Files  /  Falcraft  /  Patterns  
File Role Description
Files folder imageResource (3 files)
  Plain text file Observer.php Class Observer Pattern Class
  Plain text file Publisher.php Class Publisher Pattern Class

  Files folder image Files  /  Falcraft  /  Patterns  /  Resource  
File Role Description
  Plain text file ObserverInterface.php Class Observer Pattern Interface
  Plain text file PublisherInterface.php Class Publisher Interface
  Plain text file StateInterface.php Class Object State Representation

Downloadfalcraft-event-2015-10-19.zip 44KB
Downloadfalcraft-event-2015-10-19.tar.gz
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:278
This week:1
All time:7,633
This week:560Up