UserInfo.php 1.07 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
<?php

declare(strict_types=1);

namespace Kreait\Firebase\Auth;

class UserInfo implements \JsonSerializable
{
    public ?string $uid = null;
    public ?string $displayName = null;
    public ?string $screenName = null;
    public ?string $email = null;
    public ?string $photoUrl = null;
    public ?string $providerId = null;
    public ?string $phoneNumber = null;

    /**
     * @param array<string, string> $data
     */
    public static function fromResponseData(array $data): self
    {
        $info = new self();
        $info->uid = $data['rawId'] ?? null;
        $info->displayName = $data['displayName'] ?? null;
        $info->screenName = $data['screenName'] ?? null;
        $info->email = $data['email'] ?? null;
        $info->photoUrl = $data['photoUrl'] ?? null;
        $info->providerId = $data['providerId'] ?? null;
        $info->phoneNumber = $data['phoneNumber'] ?? null;

        return $info;
    }

    /**
     * @return array<string, string|null>
     */
    public function jsonSerialize(): array
    {
        return \get_object_vars($this);
    }
}