|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Utopia\Migration\Resources\Backups; |
| 4 | + |
| 5 | +use Utopia\Migration\Resource; |
| 6 | +use Utopia\Migration\Transfer; |
| 7 | + |
| 8 | +class Policy extends Resource |
| 9 | +{ |
| 10 | + /** |
| 11 | + * @param string $id |
| 12 | + * @param string $name |
| 13 | + * @param array<string> $services |
| 14 | + * @param int $retention |
| 15 | + * @param string $schedule |
| 16 | + * @param bool $enabled |
| 17 | + * @param string $resourceId |
| 18 | + * @param string $resourceType |
| 19 | + */ |
| 20 | + public function __construct( |
| 21 | + string $id = '', |
| 22 | + private readonly string $name = '', |
| 23 | + private readonly array $services = [], |
| 24 | + private readonly int $retention = 0, |
| 25 | + private readonly string $schedule = '', |
| 26 | + private readonly bool $enabled = true, |
| 27 | + private readonly string $resourceId = '', |
| 28 | + private readonly string $resourceType = '', |
| 29 | + ) { |
| 30 | + $this->id = $id; |
| 31 | + } |
| 32 | + |
| 33 | + /** |
| 34 | + * @param array<string, mixed> $array |
| 35 | + * @return self |
| 36 | + */ |
| 37 | + public static function fromArray(array $array): self |
| 38 | + { |
| 39 | + return new self( |
| 40 | + $array['id'], |
| 41 | + $array['name'] ?? '', |
| 42 | + $array['services'] ?? [], |
| 43 | + $array['retention'] ?? 0, |
| 44 | + $array['schedule'] ?? '', |
| 45 | + $array['enabled'] ?? true, |
| 46 | + $array['resourceId'] ?? '', |
| 47 | + $array['resourceType'] ?? '', |
| 48 | + ); |
| 49 | + } |
| 50 | + |
| 51 | + /** |
| 52 | + * @return array<string, mixed> |
| 53 | + */ |
| 54 | + public function jsonSerialize(): array |
| 55 | + { |
| 56 | + return [ |
| 57 | + 'id' => $this->id, |
| 58 | + 'name' => $this->name, |
| 59 | + 'services' => $this->services, |
| 60 | + 'retention' => $this->retention, |
| 61 | + 'schedule' => $this->schedule, |
| 62 | + 'enabled' => $this->enabled, |
| 63 | + 'resourceId' => $this->resourceId, |
| 64 | + 'resourceType' => $this->resourceType, |
| 65 | + ]; |
| 66 | + } |
| 67 | + |
| 68 | + public static function getName(): string |
| 69 | + { |
| 70 | + return Resource::TYPE_BACKUP_POLICY; |
| 71 | + } |
| 72 | + |
| 73 | + public function getGroup(): string |
| 74 | + { |
| 75 | + return Transfer::GROUP_BACKUPS; |
| 76 | + } |
| 77 | + |
| 78 | + public function getPolicyName(): string |
| 79 | + { |
| 80 | + return $this->name; |
| 81 | + } |
| 82 | + |
| 83 | + /** |
| 84 | + * @return array<string> |
| 85 | + */ |
| 86 | + public function getServices(): array |
| 87 | + { |
| 88 | + return $this->services; |
| 89 | + } |
| 90 | + |
| 91 | + public function getRetention(): int |
| 92 | + { |
| 93 | + return $this->retention; |
| 94 | + } |
| 95 | + |
| 96 | + public function getSchedule(): string |
| 97 | + { |
| 98 | + return $this->schedule; |
| 99 | + } |
| 100 | + |
| 101 | + public function getEnabled(): bool |
| 102 | + { |
| 103 | + return $this->enabled; |
| 104 | + } |
| 105 | + |
| 106 | + public function getResourceId(): string |
| 107 | + { |
| 108 | + return $this->resourceId; |
| 109 | + } |
| 110 | + |
| 111 | + public function getResourceType(): string |
| 112 | + { |
| 113 | + return $this->resourceType; |
| 114 | + } |
| 115 | +} |
0 commit comments