| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- <?php
- namespace Overtrue\Socialite;
- use ArrayAccess;
- use JsonSerializable;
- use Overtrue\Socialite\Contracts\ProviderInterface;
- use Overtrue\Socialite\Contracts\UserInterface;
- use Overtrue\Socialite\Traits\HasAttributes;
- class User implements ArrayAccess, UserInterface, JsonSerializable, \Serializable
- {
- use HasAttributes;
- /**
- * @var \Overtrue\Socialite\Contracts\ProviderInterface|null
- */
- protected ?ProviderInterface $provider;
- public function __construct(array $attributes, ProviderInterface $provider = null)
- {
- $this->attributes = $attributes;
- $this->provider = $provider;
- }
- public function getId()
- {
- return $this->getAttribute('id') ?? $this->getEmail();
- }
- public function getNickname(): ?string
- {
- return $this->getAttribute('nickname') ?? $this->getName();
- }
- public function getName(): ?string
- {
- return $this->getAttribute('name');
- }
- public function getEmail(): ?string
- {
- return $this->getAttribute('email');
- }
- public function getAvatar(): ?string
- {
- return $this->getAttribute('avatar');
- }
- public function setAccessToken(string $token): self
- {
- $this->setAttribute('access_token', $token);
- return $this;
- }
- public function getAccessToken(): ?string
- {
- return $this->getAttribute('access_token');
- }
- public function setRefreshToken(?string $refreshToken): self
- {
- $this->setAttribute('refresh_token', $refreshToken);
- return $this;
- }
- public function getRefreshToken(): ?string
- {
- return $this->getAttribute('refresh_token');
- }
- public function setExpiresIn(int $expiresIn): self
- {
- $this->setAttribute('expires_in', $expiresIn);
- return $this;
- }
- public function getExpiresIn(): ?int
- {
- return $this->getAttribute('expires_in');
- }
- public function setRaw(array $user): self
- {
- $this->setAttribute('raw', $user);
- return $this;
- }
- public function getRaw(): array
- {
- return $this->getAttribute('raw');
- }
- public function setTokenResponse(array $response)
- {
- $this->setAttribute('token_response', $response);
- return $this;
- }
- public function getTokenResponse()
- {
- return $this->getAttribute('token_response');
- }
- public function jsonSerialize(): array
- {
- return $this->attributes;
- }
- public function serialize()
- {
- return serialize($this->attributes);
- }
- public function unserialize($serialized)
- {
- $this->attributes = unserialize($serialized) ?: [];
- }
- /**
- * @return \Overtrue\Socialite\Contracts\ProviderInterface
- */
- public function getProvider(): \Overtrue\Socialite\Contracts\ProviderInterface
- {
- return $this->provider;
- }
- /**
- * @param \Overtrue\Socialite\Contracts\ProviderInterface $provider
- *
- * @return $this
- */
- public function setProvider(\Overtrue\Socialite\Contracts\ProviderInterface $provider)
- {
- $this->provider = $provider;
- return $this;
- }
- }
|