PHP Classes

File: Falcraft/examples/Event/GenericEvent.php

Recommend this page to a friend!
  Classes of Asher Wolfstein   Universal PHP Event System   Falcraft/examples/Event/GenericEvent.php   Download  
File: Falcraft/examples/Event/GenericEvent.php
Role: Example script
Content type: text/plain
Description: Generic Event Example
Class: Universal PHP Event System
Manage events with the Observer/Publisher patterns
Author: By
Last change:
Date: 8 years ago
Size: 3,488 bytes
 

Contents

Class file image Download
<?php

require_once( __DIR__ . '/../../Event/GenericEvent.php' );
require_once(
__DIR__ . '/../../Data/Types/Null.php' );
require_once(
__DIR__ . '/../../Data/Types/Set.php' );

use
Falcraft\Event;
use
Falcraft\Patterns;
use
Falcraft\Data\Types;

echo
"Falcraft\\Event\\GenericEvent.php Test\n";
echo
"------------------------------------\n\n";
   
echo
"Basic Instantiation -- \n\n";

$success = true;

try {
   
$null = new Types\Null();
    echo
"event = new EventResource\\GenericEvent( \$null, \n" .
        
"testFunction, \n testClass, \n testNamespace, \n null, \n " .
        
"array( tag1, tag2 ), \n array( cat1, cat2 ), \n" .
        
" array( options => strict ) );\n";
   
$event = new Event\GenericEvent(
       
$null,
       
'testFunction',
       
'testClass',
       
'testNamespace',
       
null,
        array(
'tag1', 'tag2'),
        array(
'cat1', 'cat2'),
        array(
'strict' => true)
    );
} catch (\
Exception $e) {
   
$success = false;
}

if (
$success) {
    echo
"Success!\n\n";
} else {
    echo
"Failure...\n\n";
}

echo
"Basic Operations -- \n\n";

$success = true;

try {
    echo
" event->getState(): \n\n";
   
var_dump($event->getState());
    echo
"\n";
} catch (\
Exception $e) {
   
$success = false;
}

if (
$success) {
    echo
"Success!\n\n";
} else {
    echo
"Failure...\n\n";
}

$success = true;

try {
    echo
" state = array( identifier => event->getIdentifier, \n" .
        
" tags => array( tag3, tag4 ), \n" .
        
" categories -> array( cat3, cat4 ), \n" .
        
" class => testClass2, \n" .
        
" function => testFunction2, \n" .
        
" namespace => testNamespace2, )\n\n";
        
   
$state = array(
       
'identifier' => $event->getIdentifier(),
       
'tags' => array('tag3', 'tag4'),
       
'categories' => array('cat3', 'cat4'),
       
'class' => 'testClass2',
       
'function' => 'testFunction2',
       
'namespace' => 'testNamespace2',
    );
   
    echo
" event->setState( state ) -> \n\n";
   
   
$event->setState($state);
   
   
var_dump($event->getState());
   
    echo
"\n";
} catch (\
Exception $e) {
   
$success = false;
}

if (
$success) {
    echo
"Success!\n";
} else {
    echo
"Failure...\n";
}

$success = true;

$tags = null;

try {
    echo
" tags = Set( array( tag7, tag8 ), strict )\n";
   
$tags = new Types\Set(
        array(
'tag7', 'tag8'),
        array(
'strict' => true)
    );
   
    echo
" event->setEventState( identifier -> event->getIdentifier, \n" .
        
" tags => \$tags, false) );\n\n";
   
   
$event->setEventState(
        array(
'identifier' => $event->getIdentifier(), 'tags' => $tags),
       
false
   
);
   
   
var_dump($event->getState());
   
    echo
"\n";
} catch (\
Exception $e) {
   
$success = false;
}

if (
$success) {
    echo
"Success!\n\n";
} else {
    echo
"Failure...\n\n";
}

$success = true;

try {
    echo
" event->stop; \n";
   
$event->stop();
    echo
" event->isStopped -> ";
    echo
$event->isStopped() ? "True\n" : "False\n";
} catch (\
Exception $e) {
   
$success = false;
}

if (
$success) {
    echo
"Success!\n\n";
} else {
    echo
"Failure...\n\n";
}

$success = true;

try {
    echo
" event->force; \n";
   
$event->force();
    echo
" event->isUnstoppable -> ";
    echo
$event->isUnstoppable() ? "True\n" : "False\n";
} catch (\
Exception $e) {
   
$success = false;
}

if (
$success) {
    echo
"Success!\n";
} else {
    echo
"Failure...\n";
}