PHP code example of dbflowlabs / core

1. Go to this page and download the library: Download dbflowlabs/core 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/ */

    

dbflowlabs / core example snippets


DbflowLabs\Core\Providers\DBFlowServiceProvider::class

return [
    'enabled' => env('DBFLOW_ENABLED', true),
    'binding_mode' => env('DBFLOW_BINDING_MODE', 'code'),
    'auth' => [
        'model' => env('DBFLOW_AUTH_MODEL'),
        'guard' => env('DBFLOW_AUTH_GUARD'),
        'table' => env('DBFLOW_AUTH_TABLE'),
        'connection' => env('DBFLOW_AUTH_CONNECTION'),
        'resolver' => DbflowLabs\Core\Support\ConfigUserResolver::class,
    ],
    'expression' => [
        'strict' => env('DBFLOW_EXPRESSION_STRICT', false),
    ],
    'visual_builder_enabled' => env('DBFLOW_VISUAL_BUILDER_ENABLED', false),
    // Plus v1.1 sections: reassignment, delegation, sla, actions, webhook
];

'auth' => [
    'model' => env('DBFLOW_AUTH_MODEL', 'App\\Models\\User'),
    'guard' => env('DBFLOW_AUTH_GUARD', 'web'),
    'table' => env('DBFLOW_AUTH_TABLE', 'users'),
    'resolver' => DbflowLabs\Core\Support\ConfigUserResolver::class,
],

use DbflowLabs\Core\DBFlow;
use DbflowLabs\Core\Services\AssigneeResolverRegistry;
use DbflowLabs\Core\Services\WorkflowDefinitionRegistry;
use DbflowLabs\Core\Services\WorkflowHooksRegistry;

DBFlow::registerDefinitionProvider(
    app(WorkflowDefinitionRegistry::class),
    $myDefinitionProvider,
);

DBFlow::registerAssigneeResolver(
    app(AssigneeResolverRegistry::class),
    'finance_team',
    $myAssigneeResolver,
);

DBFlow::registerWorkflowHooks(
    app(WorkflowHooksRegistry::class),
    'refund_approval',
    MyRefundHooks::class,
);

use DbflowLabs\Core\Actions\SyncWorkflowDefinitions;

/** @var array{created: list<string>, updated: list<string>, unchanged: list<string>} $summary */
$summary = app(SyncWorkflowDefinitions::class)->handle();

use DbflowLabs\Core\Contracts\Workflowable;
use DbflowLabs\Core\Traits\HasWorkflow;

final class RefundRequest extends Model implements Workflowable
{
    use HasWorkflow;

    public function workflowBusinessKey(): ?string
    {
        return $this->reference_no;
    }

    public function workflowDisplayName(): string
    {
        return 'Refund Request';
    }
}

use DbflowLabs\Core\Contracts\WorkflowContextInterface;

public function getWorkflowVariables(): array
{
    return [
        'total_amount' => (float) $this->amount,
        'supplier_type' => $this->supplier_type,
    ];
}

$instance = $refundRequest->startWorkflow('refund_approval');
// equivalent to DBFlow::start('refund_approval', $refundRequest, auth()->user());

use DbflowLabs\Core\DBFlow;

$instance = DBFlow::start(
    'refund_approval',
    $refundRequest,
    auth()->user(),
    [
        // Host-defined keys — stored as JSON on dbflow_workflow_instances.metadata
        'submit_comment' => 'Q2 budget exception',
        // Used for condition routing when the model does not implement WorkflowContextInterface
        'variables' => ['priority' => 'high'],
    ],
);

DBFlow::approve(
    $task,
    auth()->user(),
    'Approved.',
);

use DbflowLabs\Core\Enums\RejectStrategy;

DBFlow::reject(
    $task,
    auth()->user(),
    'Amount exceeds policy.',
    RejectStrategy::Starter,
);

DBFlow::cancel(
    $instance,
    auth()->user(),
    'Withdrawn by submitter.',
);

DBFlow::reassign(
    $task,
    auth()->user(),
    $replacementUserId,
    'Reassigned while on leave.',
);

$delegation = DBFlow::createDelegation(
    $delegator,
    $delegate,
    now(),
    now()->addDays(7),
    auth()->user(),
    workflowKey: 'refund_approval',
);

DBFlow::migratePendingTasksToDelegate($delegation, auth()->user(), dryRun: true);
DBFlow::revokeDelegation($delegation, auth()->user());

$order->hasRunningWorkflow('refund_approval');
$order->runningWorkflowInstance('refund_approval');
$order->completedWorkflowInstance('refund_approval');
$order->workflowLogs('refund_approval');

// Fixed user (demo / tests)
'assignees' => ['type' => 'user', 'value' => '1'],

// Host-registered resolver (roles, departments, dynamic rules)
'assignees' => ['type' => 'callback', 'callback' => 'finance_team'],

// Resolver key alias — NOT a framework permission string
'assignees' => ['type' => 'permission', 'value' => 'approve_refunds'],

// Register the resolver key used above
DBFlow::registerAssigneeResolver(
    app(AssigneeResolverRegistry::class),
    'approve_refunds',
    new ApproveRefundsAssigneeResolver(),
);

// Does NOT auto-resolve Laravel / Spatie permissions
'assignees' => ['type' => 'permission', 'value' => 'approve-refunds'],
bash
php artisan vendor:publish --tag=dbflow-config
text
config/dbflow.php
bash
php artisan vendor:publish --tag=dbflow-migrations
php artisan migrate
bash
php artisan vendor:publish --tag=dbflow-config
bash
php artisan dbflow:sync
php artisan dbflow:sync --dry-run
php artisan dbflow:sync --workflow=refund_approval
bash
php artisan dbflow:process-timeouts
bash
php artisan dbflow:diagnostics
bash
php artisan dbflow:process-timeouts