Version.php 2.67 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
<?php

declare(strict_types=1);

namespace Kreait\Firebase\RemoteConfig;

use Kreait\Firebase\Util\DT;

final class Version
{
    private VersionNumber $versionNumber;
    private User $user;
    private \DateTimeImmutable $updatedAt;
    private string $description;
    private UpdateOrigin $updateOrigin;
    private UpdateType $updateType;
    private ?VersionNumber $rollbackSource;

    private function __construct(
        VersionNumber $versionNumber,
        User $user,
        string $description,
        \DateTimeImmutable $updatedAt,
        UpdateOrigin $updateOrigin,
        UpdateType $updateType,
        ?VersionNumber $rollbackSource
    ) {
        $this->versionNumber = $versionNumber;
        $this->user = $user;
        $this->description = $description;
        $this->updatedAt = $updatedAt;
        $this->updateOrigin = $updateOrigin;
        $this->updateType = $updateType;
        $this->rollbackSource = $rollbackSource;
    }

    /**
     * @internal
     *
     * @param array<string, mixed> $data
     */
    public static function fromArray(array $data): self
    {
        $versionNumber = VersionNumber::fromValue($data['versionNumber']);
        $user = User::fromArray($data['updateUser']);
        $updatedAt = DT::toUTCDateTimeImmutable($data['updateTime']);
        $description = $data['description'] ?? '';

        $updateOrigin = ($data['updateOrigin'] ?? null)
            ? UpdateOrigin::fromValue($data['updateOrigin'])
            : UpdateOrigin::fromValue(UpdateOrigin::UNSPECIFIED);

        $updateType = ($data['updateType'] ?? null)
            ? UpdateType::fromValue($data['updateType'])
            : UpdateType::fromValue(UpdateType::UNSPECIFIED);

        $rollbackSource = ($data['rollbackSource'] ?? null)
            ? VersionNumber::fromValue($data['rollbackSource'])
            : null;

        return new self(
            $versionNumber,
            $user,
            $description,
            $updatedAt,
            $updateOrigin,
            $updateType,
            $rollbackSource
        );
    }

    public function versionNumber(): VersionNumber
    {
        return $this->versionNumber;
    }

    public function user(): User
    {
        return $this->user;
    }

    public function updatedAt(): \DateTimeImmutable
    {
        return $this->updatedAt;
    }

    public function description(): string
    {
        return $this->description;
    }

    public function updateOrigin(): UpdateOrigin
    {
        return $this->updateOrigin;
    }

    public function updateType(): UpdateType
    {
        return $this->updateType;
    }

    public function rollbackSource(): ?VersionNumber
    {
        return $this->rollbackSource;
    }
}