PHP code example of waysnx / business-framework

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

    

waysnx / business-framework example snippets


// In a service provider's boot() method:
$workflowRegistry = app(WorkflowRegistry::class);
$workflowRegistry->register(OnboardingDefinition::create());

$entityRegistry = app(EntityRegistry::class);
$entityRegistry->register(EmployeeDefinition::create());

// In a service provider's boot() method:
$workflowRegistry = app(WorkflowRegistry::class);
$workflowRegistry->register(OnboardingDefinition::create());

$engine = new WorkflowEngine($workflowRegistry, $lifecycleManager);
$context = new WorkflowContext(
    workflowId: 'employee-onboarding',
    executionId: 'exec-123',
    entity: $employee,
    moduleId: 'hr',
    inputData: ['department' => 'engineering']
);
$result = $engine->execute('employee-onboarding', $context);

use WaysNX\BusinessFramework\Registry\WorkflowRegistry;
use WaysNX\BusinessFramework\Workflow\WorkflowEngine;
use WaysNX\BusinessFramework\Workflow\WorkflowContext;

class AuditController {
    public function __construct(
        private WorkflowRegistry $workflows,
        private WorkflowEngine $engine
    ) {}
    
    public function startAudit() {
        // Retrieve workflow definition from registry
        $workflow = $this->workflows->findById('audit-review');
        
        // Create execution context
        $context = new WorkflowContext(
            workflowId: 'audit-review',
            executionId: 'audit-' . uniqid(),
            entity: $audit,
            inputData: ['department' => $audit->department]
        );
        
        // Execute workflow
        $result = $this->engine->execute('audit-review', $context);
        
        if ($result->succeeded()) {
            // Handle success
        } else {
            // Handle failure
            foreach ($result->errors as $error) {
                logger()->error($error);
            }
        }
    }
}

// All components are bound as singletons:
$this->app->singleton(WorkflowRegistry::class, ...);
$this->app->singleton(WorkflowEngine::class, ...);
$this->app->singleton(ValidationFramework::class, ...);
// ... and others

$allWorkflows = $registry->all();
$hrWorkflows = $registry->findByModule('hr');
$eventTriggeredWorkflows = $registry->findByTrigger('event');
bash
php artisan wbf:doctor
bash
php artisan wbf:list
bash
php artisan wbf:list workflows
php artisan wbf:list business-functions
php artisan wbf:list validations
php artisan wbf:list modules
php artisan wbf:list entities
bash
php artisan wbf:doctor               # Show health summary
php artisan wbf:doctor --detail      # Show detailed diagnostics
php artisan wbf:doctor --json        # Output as JSON
php artisan wbf:doctor --component WorkflowEngine   # Check specific component
bash
php artisan wbf:make module HumanResources
php artisan wbf:make entity Employee
php artisan wbf:make business-function ApplyLeave
php artisan wbf:make validation CheckEligibility
php artisan wbf:make workflow OnboardingWorkflow

# Options:
php artisan wbf:make business-function ApplyLeave --module=hr
php artisan wbf:make business-function ApplyLeave --namespace="App\\Hr\\Functions"
php artisan wbf:make business-function ApplyLeave --description="Process leave requests"
php artisan wbf:make business-function ApplyLeave --force   # Overwrite if exists
php artisan wbf:make business-function ApplyLeave --json    # Output as JSON
bash
php artisan wbf:register module HumanResources
php artisan wbf:register entity Employee
php artisan wbf:register business-function ApplyLeave
php artisan wbf:register validation CheckEligibility
php artisan wbf:register workflow OnboardingWorkflow

# Options:
php artisan wbf:register workflow OnboardingWorkflow --fail-if-not-found  # Exit with error if not found
php artisan wbf:register workflow OnboardingWorkflow --json               # Output as JSON