|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Utopia\Migration\Resources\Settings; |
| 4 | + |
| 5 | +use Utopia\Migration\Resource; |
| 6 | +use Utopia\Migration\Transfer; |
| 7 | + |
| 8 | +/** |
| 9 | + * Singleton resource representing the project's custom SMTP configuration. |
| 10 | + * Password is not migrated — the source API never exposes it. |
| 11 | + */ |
| 12 | +class SMTP extends Resource |
| 13 | +{ |
| 14 | + public function __construct( |
| 15 | + string $id, |
| 16 | + private readonly bool $enabled = false, |
| 17 | + private readonly string $senderName = '', |
| 18 | + private readonly string $senderEmail = '', |
| 19 | + private readonly string $replyToName = '', |
| 20 | + private readonly string $replyToEmail = '', |
| 21 | + private readonly string $host = '', |
| 22 | + private readonly int $port = 0, |
| 23 | + private readonly string $username = '', |
| 24 | + private readonly string $secure = '', |
| 25 | + string $createdAt = '', |
| 26 | + string $updatedAt = '', |
| 27 | + ) { |
| 28 | + $this->id = $id; |
| 29 | + $this->createdAt = $createdAt; |
| 30 | + $this->updatedAt = $updatedAt; |
| 31 | + } |
| 32 | + |
| 33 | + /** |
| 34 | + * @param array<string, mixed> $array |
| 35 | + */ |
| 36 | + public static function fromArray(array $array): self |
| 37 | + { |
| 38 | + return new self( |
| 39 | + $array['id'], |
| 40 | + (bool) ($array['enabled'] ?? false), |
| 41 | + (string) ($array['senderName'] ?? ''), |
| 42 | + (string) ($array['senderEmail'] ?? ''), |
| 43 | + (string) ($array['replyToName'] ?? ''), |
| 44 | + (string) ($array['replyToEmail'] ?? ''), |
| 45 | + (string) ($array['host'] ?? ''), |
| 46 | + (int) ($array['port'] ?? 0), |
| 47 | + (string) ($array['username'] ?? ''), |
| 48 | + (string) ($array['secure'] ?? ''), |
| 49 | + createdAt: $array['createdAt'] ?? '', |
| 50 | + updatedAt: $array['updatedAt'] ?? '', |
| 51 | + ); |
| 52 | + } |
| 53 | + |
| 54 | + /** |
| 55 | + * @return array<string, mixed> |
| 56 | + */ |
| 57 | + public function jsonSerialize(): array |
| 58 | + { |
| 59 | + return [ |
| 60 | + 'id' => $this->id, |
| 61 | + 'enabled' => $this->enabled, |
| 62 | + 'senderName' => $this->senderName, |
| 63 | + 'senderEmail' => $this->senderEmail, |
| 64 | + 'replyToName' => $this->replyToName, |
| 65 | + 'replyToEmail' => $this->replyToEmail, |
| 66 | + 'host' => $this->host, |
| 67 | + 'port' => $this->port, |
| 68 | + 'username' => $this->username, |
| 69 | + 'secure' => $this->secure, |
| 70 | + 'createdAt' => $this->createdAt, |
| 71 | + 'updatedAt' => $this->updatedAt, |
| 72 | + ]; |
| 73 | + } |
| 74 | + |
| 75 | + public static function getName(): string |
| 76 | + { |
| 77 | + return Resource::TYPE_SMTP; |
| 78 | + } |
| 79 | + |
| 80 | + public function getGroup(): string |
| 81 | + { |
| 82 | + return Transfer::GROUP_INTEGRATIONS; |
| 83 | + } |
| 84 | + |
| 85 | + public function getEnabled(): bool |
| 86 | + { |
| 87 | + return $this->enabled; |
| 88 | + } |
| 89 | + |
| 90 | + public function getSenderName(): string |
| 91 | + { |
| 92 | + return $this->senderName; |
| 93 | + } |
| 94 | + |
| 95 | + public function getSenderEmail(): string |
| 96 | + { |
| 97 | + return $this->senderEmail; |
| 98 | + } |
| 99 | + |
| 100 | + public function getReplyToName(): string |
| 101 | + { |
| 102 | + return $this->replyToName; |
| 103 | + } |
| 104 | + |
| 105 | + public function getReplyToEmail(): string |
| 106 | + { |
| 107 | + return $this->replyToEmail; |
| 108 | + } |
| 109 | + |
| 110 | + public function getHost(): string |
| 111 | + { |
| 112 | + return $this->host; |
| 113 | + } |
| 114 | + |
| 115 | + public function getPort(): int |
| 116 | + { |
| 117 | + return $this->port; |
| 118 | + } |
| 119 | + |
| 120 | + public function getUsername(): string |
| 121 | + { |
| 122 | + return $this->username; |
| 123 | + } |
| 124 | + |
| 125 | + public function getSecure(): string |
| 126 | + { |
| 127 | + return $this->secure; |
| 128 | + } |
| 129 | +} |
0 commit comments