PHP code example of alizharb / forgepulse
1. Go to this page and download the library: Download alizharb/forgepulse 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/ */
alizharb / forgepulse example snippets
use AlizHarb\ForgePulse\Models\Workflow;
use AlizHarb\ForgePulse\Enums\WorkflowStatus;
$workflow = Workflow::create([
'name' => 'User Onboarding',
'description' => 'Automated user onboarding process',
'status' => WorkflowStatus::ACTIVE,
]);
use AlizHarb\ForgePulse\Enums\StepType;
// Send welcome email
$workflow->steps()->create([
'name' => 'Send Welcome Email',
'type' => StepType::NOTIFICATION,
'position' => 1,
'configuration' => [
'notification_class' => \App\Notifications\WelcomeEmail::class,
'recipients' => ['{{user_id}}'],
],
]);
// Wait 1 day
$workflow->steps()->create([
'name' => 'Wait 24 Hours',
'type' => StepType::DELAY,
'position' => 2,
'configuration' => [
'seconds' => 86400,
],
]);
// Execute asynchronously (queued)
$execution = $workflow->execute([
'user_id' => $user->id,
'email' => $user->email,
]);
// Execute synchronously
$execution = $workflow->execute(['user_id' => $user->id], async: false);
use AlizHarb\ForgePulse\Enums\StepType;
$step = $workflow->steps()->create([
'type' => StepType::ACTION,
'configuration' => [
'action_class' => \App\Actions\ProcessUserData::class,
'parameters' => ['user_id' => '{{user_id}}'],
],
]);
$step = $workflow->steps()->create([
'type' => StepType::NOTIFICATION,
'configuration' => [
'notification_class' => \App\Notifications\OrderConfirmation::class,
'recipients' => ['{{user_id}}'],
],
]);
$step = $workflow->steps()->create([
'type' => StepType::WEBHOOK,
'configuration' => [
'url' => 'https://api.example.com/webhook',
'method' => 'POST',
'headers' => ['Authorization' => 'Bearer token'],
'payload' => ['data' => '{{context}}'],
],
]);
use AlizHarb\ForgePulse\Enums\StepType;
$step->update([
'conditions' => [
'operator' => 'and',
'rules' => [
['field' => 'user.role', 'operator' => '==', 'value' => 'premium'],
['field' => 'order.total', 'operator' => '>', 'value' => 100],
],
],
]);
// Example: Regex pattern matching
$step->update([
'conditions' => [
'operator' => 'and',
'rules' => [
['field' => 'email', 'operator' => 'regex', 'value' => '/^[a-z]+@company\.com$/'],
['field' => 'age', 'operator' => 'between', 'value' => [18, 65]],
['field' => 'permissions', 'operator' => 'contains_all', 'value' => ['read', 'write']],
],
],
]);
// Save as template
$template = $workflow->saveAsTemplate('User Onboarding Template');
// Create workflow from template
$newWorkflow = $template->instantiateFromTemplate('New Onboarding');
// Export template to file
$templateManager = app(\AlizHarb\ForgePulse\Services\TemplateManager::class);
$path = $templateManager->export($template);
// Import template from file
$workflow = $templateManager->import($path, 'Imported Workflow');
$step->update([
'timeout' => 30, // seconds
]);
// Pause execution
$execution->pause('Waiting for manual approval');
// Resume execution
$execution->resume();
// Check if paused
if ($execution->isPaused()) {
echo "Paused: " . $execution->pause_reason;
}
// Configure steps to run in parallel
$step1->update([
'execution_mode' => 'parallel',
'parallel_group' => 'email-notifications',
]);
$step2->update([
'execution_mode' => 'parallel',
'parallel_group' => 'email-notifications',
]);
// Both steps will execute concurrently
$execution = $workflow->execute([
'scheduled_at' => now()->addHours(2),
'context' => ['user_id' => 123],
]);
'api' => [
'enabled' => true,
'middleware' => ['api', 'auth:sanctum'],
],
// Automatic versioning on save (enabled by default)
$workflow->save(); // Creates version automatically
// Manual version creation
$version = $workflow->createVersion('Before major changes');
// View version history
$versions = $workflow->versions;
// Rollback to a previous version
$workflow->restoreVersion($versionId);
// Compare versions
$latestVersion = $workflow->latestVersion();
$diff = $latestVersion->compare($previousVersion);
'versioning' => [
'enabled' => true,
'max_versions' => 50,
'auto_version_on_save' => true,
'retention_days' => 90,
],
use AlizHarb\ForgePulse\Events\WorkflowCompleted;
use App\Listeners\SendWorkflowCompletionNotification;
protected $listen = [
WorkflowCompleted::class => [
SendWorkflowCompletionNotification::class,
],
];
app()->setLocale('es'); // Spanish
app()->setLocale('fr'); // French
app()->setLocale('de'); // German
app()->setLocale('ar'); // Arabic
'teams' => [
'enabled' => true,
'model' => \App\Models\Team::class,
],
'permissions' => [
'enabled' => false,
// ...
],
bash
php artisan vendor:publish --tag=forgepulse-config
bash
php artisan vendor:publish --tag=forgepulse-migrations
php artisan migrate
bash
php artisan vendor:publish --tag=forgepulse-views
php artisan vendor:publish --tag=forgepulse-assets
php artisan vendor:publish --tag=forgepulse-lang
bash
composer analyse