*/ private array $payload; /** * @var \DateTimeImmutable */ private \DateTimeImmutable $occurred_at; /** * Constructor. * * @param string $trigger_name Trigger identifier (matches WorkflowTriggers::getTriggers() keys). * @param array $payload Event payload. * @param string|null $occurred_at Original event occurrence timestamp. */ public function __construct( string $trigger_name, array $payload = array(), ?string $occurred_at = null ) { $this->trigger_name = $trigger_name; $this->payload = $payload; try { $this->occurred_at = ! empty( $occurred_at ) ? new \DateTimeImmutable( $occurred_at, wp_timezone() ) : new \DateTimeImmutable( 'now', wp_timezone() ); } catch ( \Exception $exception ) { $this->occurred_at = new \DateTimeImmutable( 'now', wp_timezone() ); } } /** * {@inheritdoc} */ public function getName(): string { return $this->trigger_name; } /** * {@inheritdoc} */ public static function getLabel(): string { return __( 'Workflow Trigger', 'afroit-messaging-workflows' ); } /** * {@inheritdoc} */ public function getPayload(): array { return $this->payload; } /** * {@inheritdoc} */ public function getOccurredAt(): \DateTimeImmutable { return $this->occurred_at; } }