PHP code example of m1lt0n / in_great_state
1. Go to this page and download the library: Download m1lt0n/in_great_state library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
m1lt0n / in_great_state example snippets
// The minimum d (that returns the object's current state) and the
// setState method (that updates the state of the object).
class Issue implements InGreatState\StatefulInterface
{
private $state;
public function __construct()
{
$this->setState('open');
}
public function currentState()
{
return $this->state;
}
public function setState($state)
{
$this->state = $state;
echo "Setting state to {$state}" . PHP_EOL;
}
}
// The minimum {
echo "Resolving transition from {$owner->currentState()} to resolved" . PHP_EOL;
});
$this->addTransition()->from('open')->to('wontfix')->actions(function ($owner) {
echo "Resolving transition from {$owner->currentState()} to wontfix" . PHP_EOL;
});
}
}
// Now, we can use the state machine :-)
$p = new Issue();
$sm = new IssueStateMachine($p);
$sm->transitionTo('resolved');
$this->addTransition()->to('wontfix')->actions(function ($owner) {
echo "Resolving transition to wontfix" . PHP_EOL;
});