PHP code example of dovuofficial / guardian-php-sdk
1. Go to this page and download the library: Download dovuofficial/guardian-php-sdk 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/ */
dovuofficial / guardian-php-sdk example snippets
$this->sdk = new DovuGuardianAPI();
$this->sdk->setGuardianBaseUrl("http://localhost:3000/api/v1/");
$context = PolicyContext::using($this->sdk)->for($policy_id);
$this->policy_workflow = PolicyWorkflow::context($context);
/**
* Set up the workflow from configuration
*/
$configuration = $this->policy_workflow->getConfiguration();
$conf = GuardianWorkflowConfiguration::get('test_workflow'); // From the "/config" folder
$specification = $configuration->generateWorkflowSpecification($conf['workflow']);
[
0 => array:4 [▶
"role" => Dovu\GuardianPhpSdk\Constants\GuardianRole {#93▶}
"tag" => "create_ecological_project"
"type" => Dovu\GuardianPhpSdk\Workflow\Constants\WorkflowTask {#710▶}
"schema_specification" => array:13 [▶
"title" => "ELV Scrapping for CO2 Emission Avoidance (AMS-III.BA & AMS-III.AJ)"
"description" => "End-of-life vehicle project registration for the recovery and recycling of materials from e-waste, using a digitised form of UN CDM Methodology version 3.0"
"type" => "object"
"
/**
* Stage one: create an ecological project (identity handled outside)
*/
$users = $this->dry_run_scenario->createUser(); // Returns a list of all users
$user = (object) end($users);
$this->dry_run_scenario->login($user->did);
$this->policy_workflow->assignRole(GuardianRole::SUPPLIER);
/**
* Build an object for the particular action
*/
$send_ecological = (object) $specification[0];
$element = WorkflowElement::parse($send_ecological);
$project = json_decode($project, true); // See "ResearchElvClientGuardianTest"
$result = GuardianActionTransaction::with($mediator)
->setWorkflowElement($element)
->setPayload($project)
->run();
ray('$send_ecological');
ray($result);
// TODO: Use the listener logic (This will increase based off of the current resource load on API)
sleep(2);
/**
* Stage two: login as registry (handled outside workflow)
*/
$this->dry_run_scenario->login($admin->did);
$approve_ecological = (object) $specification[1];
$element = WorkflowElement::parse($approve_ecological);
// TODO: This would be the "plucker" (can we make this more dynamic?)
$result = GuardianActionTransaction::with($mediator)
->setWorkflowElement($element)
->setFilterValue($project['uuid'])
->setApprovalOption(ApprovalOption::APPROVE)
->run();