TriggerDispatcher
in package
implements
EventListenerInterface
Dispatches trigger events to find and start matching workflows.
Supports two dispatch patterns:
- Explicit: call
dispatch()directly from service/controller code. - Event-driven: call
attachToEventManager()during bootstrap, then fire CakePHP events with subject 'Workflow.trigger' and data keys 'eventName', 'eventData', 'triggeredBy'.
The explicit pattern is preferred for clarity and testability. Event-driven dispatch is useful for decoupling plugins that don't want a direct dependency on TriggerDispatcher.
Table of Contents
Interfaces
- EventListenerInterface
Properties
- $attachedListener : self|null
- $engine : WorkflowEngineInterface
Methods
- __construct() : mixed
- Constructor.
- attachToEventManager() : void
- Register this dispatcher as a CakePHP event listener.
- dispatch() : array<string|int, mixed>
- Dispatch a trigger event to find and start matching workflows.
- getEngine() : WorkflowEngineInterface
- Return the engine backing this dispatcher for follow-up workflow operations.
- handleWorkflowEvent() : void
- Handle a CakePHP event by dispatching to the workflow engine.
- implementedEvents() : array<string, mixed>
- CakePHP EventListenerInterface — events this listener handles.
Properties
$attachedListener
private
static self|null
$attachedListener
= null
$engine
private
WorkflowEngineInterface
$engine
Methods
__construct()
Constructor.
public
__construct(WorkflowEngineInterface $engine) : mixed
Parameters
- $engine : WorkflowEngineInterface
-
Workflow engine
attachToEventManager()
Register this dispatcher as a CakePHP event listener.
public
attachToEventManager([EventManager|null $eventManager = null ]) : void
Call during Application::bootstrap() or plugin bootstrap to enable automatic workflow dispatch from CakePHP events:
$triggerDispatcher->attachToEventManager();
Then fire events anywhere: EventManager::instance()->dispatch(new Event('Workflow.trigger', $this, [ 'eventName' => 'Officers.HireRequested', 'eventData' => ['officerId' => 42], 'triggeredBy' => $memberId, ]));
Parameters
- $eventManager : EventManager|null = null
dispatch()
Dispatch a trigger event to find and start matching workflows.
public
dispatch(string $eventName[, array<string|int, mixed> $eventData = [] ][, int|null $triggeredBy = null ]) : array<string|int, mixed>
Parameters
- $eventName : string
-
Event identifier (e.g., 'Officers.HireRequested')
- $eventData : array<string|int, mixed> = []
-
Data associated with the event
- $triggeredBy : int|null = null
-
Member who triggered
Return values
array<string|int, mixed> —Array of ServiceResult from started workflows
getEngine()
Return the engine backing this dispatcher for follow-up workflow operations.
public
getEngine() : WorkflowEngineInterface
Return values
WorkflowEngineInterfacehandleWorkflowEvent()
Handle a CakePHP event by dispatching to the workflow engine.
public
handleWorkflowEvent(EventInterface $event) : void
Parameters
- $event : EventInterface
implementedEvents()
CakePHP EventListenerInterface — events this listener handles.
public
implementedEvents() : array<string, mixed>