Update VkUser.php

This commit is contained in:
2025-01-11 02:05:15 +03:00
parent b7fce352c9
commit 42969feac6
2 changed files with 52 additions and 10 deletions

View File

@@ -1,6 +1,6 @@
{ {
"name": "1sept/oauth2-vkontakte", "name": "1sept/oauth2-vkontakte",
"version": "2.1.1", "version": "2.1.2",
"description": "VK provider for league/oauth2-client", "description": "VK provider for league/oauth2-client",
"keywords": [ "keywords": [
"league", "league",

View File

@@ -11,10 +11,7 @@ use League\OAuth2\Client\Provider\ResourceOwnerInterface;
*/ */
class VkUser implements ResourceOwnerInterface class VkUser implements ResourceOwnerInterface
{ {
/** protected array $response;
* @var array
*/
protected $response;
/** /**
* User constructor. * User constructor.
@@ -24,11 +21,17 @@ class VkUser implements ResourceOwnerInterface
$this->response = $response; $this->response = $response;
} }
/**
* Вернуть все поля массивом
*/
public function toArray(): array public function toArray(): array
{ {
return $this->response; return $this->response;
} }
/**
* Идентификатор пользователя.
*/
public function getId(): int public function getId(): int
{ {
return (int) ((bool) $this->getField('uid') ? $this->getField('uid') : $this->getField('id')); return (int) ((bool) $this->getField('uid') ? $this->getField('uid') : $this->getField('id'));
@@ -43,7 +46,7 @@ class VkUser implements ResourceOwnerInterface
} }
/** /**
* Дата рождения. Возвращается в формате D.M.YYYY или D.M (если год рождения скрыт). Если дата рождения скрыта целиком, поле отсутствует в ответе * Дата рождения. Возвращается в формате D.M.YYYY или D.M (если год рождения скрыт). Если дата рождения скрыта целиком, поле отсутствует в ответе.
* *
* @return string|null DD.MM.YYYY * @return string|null DD.MM.YYYY
*/ */
@@ -53,6 +56,10 @@ class VkUser implements ResourceOwnerInterface
} }
/** /**
* Информация о городе, указанном на странице пользователя в разделе «Контакты». Возвращаются следующие поля:
* id (integer) — идентификатор города, который можно использовать для получения его названия с помощью метода database.getCitiesById;
* title (string) — название города.
*
* @return array [id =>, title => string] * @return array [id =>, title => string]
*/ */
public function getCity(): ?array public function getCity(): ?array
@@ -61,6 +68,10 @@ class VkUser implements ResourceOwnerInterface
} }
/** /**
* Информация о стране, указанной на странице пользователя в разделе «Контакты». Возвращаются следующие поля:
* id (integer) — идентификатор страны, который можно использовать для получения ее названия с помощью метода database.getCountriesById;
* title (string) — название страны.
*
* @return array [id =>, title => string] * @return array [id =>, title => string]
*/ */
public function getCountry(): ?array public function getCountry(): ?array
@@ -69,6 +80,9 @@ class VkUser implements ResourceOwnerInterface
} }
/** /**
* Короткий адрес страницы. Возвращается строка, содержащая короткий адрес страницы (например, andrew).
* Если он не назначен, возвращается "id"+user_id, например, id35828305.
*
* Short address to user page. * Short address to user page.
*/ */
public function getDomain(): ?string public function getDomain(): ?string
@@ -77,7 +91,7 @@ class VkUser implements ResourceOwnerInterface
} }
/** /**
* Return firstname. * Имя.
*/ */
public function getFirstName(): ?string public function getFirstName(): ?string
{ {
@@ -95,13 +109,16 @@ class VkUser implements ResourceOwnerInterface
} }
/** /**
* Has user avatar? * Информация о том, установил ли пользователь фотографию для профиля. Возвращаемые значения: 1 — установил, 0 — не установил.
*/ */
public function isHasPhoto(): bool public function isHasPhoto(): bool
{ {
return (bool) $this->getField('has_photo'); return (bool) $this->getField('has_photo');
} }
/**
* Название родного города.
*/
public function getHomeTown(): ?string public function getHomeTown(): ?string
{ {
return $this->getField('home_town'); return $this->getField('home_town');
@@ -115,39 +132,64 @@ class VkUser implements ResourceOwnerInterface
return (bool) $this->getField('is_friend'); return (bool) $this->getField('is_friend');
} }
/**
* Фамилия.
*/
public function getLastName(): ?string public function getLastName(): ?string
{ {
return $this->getField('last_name'); return $this->getField('last_name');
} }
/**
* Девичья фамилия.
*/
public function getMaidenName(): ?string public function getMaidenName(): ?string
{ {
return $this->getField('maiden_name'); return $this->getField('maiden_name');
} }
/**
* Никнейм (отчество) пользователя.
*/
public function getNickname(): ?string public function getNickname(): ?string
{ {
return $this->getField('nickname'); return $this->getField('nickname');
} }
/** /**
* It's square! * URL квадратной фотографии с максимальной шириной.
* Может быть возвращена фотография, имеющая ширину как 200, так и 100 пикселей.
* В случае отсутствия у пользователя фотографии возвращается https://vk.com/images/camera_200.png.
*/ */
public function getPhotoMax(): ?string public function getPhotoMax(): ?string
{ {
return $this->getField('photo_max'); return $this->getField('photo_max');
} }
/**
* URL фотографии максимального размера. Может быть возвращена фотография,
* имеющая ширину как 400, так и 200 пикселей.
* В случае отсутствия у пользователя фотографии возвращается https://vk.com/images/camera_400.png.
*/
public function getPhotoMaxOrig(): ?string public function getPhotoMaxOrig(): ?string
{ {
return $this->getField('photo_max_orig'); return $this->getField('photo_max_orig');
} }
/**
* Короткое имя страницы.
*/
public function getScreenName(): ?string public function getScreenName(): ?string
{ {
return $this->getField('screen_name'); return $this->getField('screen_name');
} }
/**
* Пол. Возможные значения
* 1 — женский;
* 2 — мужской;
* 0 — пол не указан.
*/
public function getSex(): ?int public function getSex(): ?int
{ {
return $this->getField('sex'); return $this->getField('sex');