Exemple #1
0
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);
Exemple #2
0
    $success = false;
}
if ($success) {
    echo "Success!\n\n";
} else {
    echo "Failure...\n\n";
}
echo "    Instantiate with Publishers Also -- \n";
$success = true;
$publisher1 = $publisher2 = $publisher3 = null;
try {
    echo "        Instantiate Publisher1 -> ";
    $publisher1 = new Patterns\Publisher();
    echo "Success!\n";
    echo "        Instantiate Publisher2 -> ";
    $publisher2 = new Patterns\Publisher();
    echo "Success!\n";
    echo "        Instantiate Publisher3 -> ";
    $publisher3 = new Patterns\Publisher();
    echo "Success!\n";
} catch (\Exception $e) {
    $success = false;
}
if (!$success) {
    echo "EXCEPTION RAISED\n\n";
}
echo "        Instantiate Conduit (3) -> ";
$success = true;
$conduit3 = null;
try {
    $conduit3 = new Event\Conduit(array(array($filter, $handlerz)), array($publisher1, $publisher2, $publisher3), array('strict' => true));
        echo "  0\n";
    }, null, 0, array('strict' => true));
    $queue->push($handler);
    $handler = new Event\Handler(null, function ($e) {
        echo "  A\n";
    }, null, 1.5, array('strict' => true));
    $queue->push($handler);
} catch (\Exception $e) {
    $success = false;
}
if ($success) {
    echo "Success!\n";
} else {
    echo "Failure...\n";
}
echo "    Fire! -> \n";
$success = true;
$publisher = $event = null;
try {
    $publisher = new Patterns\Publisher();
    $publisher->attachListener($queue);
    $event = new Event\GenericEvent(null, null, null, null);
    $publisher->setState($event);
} catch (\Exception $e) {
    $success = false;
}
if ($success) {
    echo "Success!\n\n";
} else {
    echo "Failure...\n\n";
}
echo "Attach Four Publishers and Unlink -> ";
$success = true;
$finalObserver = null;
$finalPublisher1 = $finalPublisher2 = $finalPublisher3 = $finalPublisher4 = null;
try {
    echo "    Instantiate Final Observer -> ";
    $finalObserver = new Patterns\Observer();
    echo "Success!\n";
    echo "    Instantiate Final Publisher 1 - 4 -> ";
    $finalPublisher1 = new Patterns\Publisher();
    $finalPublisher1->attachListener($finalObserver);
    $finalPublisher2 = new Patterns\Publisher();
    $finalPublisher2->attachListener($finalObserver);
    $finalPublisher3 = new Patterns\Publisher();
    $finalPublisher3->attachListener($finalObserver);
    $finalPublisher4 = new Patterns\Publisher();
    $finalPublisher4->attachListener($finalObserver);
    echo "Success!\n";
} catch (\Exception $e) {
    $success = false;
}
if (!$success) {
    echo "EXCEPTION RAISED\n";
}
echo "    Unlink Observer -> ";
$success = true;
try {
    $finalObserver->unlink();
} catch (\Exception $e) {
    $success = false;
}