1. Go to this page and download the library: Download laravolt/camunda 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/ */
use Laravolt\Camunda\Http\ProcessDefinitionClient;
$variables = ['title' => ['value' => 'Sample Title', 'type' => 'string']];
// Start new process instance
$instance = ProcessDefinitionClient::start(key: 'process_1', variables: $variables);
// Start new process instance with some business key
$instance = ProcessDefinitionClient::start(key: 'process_1', variables: $variables, businessKey: 'somekey');
// Get BPMN definition in XML format
ProcessDefinitionClient::xml(key: 'process_1');
ProcessDefinitionClient::xml(id: 'process_1:xxxx');
// Get all definition
ProcessDefinitionClient::get();
// Get definitions based on some parameters
$params = ['latestVersion' => true];
ProcessDefinitionClient::get($params);
use Laravolt\Camunda\Http\ProcessInstanceClient;
// Find by ID
$processInstance = ProcessInstanceClient::find(id: 'some-id');
// Get all instances
ProcessInstanceClient::get();
// Get instances based on some parameters
$params = ['businessKeyLike' => 'somekey'];
ProcessInstanceClient::get($params);
ProcessInstanceClient::variables(id: 'some-id');
ProcessInstanceClient::delete(id: 'some-id');
use Laravolt\Camunda\Http\MessageEventClient;
// Start processinstance with message event
// Required
// messageName : message event name
// businessKey : Busniess key for process instance
// Rerturn Process insntance from message event
MessageEventClient::start(messageName: "testing", businessKey: "businessKey")
use Laravolt\Camunda\Http\TaskClient;
$task = TaskClient::find(id: 'task-id');
$tasks = TaskClient::getByProcessInstanceId(id: 'process-instance-id');
$tasks = TaskClient::getByProcessInstanceIds(ids: 'arrayof-process-instance-ids');
TaskClient::submit(id: 'task-id', variables: ['name' => ['value' => 'Foo', 'type' => 'String']]); // will return true or false
$variables = TaskClient::submitAndReturnVariables(id: 'task-id', variables: ['name' => ['value' => 'Foo', 'type' => 'String']]) // will return array of variable
// Claim a Task
$tasks = TaskClient::claim($task_id, $user_id);
// Unclaim a Task
$tasks = TaskClient::unclaim($task_id);
// Assign a Task
$tasks = TaskClient::assign($task_id, $user_id);
use Laravolt\Camunda\Http\ExternalTaskClient;
$topics = [
['topicName' => 'pdf', 'lockDuration' => 600_000]
];
$externalTasks = ExternalTaskClient::fetchAndLock('worker1', $topics);
foreach ($externalTasks as $externalTask) {
// do something with $externalTask
// Mark as complete after finished
ExternalTaskClient::complete($externalTasks->id);
}
// Unlock some task
ExternalTaskClient::unlock($task->id)
// Get task locked
$externalTaskLocked = ExternalTaskClient::getTaskLocked();
use Laravolt\Camunda\Dto\ExternalTask;
use Laravolt\Camunda\Http\ExternalTaskClient;
public function __construct(
public string $workerId,
public ExternalTask $task
) {
}
public function handle()
{
// Do something with $this->task, e.g: get the variables and generate PDF
$variables = \Laravolt\Camunda\Http\ProcessInstanceClient::variables($this->task->processDefinitionId);
// PdfService::generate()
// Complete the task
$status = ExternalTaskClient::complete($this->task->id, $this->workerId);
}
// AppServiceProvider.php
use Laravolt\Camunda\Http\ExternalTaskClient;
public function boot()
{
ExternalTaskClient::subscribe('pdf', GeneratePdf::class);
}
// app/Console/Kernel.php
protected function schedule(Schedule $schedule)
{
$schedule->command('camunda:consume-external-task --workerId=worker1')->everyMinute();
}
use Laravolt\Camunda\Http\TaskHistoryClient;
$completedTask = TaskHistoryClient::find(id: 'task-id');
$completedTasks = TaskHistoryClient::getByProcessInstanceId(id: 'process-instance-id');
use Laravolt\Camunda\Http\DeploymentClient;
// Deploy bpmn file(s)
DeploymentClient::create('test-deploy', '/path/to/file.bpmn');
DeploymentClient::create('test-deploy', ['/path/to/file1.bpmn', '/path/to/file2.bpmn']);
// Get deployment list
DeploymentClient::get();
// Find detailed info about some deployment
DeploymentClient::find($id);
// Truncate (delete all) deployments
$cascade = true;
DeploymentClient::truncate($cascade);
// Delete single deployment
DeploymentClient::delete(id: 'test-deploy', cascade: $cascade);