Author: Oliver Tischlinger
Inheritance: implements IteratorAggregate, implements MetaborStd\NamedCollectionInterface
Example #1
0
 /**
  * @see MetaborStd\Statemachine.StateInterface::getEvent()
  */
 public function getEvent($name)
 {
     if ($this->events->has($name)) {
         $event = $this->events->get($name);
     } else {
         $event = new Event($name);
         $this->events->add($event);
     }
     return $event;
 }
Example #2
0
 /**
  * @see MetaborStd.NamedInterface::getName()
  */
 public function getName()
 {
     return '(' . implode(' and ', $this->conditions->getNames()) . ')';
 }
Example #3
0
<?php

require_once __DIR__ . '/vendor/autoload.php';
use Example\Order\Process\Postpayment;
use Example\Order\Process\Prepayment;
use Metabor\NamedCollection;
use Metabor\Statemachine\Graph\GraphBuilder;
use Fhaculty\Graph\Graph;
use Graphp\GraphViz\GraphViz;
try {
    $processes = new NamedCollection();
    $processes->add(new Prepayment());
    $processes->add(new Postpayment());
    if (isset($_GET['process'])) {
        $processName = strtolower($_GET['process']);
        if ($processes->has($processName)) {
            $process = $processes->get($processName);
        }
    }
    if (!isset($process)) {
        $processNames = $processes->getNames();
        $processName = reset($processNames);
        $process = $processes->get($processName);
    }
    $graph = new Graph();
    $builder = new GraphBuilder($graph);
    $builder->addStateCollection($process);
    $viz = new GraphViz();
    $viz->setFormat('svg');
    echo file_get_contents($viz->createImageFile($graph));
} catch (Exception $e) {
Example #4
0
<pre>
<?php 
require_once __DIR__ . '/vendor/autoload.php';
use Example\Order\Process\Postpayment;
use Example\Order\ProcessConstants;
use Example\Order\EventConstants;
use Example\Order\Order;
use Example\Order\Process\Prepayment;
use Metabor\NamedCollection;
$processes = new NamedCollection();
$processes->add(new Prepayment());
$processes->add(new Postpayment());
$orders = array();
$orders['PREPAYMENT 1'] = new Order('PREPAYMENT 1', $processes->get(ProcessConstants::PROCESS_PREPAYMENT));
$orders['PREPAYMENT 2'] = new Order('PREPAYMENT 2', $processes->get(ProcessConstants::PROCESS_PREPAYMENT));
$orders['POSTPAYMENT 1'] = new Order('POSTPAYMENT 1', $processes->get(ProcessConstants::PROCESS_POSTPAYMENT));
$orders['POSTPAYMENT 2'] = new Order('POSTPAYMENT 2', $processes->get(ProcessConstants::PROCESS_POSTPAYMENT));
echo '=============================================================' . PHP_EOL;
echo 'all created orders have the status "new"' . PHP_EOL;
echo '=============================================================' . PHP_EOL;
foreach ($orders as $order) {
    echo $order . ' has status ' . $order->getCurrentStateName() . PHP_EOL;
    echo 'possible events: ' . implode(', ', $order->getEventNames()) . PHP_EOL;
    echo '-------------------------------------------------------------' . PHP_EOL;
}
echo '=============================================================' . PHP_EOL;
echo 'now we are authorizing all orders if possible' . PHP_EOL;
echo '=============================================================' . PHP_EOL;
foreach ($orders as $order) {
    echo $order . ' has status ' . $order->getCurrentStateName() . PHP_EOL;
    if ($order->hasEvent(EventConstants::EVENT_AUTHORIZE)) {
 /**
  * @param object $subject
  * @return ProcessInterface
  */
 public function detectProcess($subject)
 {
     $name = $this->detectProcessName($subject);
     return $this->processes->get($name);
 }
 /**
  *
  * @param StateInterface $state
  */
 public function addState(StateInterface $state)
 {
     $this->states->add($state);
 }