|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Utopia\Migration\Resources\Auth; |
| 4 | + |
| 5 | +use Utopia\Migration\Resource; |
| 6 | +use Utopia\Migration\Transfer; |
| 7 | + |
| 8 | +/** |
| 9 | + * Singleton resource representing the project's auth-method flags. |
| 10 | + * One per project; the destination updates the project doc, not a new row. |
| 11 | + */ |
| 12 | +class AuthMethods extends Resource |
| 13 | +{ |
| 14 | + public function __construct( |
| 15 | + string $id, |
| 16 | + private readonly bool $emailPassword = true, |
| 17 | + private readonly bool $magicURL = true, |
| 18 | + private readonly bool $emailOtp = true, |
| 19 | + private readonly bool $anonymous = true, |
| 20 | + private readonly bool $invites = true, |
| 21 | + private readonly bool $jwt = true, |
| 22 | + private readonly bool $phone = true, |
| 23 | + string $createdAt = '', |
| 24 | + string $updatedAt = '', |
| 25 | + ) { |
| 26 | + $this->id = $id; |
| 27 | + $this->createdAt = $createdAt; |
| 28 | + $this->updatedAt = $updatedAt; |
| 29 | + } |
| 30 | + |
| 31 | + /** |
| 32 | + * @param array<string, mixed> $array |
| 33 | + */ |
| 34 | + public static function fromArray(array $array): self |
| 35 | + { |
| 36 | + return new self( |
| 37 | + $array['id'], |
| 38 | + (bool) ($array['emailPassword'] ?? true), |
| 39 | + (bool) ($array['magicURL'] ?? true), |
| 40 | + (bool) ($array['emailOtp'] ?? true), |
| 41 | + (bool) ($array['anonymous'] ?? true), |
| 42 | + (bool) ($array['invites'] ?? true), |
| 43 | + (bool) ($array['jwt'] ?? true), |
| 44 | + (bool) ($array['phone'] ?? true), |
| 45 | + createdAt: $array['createdAt'] ?? '', |
| 46 | + updatedAt: $array['updatedAt'] ?? '', |
| 47 | + ); |
| 48 | + } |
| 49 | + |
| 50 | + /** |
| 51 | + * @return array<string, mixed> |
| 52 | + */ |
| 53 | + public function jsonSerialize(): array |
| 54 | + { |
| 55 | + return [ |
| 56 | + 'id' => $this->id, |
| 57 | + 'emailPassword' => $this->emailPassword, |
| 58 | + 'magicURL' => $this->magicURL, |
| 59 | + 'emailOtp' => $this->emailOtp, |
| 60 | + 'anonymous' => $this->anonymous, |
| 61 | + 'invites' => $this->invites, |
| 62 | + 'jwt' => $this->jwt, |
| 63 | + 'phone' => $this->phone, |
| 64 | + 'createdAt' => $this->createdAt, |
| 65 | + 'updatedAt' => $this->updatedAt, |
| 66 | + ]; |
| 67 | + } |
| 68 | + |
| 69 | + public static function getName(): string |
| 70 | + { |
| 71 | + return Resource::TYPE_AUTH_METHODS; |
| 72 | + } |
| 73 | + |
| 74 | + public function getGroup(): string |
| 75 | + { |
| 76 | + return Transfer::GROUP_AUTH; |
| 77 | + } |
| 78 | + |
| 79 | + public function getEmailPassword(): bool |
| 80 | + { |
| 81 | + return $this->emailPassword; |
| 82 | + } |
| 83 | + |
| 84 | + public function getMagicURL(): bool |
| 85 | + { |
| 86 | + return $this->magicURL; |
| 87 | + } |
| 88 | + |
| 89 | + public function getEmailOtp(): bool |
| 90 | + { |
| 91 | + return $this->emailOtp; |
| 92 | + } |
| 93 | + |
| 94 | + public function getAnonymous(): bool |
| 95 | + { |
| 96 | + return $this->anonymous; |
| 97 | + } |
| 98 | + |
| 99 | + public function getInvites(): bool |
| 100 | + { |
| 101 | + return $this->invites; |
| 102 | + } |
| 103 | + |
| 104 | + public function getJwt(): bool |
| 105 | + { |
| 106 | + return $this->jwt; |
| 107 | + } |
| 108 | + |
| 109 | + public function getPhone(): bool |
| 110 | + { |
| 111 | + return $this->phone; |
| 112 | + } |
| 113 | +} |
0 commit comments