$reversePayment = new Transition($committed, $reversed); $this->addTransition($authPayment); $this->addTransition($commitPayment); $this->addTransition($approvePayment); $this->addTransition($commitPaymentReview); $this->addTransition($reversePayment); $this->addTrigger('authorize', array($authPayment)); $this->addTrigger('commit', array($commitPayment, $commitPaymentReview, $approvePayment)); $this->addTrigger('approve', array($approvePayment)); // Set the current state of the object $this->setCurrentState($this->payment->state); } } // Start up the machine $payment = new Payment(); $stateMachine = new PaymentMachine('test', $payment); // Run tests $stateMachine->trigger('authorize'); $stateMachine->trigger('commit'); // Render a GraphViz graph $viz = new GraphViz(new Graph()); $viz->setExecutable(''); // Path to dot.exe $viz->setFormat('svg'); $render = new GraphRender($viz); // Set the executable path and then uncomment this line // echo $render->visualize($stateMachine); // Render an ASCII graph echo "<br/><br/>"; $render = new GraphAscii(); echo nl2br($render->visualize($stateMachine));