PHP Classes

PHP Publish Subscribe: Register and call handlers of events by name

Recommend this page to a friend!
  Info   View files Example   View files View files (20)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 42 All time: 10,674 This week: 190Up
Version License PHP version Categories
publishsubscribe 1.1.0Artistic License5PHP 5, Language
Description 

Author

This package can register and call handlers of events by name.

It can register callback functions that will be called when an event with a given name happens.

The package can also process events that are triggered and call all functions that were registered to handled the called event.

Besides the PHP version it also provides implementations of this publish and subscribe solution in JavaScript and Python.

Picture of Nikos M.
Name: Nikos M. is available for providing paid consulting. Contact Nikos M. .
Classes: 17 packages by
Country: Greece Greece
Age: 47
All time rank: 8699 in Greece Greece
Week rank: 26 Up1 in Greece Greece Up
Innovation award
Innovation award
Nominee: 7x

Winner: 2x

Example

<?php
require('../src/php/PublishSubscribe.php');

echo(
'PublishSubscribe.VERSION = ' . PublishSubscribe::VERSION . PHP_EOL);

function
_log(&$evt)
{
    echo(
print_r(array('topic'=>$evt->topic, 'originalTopic'=>$evt->originalTopic, 'tags'=>$evt->tags, 'namespaces'=>$evt->namespaces, 'timestamp'=>$evt->timestamp), true). PHP_EOL);
    echo(
print_r($evt->data, true). PHP_EOL);
}

function
handler1($evt)
{
    echo(
'Handler1' . PHP_EOL);
   
_log($evt);
   
$evt->next();
   
// event abort
    //$evt->abort( );
    // stop bubble propagation
    //$evt->propagate( false );
    // stop propagation on same event
    //$evt->stop( );
    //return false;
}
function
handler2($evt)
{
    echo(
'Handler2' . PHP_EOL);
   
_log($evt);
   
$evt->next();
}
function
handler3($evt)
{
    echo(
'Handler3' . PHP_EOL);
   
_log($evt);
   
$evt->next();
}
function
handler4($evt)
{
    echo(
'Handler4' . PHP_EOL);
   
_log($evt);
   
$evt->next();
}

$pb = new PublishSubscribe( );
$pb
   
->on('Topic1/SubTopic11#Tag1#Tag2', 'handler1')
    ->
on1('Topic1/SubTopic11#Tag1#Tag2@NS1', 'handler2')
    ->
on('Topic1/SubTopic11#Tag1#Tag2@NS1@NS2', 'handler3')
    ->
off('@NS1@NS2')
    ->
pipeline('Topic1/SubTopic11#Tag2#Tag1', array('key1'=> 'value1'))
    ->
pipeline('Topic1/SubTopic11#Tag2#Tag1@NS1', array('key1'=> 'value1'))
;


  Files folder image Files  
File Role Description
Files folder imagesrc (6 directories)
Files folder imagetest (10 files)
Accessible without login Image file publishsubscribe.jpg Icon Icon image
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  src  
File Role Description
Files folder imageactionscript (1 file)
Files folder imagec (1 file)
Files folder imagejava (1 file)
Files folder imagejs (2 files)
Files folder imagephp (1 file)
Files folder imagepython (2 files)

  Files folder image Files  /  src  /  actionscript  
File Role Description
  Accessible without login Plain text file todo.txt Doc. Documentation

  Files folder image Files  /  src  /  c  
File Role Description
  Accessible without login Plain text file todo.txt Doc. Documentation

  Files folder image Files  /  src  /  java  
File Role Description
  Accessible without login Plain text file todo.txt Doc. Documentation

  Files folder image Files  /  src  /  js  
File Role Description
  Accessible without login Plain text file PublishSubscribe.js Data Auxiliary data
  Accessible without login Plain text file PublishSubscribe.min.js Data Auxiliary data

  Files folder image Files  /  src  /  php  
File Role Description
  Plain text file PublishSubscribe.php Class Class source

  Files folder image Files  /  src  /  python  
File Role Description
  Accessible without login Plain text file PublishSubscribe.py Data Auxiliary data
  Accessible without login Plain text file __init__.py Data Auxiliary data

  Files folder image Files  /  test  
File Role Description
  Accessible without login Plain text file out-js Data Auxiliary data
  Accessible without login Plain text file out-php Data Auxiliary data
  Accessible without login Plain text file out-py Data Auxiliary data
  Accessible without login Plain text file test.js Data Auxiliary data
  Accessible without login Plain text file test.php Example Example script
  Accessible without login Plain text file test.py Data Auxiliary data
  Accessible without login Plain text file test_filter.js Data Auxiliary data
  Accessible without login Plain text file test_filter.php Example Example script
  Accessible without login Plain text file test_pipeline.js Data Auxiliary data
  Accessible without login Plain text file test_pipeline.php Example Example script

 Version Control Unique User Downloads Download Rankings  
 100%
Total:42
This week:0
All time:10,674
This week:190Up