1 | <?php |
||
20 | public function __construct(array $attributes, ProviderInterface $provider = null) |
||
21 | { |
||
22 | $this->attributes = $attributes; |
||
23 | $this->provider = $provider; |
||
24 | } |
||
25 | |||
26 | public function getId() |
||
27 | { |
||
28 | return $this->getAttribute('id') ?? $this->getEmail(); |
||
29 | } |
||
30 | |||
31 | public function getNickname(): ?string |
||
32 | { |
||
33 | return $this->getAttribute('nickname') ?? $this->getName(); |
||
34 | } |
||
35 | |||
36 | public function getName(): ?string |
||
37 | { |
||
38 | return $this->getAttribute('name'); |
||
39 | } |
||
40 | |||
41 | public function getEmail(): ?string |
||
42 | { |
||
43 | return $this->getAttribute('email'); |
||
44 | } |
||
45 | |||
46 | public function getAvatar(): ?string |
||
47 | { |
||
48 | return $this->getAttribute('avatar'); |
||
49 | } |
||
50 | |||
51 | public function setAccessToken(string $token): self |
||
52 | { |
||
53 | $this->setAttribute('access_token', $token); |
||
54 | |||
55 | return $this; |
||
56 | } |
||
57 | |||
58 | public function getAccessToken(): ?string |
||
59 | { |
||
60 | return $this->getAttribute('access_token'); |
||
61 | } |
||
62 | |||
63 | public function setRefreshToken(?string $refreshToken): self |
||
64 | { |
||
65 | $this->setAttribute('refresh_token', $refreshToken); |
||
66 | |||
67 | return $this; |
||
68 | } |
||
69 | |||
70 | public function getRefreshToken(): ?string |
||
71 | { |
||
72 | return $this->getAttribute('refresh_token'); |
||
73 | } |
||
74 | |||
75 | public function setExpiresIn(int $expiresIn): self |
||
76 | { |
||
77 | $this->setAttribute('expires_in', $expiresIn); |
||
78 | |||
79 | return $this; |
||
80 | } |
||
81 | |||
82 | public function getExpiresIn(): ?int |
||
83 | { |
||
84 | return $this->getAttribute('expires_in'); |
||
85 | } |
||
86 | |||
87 | public function setRaw(array $user): self |
||
88 | { |
||
89 | $this->setAttribute('raw', $user); |
||
90 | |||
91 | return $this; |
||
92 | } |
||
93 | |||
94 | public function getRaw(): array |
||
95 | { |
||
96 | return $this->getAttribute('raw'); |
||
97 | } |
||
98 | |||
99 | public function setTokenResponse(array $response) |
||
100 | { |
||
101 | $this->setAttribute('token_response', $response); |
||
102 | |||
103 | return $this; |
||
104 | } |
||
105 | |||
106 | public function getTokenResponse() |
||
107 | { |
||
108 | return $this->getAttribute('token_response'); |
||
109 | } |
||
110 | |||
111 | public function jsonSerialize(): array |
||
112 | { |
||
113 | return $this->attributes; |
||
114 | } |
||
115 | |||
116 | public function serialize() |
||
117 | { |
||
118 | return serialize($this->attributes); |
||
119 | } |
||
120 | |||
121 | public function unserialize($serialized) |
||
122 | { |
||
123 | $this->attributes = unserialize($serialized) ?: []; |
||
124 | } |
||
125 | |||
126 | /** |
||
127 | * @return \Overtrue\Socialite\Contracts\ProviderInterface |
||
128 | */ |
||
129 | public function getProvider(): \Overtrue\Socialite\Contracts\ProviderInterface |
||
130 | { |
||
131 | return $this->provider; |
||
132 | } |
||
133 | |||
134 | /** |
||
135 | * @param \Overtrue\Socialite\Contracts\ProviderInterface $provider |
||
136 | * |
||
137 | * @return $this |
||
138 | */ |
||
139 | public function setProvider(\Overtrue\Socialite\Contracts\ProviderInterface $provider) |
||
140 | { |
||
141 | $this->provider = $provider; |
||
142 | |||
143 | return $this; |
||
144 | } |
||
145 | } |
||
146 |