jeyroik/df-triggers

There is no license information available for the latest version (4.1.4) of this package.

DF triggers

4.1.4 2023-09-20 14:32 UTC

README

tests codecov.io Latest Stable Version Total Downloads Dependents

df-trigger

DF trigger package

Usage

// 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';
        }
    }
}

Context usage

$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
        ]
    ]
]));