1. Go to this page and download the library: Download aurorawebsoftware/arflow 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/ */
aurorawebsoftware / arflow example snippets
use AuroraWebSoftware\ArFlow\Traits\HasState;
class YourModel extends Model
{
use HasState;
// Your model properties and methods
}
use AuroraWebSoftware\ArFlow\Contacts\StateableModelContract;
class YourModel extends Model implements StateableModelContract
{
use HasState;
public static function supportedWorkflows(): array
{
return ['workflow1', 'workflow3'];
}
// Your model properties and methods
}
class YourModel extends Model implements StateableModelContract
{
use HasState;
public static function workflowAttribute(): string
{
return 'workflow';
}
public static function stateAttribute(): string
{
return 'state';
}
public static function stateMetadataAttribute(): string
{
return 'state_metadata';
}
// Your model properties and methods
}
// Defined transition states
$definedStates = $model->definedTransitionStates();
// Allowed transition states
$allowedStates = $model->allowedTransitionStates();
namespace App\ArFlow\Guards;
use AuroraWebSoftware\ArFlow\Contacts\StateableModelContract;
use AuroraWebSoftware\ArFlow\Contacts\TransitionGuardContract;
use AuroraWebSoftware\ArFlow\DTOs\TransitionGuardResultDTO;
class PermissionTransitionGuard implements TransitionGuardContract
{
private StateableModelContract $model;
private string $from;
private string $to;
private array $parameters;
public function __construct() {}
public function boot(StateableModelContract &Model $model, string $from, string $to, array $parameters): void
{
$this->model = $model;
$this->from = $from;
$this->to = $to;
$this->parameters = $parameters;
// You can perform any initialization here.
}
public function handle(): TransitionGuardResultDTO
{
// Implement your logic to check permissions here.
// For example, check if the user has the
use AuroraWebSoftware\ArFlow\Contacts\TransitionActionContract;
class SendNotificationAction implements TransitionActionContract
{
public function boot(StateableModelContract&Model $model, string $from, string $to, array $parameters = []): void {}
public function handle(): void
{
// Send a notification when the transition is successful.
}
public function failed(): void
{
// Handle any cleanup or error logging here if the action fails.
}
}
namespace AuroraWebSoftware\ArFlow\Tests\Jobs;
use AuroraWebSoftware\ArFlow\Abstracts\AbstractTransitionSuccessJob;
use AuroraWebSoftware\ArFlow\Contacts\StateableModelContract;
use Illuminate\Database\Eloquent\Model;
class TestTransitionSuccessJob extends AbstractTransitionSuccessJob
{
/**
* Execute the job.
* @param StateableModelContract&Model $model
* @param string $from
* @param string $to
* @param array $parameters
*/
public function handle(StateableModelContract & Model $model, string $from, string $to, array $parameters = []): void
{
// Process
}
}