Creating a custom token provider
Token providers allow you to use dynamic token replacement in condition and function arguments. For example, the following condition definition allows checking against the dynamic state variable named email_address
:
condition:
ref: string.EndsWith
args:
pattern: @gmail.com
value: $email_address
You can extend CfFlow to provide your own tokens that will be replaced dynamically with your own logic.
The IWorkflowArgSubstitutionProvider interface
To create your own token provider, create a CFC that implements the following interface:
interface {
public struct function getTokens(
required array requiredTokens
, required WorkflowInstance wfInstance
);
}
For example:
component implements="cfflow.models.substitution.IWorkflowArgSubstitutionProvider" {
public struct function getTokens(
required array requiredTokens
, required WorkflowInstance wfInstance
) {
var tokens = {};
// the array of requiredTokens are tokens
// parsed from the args. This allows you to
// only generate the tokens that are necessary
if ( ArrayFindNoCase( requiredTokens, "$my.custom.token" ) ) {
tokens[ "$my.custom.token" ] = "a hardcoded example";
}
return tokens;
}
}
Register your token provider with CfFlow
Create an instance of your component, and register it with the core engine:
var myTokenProvider = new myTokenProvider();
cfflow.registerTokenProvider( myTokenProvider );
That’s it!