Skip to content

Instantly share code, notes, and snippets.

@jorgecc
Created December 9, 2018 18:52
Show Gist options
  • Save jorgecc/3b74df4492a85b9a83ded7e9ec00f710 to your computer and use it in GitHub Desktop.
Save jorgecc/3b74df4492a85b9a83ded7e9ec00f710 to your computer and use it in GitHub Desktop.
BuyMilk4
<?php
// business rules
$smachine->addTransition(INITIAL_STATE,DRIVING_TO_BUY_MILK
,'when milk = 0 and gas > 0');
$smachine->addTransition(INITIAL_STATE,CANCEL_DRIVING
,'when gas = 0',null,'stop'); // null means, no timeout and stop means, the job will stop
$smachine->addTransition(DRIVING_TO_BUY_MILK,PICKING_THE_MILK
,'when store_open = 1 and stock_milk > 0');
$smachine->addTransition(DRIVING_TO_BUY_MILK,UNABLE_TO_PURCHASE
,'when store_open = 0 or stock_milk = 0');
$smachine->addTransition(PICKING_THE_MILK,PAYING_FOR_THE_MILK
,'when money >= price set milk = 1');
$smachine->addTransition(PICKING_THE_MILK,UNABLE_TO_PURCHASE
,'when money < price');
$smachine->addTransition(UNABLE_TO_PURCHASE,DRIVE_BACK_HOME
,'when timeout',0,'stop');
$smachine->addTransition(PAYING_FOR_THE_MILK,DRIVE_BACK_HOME
,'when timeout',0,'stop');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment