Initial Version
This commit is contained in:
81
shared/lib/Mail/Queue/SendOptions.php
Normal file
81
shared/lib/Mail/Queue/SendOptions.php
Normal file
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace KTXF\Mail\Queue;
|
||||
|
||||
use JsonSerializable;
|
||||
|
||||
/**
|
||||
* Mail Send Options
|
||||
*
|
||||
* Configuration options for message delivery behavior.
|
||||
*
|
||||
* @since 2025.05.01
|
||||
*/
|
||||
class SendOptions implements JsonSerializable {
|
||||
|
||||
/**
|
||||
* @param bool $immediate Send immediately bypassing queue (for 2FA, etc.)
|
||||
* @param int $priority Queue priority (-100 to 100, higher = sooner)
|
||||
* @param int $retryCount Maximum retry attempts on failure
|
||||
* @param int|null $delaySeconds Delay before first send attempt
|
||||
*/
|
||||
public function __construct(
|
||||
public readonly bool $immediate = false,
|
||||
public readonly int $priority = 0,
|
||||
public readonly int $retryCount = 3,
|
||||
public readonly ?int $delaySeconds = null,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Creates options for immediate delivery (bypasses queue)
|
||||
*
|
||||
* @since 2025.05.01
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public static function immediate(): self {
|
||||
return new self(immediate: true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates options for high-priority queued delivery
|
||||
*
|
||||
* @since 2025.05.01
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public static function highPriority(): self {
|
||||
return new self(priority: 50);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates options for low-priority queued delivery (bulk mail)
|
||||
*
|
||||
* @since 2025.05.01
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public static function lowPriority(): self {
|
||||
return new self(priority: -50);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function jsonSerialize(): array {
|
||||
return [
|
||||
'immediate' => $this->immediate,
|
||||
'priority' => $this->priority,
|
||||
'retryCount' => $this->retryCount,
|
||||
'delaySeconds' => $this->delaySeconds,
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user