Deal with situation when friends.get return only ids (integers, not objects) – only when no fields-option was passed

This commit is contained in:
trogwar
2016-07-01 18:16:46 +03:00
committed by Jack Wall
parent 5596bc7350
commit 54e16ad046
2 changed files with 5 additions and 11 deletions

View File

@@ -11,8 +11,6 @@ use League\OAuth2\Client\Provider\ResourceOwnerInterface;
*/
class User implements ResourceOwnerInterface
{
// ========== Interface ==========
/**
* @type array
*/
@@ -42,8 +40,6 @@ class User implements ResourceOwnerInterface
return (int)($this->getField('uid') ?: $this->getField('id'));
}
// ========== helpers ==========
/**
* Helper for getting user data
*
@@ -56,8 +52,6 @@ class User implements ResourceOwnerInterface
return !empty($this->response[$key]) ? $this->response[$key] : null;
}
// ========== Getters for default scope ==========
/**
* @return string|null DD.MM.YYYY
*/

View File

@@ -111,8 +111,6 @@ class Vkontakte extends AbstractProvider
//'wall_comments',
];
// ========== Abstract ==========
public function getBaseAuthorizationUrl()
{
return "$this->baseOAuthUri/authorize";
@@ -173,8 +171,6 @@ class Vkontakte extends AbstractProvider
return new User($response, $response['id']);
}
// ========== API methods ==========
/**
* @see https://vk.com/dev/users.get
*
@@ -228,7 +224,11 @@ class Vkontakte extends AbstractProvider
$response = $this->getResponse($this->createRequest(static::METHOD_GET, $url, $token, []))['response'];
$friends = !empty($response['items']) ? $response['items'] : $response;
$array2friend = function ($friendData) { return new User($friendData); };
$array2friend = function ($friendData) {
if (is_numeric($friendData)) $friendData = ['id' => $friendData];
return new User($friendData);
};
return array_map($array2friend, $friends);
}