PHP code example of sbooker / workflow
1. Go to this page and download the library: Download sbooker/workflow 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/ */
sbooker / workflow example snippets
// Step 1. Create Status Enum
use Sbooker\Workflow\Status;
enum ConcreteStatus: string implements Status
{
use \Sbooker\Workflow\EnumTrait;
case first = "first";
case second = "second";
}
// Step 2. Define workflow
use Sbooker\Workflow\Workflow;
use Ds\Map;
use Ds\Set;
final class ConcreteWorkflow extends Workflow
{
public function __construct()
{
parent::__construct(ConcreteStatus::first);
}
protected function buildTransitionMap(): Map
{
$map = new Map();
$map->put(ConcreteStatus::first, new Set([ConcreteStatus::second]));
return $map;
}
protected function getStatusClass(): string
{
return ConcreteStatus::class;
}
}
// Step 3. Use workflow in your entity for state control
class ConcreteEntity {
// ...
private ConcreteWorkflow $workflow;
// ...
public function __construct() {
// ...
$this->workflow = new ConcreteWorkflow();
// ...
}
public function doSecond(): void {
// ...
$this->workflow->transitTo(ConcreteStatus::second());
// ...
}
}