PHP Classes

File: test/test_filter.php

Recommend this page to a friend!
  Classes of Nikos M.  >  PHP Publish Subscribe  >  test/test_filter.php  >  Download  
File: test/test_filter.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP Publish Subscribe
Register and call handlers of events by name
Author: By
Last change:
Date: 1 year ago
Size: 1,226 bytes
 

Contents

Class file image Download
<?php
require('../src/php/PublishSubscribe.php');

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

function
filter($pb, $hook, $value=null, $args=null)
{
   
$data = new stdClass;
    if ( !empty(
$args) )
    {
        foreach((array)
$args as $k=>$v)
           
$data->{$k} = $v;
    }
   
$data->value = $value;
   
$pb->trigger($hook, $data);
    return
$data->value;
}

function
filter_pipeline($pb, $hook, $value=null, $args=null)
{
   
$data = new stdClass;
    if ( !empty(
$args) )
    {
        foreach((array)
$args as $k=>$v)
           
$data->{$k} = $v;
    }
   
$data->value = $value;
   
$pb->pipeline($hook, $data, null, function($evt){
        echo(
$evt->data->value . PHP_EOL);
    });
}

$pb = new PublishSubscribe( );
$pb->on('filter_value', function($evt){
   
print_r($evt->data);
   
$evt->data->value++;
});
$pb->on('filter_value_pipeline', function($evt){
   
print_r($evt->data);
   
$evt->data->value++;
   
$evt->next();
});
$pb->on('filter_value_pipeline', function($evt){
   
print_r($evt->data);
   
$evt->data->value++;
   
$evt->next();
});
$pb->on('filter_value_pipeline', function($evt){
   
print_r($evt->data);
   
$evt->data->value++;
   
$evt->next();
});

echo
filter($pb, 'filter_value', 2) . PHP_EOL;
filter_pipeline($pb, 'filter_value_pipeline', 2);

For more information send a message to info at phpclasses dot org.