PHP code example of jeyroik / df-triggers

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

    

jeyroik / df-triggers example snippets


// get income request with specified instance id and event name
// get instance by instance id
// @var IInstance $instance
use deflou\components\triggers\TriggerService;

$resolvedEvent = $instance->buildResolver()->resolveEvent();
$triggerService = new TriggerService();

$triggers = $triggerService->getTriggers($instance->getId(), $eventName, ['vendorName1', 'vendorName2, ...']);

foreach ($triggers as $trigger) {
    if ($triggerService->isApplicableTrigger($resolvedEvent, $trigger)) {
        $result = $trigger->getInstance(ETrigger::Operation)->buildResolver()->resolveOperation($resolvedEvent, $trigger)->run();

        if ($result->isSuccess()) {
            echo 'Success trigger #' . $trigger->getId() . ' execution';
        } else {
            echo 'Failed trigger #' . $trigger->getId() . ' execution';
        }
    }
}

$ts = new TemplateService();
$templates = $ts->getTemplates($someRepo, new ContextTrigger([
    ContextTrigger::FIELD__PARAMS => [
        ContextTrigger::PARAM__FOR => [
            IParam::FIELD__NAME => ContextTrigger::PARAM__FOR,
            IParam::FIELD__VALUE => ETrigger::Event
        ],
        ContextTrigger::PARAM__TRIGGER => [
            IParam::FIELD__NAME => ContextTrigger::PARAM__TRIGGER,
            IParam::FIELD__VALUE => $trigger
        ]
    ]
]));