2015-03-23 23:41:41 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Skobkin\Bundle\PointToolsBundle\Service;
|
|
|
|
|
2015-05-28 22:47:06 +00:00
|
|
|
use Doctrine\ORM\EntityManager;
|
|
|
|
use Doctrine\ORM\EntityRepository;
|
2017-01-08 23:26:06 +00:00
|
|
|
use GuzzleHttp\ClientInterface;
|
|
|
|
use GuzzleHttp\Exception\RequestException;
|
2017-01-05 20:17:19 +00:00
|
|
|
use JMS\Serializer\Serializer;
|
2017-01-09 01:42:06 +00:00
|
|
|
use Psr\Log\LoggerInterface;
|
2017-01-05 20:17:19 +00:00
|
|
|
use Skobkin\Bundle\PointToolsBundle\DTO\Api\Auth;
|
2015-03-23 23:41:41 +00:00
|
|
|
use Skobkin\Bundle\PointToolsBundle\Entity\User;
|
2015-10-01 18:05:11 +00:00
|
|
|
use Skobkin\Bundle\PointToolsBundle\Service\Exceptions\ApiException;
|
2015-10-05 00:59:22 +00:00
|
|
|
use Skobkin\Bundle\PointToolsBundle\Service\Exceptions\InvalidResponseException;
|
|
|
|
use Skobkin\Bundle\PointToolsBundle\Service\Exceptions\UserNotFoundException;
|
|
|
|
use Symfony\Component\HttpFoundation\Response;
|
2015-03-23 23:41:41 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Basic Point.im user API functions from /api/user/*
|
|
|
|
*/
|
|
|
|
class UserApi extends AbstractApi
|
|
|
|
{
|
2015-05-28 22:47:06 +00:00
|
|
|
const AVATAR_SIZE_SMALL = '24';
|
|
|
|
const AVATAR_SIZE_MEDIUM = '40';
|
|
|
|
const AVATAR_SIZE_LARGE = '80';
|
|
|
|
|
2015-03-23 23:41:41 +00:00
|
|
|
/**
|
|
|
|
* @var string Base URL for user avatars
|
|
|
|
*/
|
2015-10-05 00:59:22 +00:00
|
|
|
protected $avatarsBaseUrl = '//point.im/avatar/';
|
2015-05-28 22:47:06 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var EntityManager
|
|
|
|
*/
|
|
|
|
protected $em;
|
|
|
|
|
2015-10-05 01:02:06 +00:00
|
|
|
/**
|
|
|
|
* @var EntityRepository
|
|
|
|
*/
|
|
|
|
protected $userRepository;
|
|
|
|
|
2017-01-05 20:17:19 +00:00
|
|
|
/**
|
|
|
|
* @var Serializer
|
|
|
|
*/
|
|
|
|
private $serializer;
|
|
|
|
|
2017-01-09 01:42:06 +00:00
|
|
|
public function __construct(ClientInterface $httpClient, LoggerInterface $logger, EntityManager $entityManager, Serializer $serializer)
|
2015-05-28 22:47:06 +00:00
|
|
|
{
|
2017-01-09 01:42:06 +00:00
|
|
|
parent::__construct($httpClient, $logger);
|
2015-05-28 22:47:06 +00:00
|
|
|
|
|
|
|
$this->em = $entityManager;
|
2017-01-05 20:17:19 +00:00
|
|
|
$this->serializer = $serializer;
|
2015-10-05 01:02:06 +00:00
|
|
|
$this->userRepository = $this->em->getRepository('SkobkinPointToolsBundle:User');
|
2015-05-28 22:47:06 +00:00
|
|
|
}
|
2015-03-27 19:49:21 +00:00
|
|
|
|
2017-01-05 20:17:19 +00:00
|
|
|
public function isAuthDataValid(string $login, string $password): bool
|
|
|
|
{
|
2017-01-09 01:42:06 +00:00
|
|
|
$this->logger->info('Checking user auth data via point.im API');
|
|
|
|
|
2017-01-05 20:17:19 +00:00
|
|
|
$auth = $this->authenticate($login, $password);
|
|
|
|
|
2017-01-05 21:54:19 +00:00
|
|
|
if (null === $auth->getError() && null !== $auth->getToken()) {
|
2017-01-09 01:42:06 +00:00
|
|
|
$this->logger->debug('Authentication successfull. Logging out.');
|
|
|
|
|
2017-01-05 20:17:19 +00:00
|
|
|
$this->logout($auth);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function authenticate(string $login, string $password): Auth
|
|
|
|
{
|
2017-01-09 01:42:06 +00:00
|
|
|
$this->logger->debug('Trying to authenticate user via Point.im API', ['login' => $login]);
|
|
|
|
|
2017-01-05 20:17:19 +00:00
|
|
|
try {
|
|
|
|
$authData = $this->getPostRequestData(
|
|
|
|
'/api/login',
|
|
|
|
[
|
|
|
|
'login' => $login,
|
|
|
|
'password' => $password,
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
return $this->serializer->deserialize($authData, Auth::class, 'json');
|
2017-01-08 23:26:06 +00:00
|
|
|
} catch (RequestException $e) {
|
2017-01-05 20:17:19 +00:00
|
|
|
if (Response::HTTP_NOT_FOUND === $e->getResponse()->getStatusCode()) {
|
|
|
|
throw new InvalidResponseException('API method not found', 0, $e);
|
|
|
|
} else {
|
|
|
|
throw $e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function logout(Auth $auth): bool
|
|
|
|
{
|
2017-01-09 01:42:06 +00:00
|
|
|
$this->logger->debug('Trying to log user out via Point.im API');
|
|
|
|
|
2017-01-05 20:17:19 +00:00
|
|
|
try {
|
|
|
|
$this->getPostRequestData('/api/logout', ['csrf_token' => $auth->getCsRfToken()]);
|
|
|
|
|
|
|
|
return true;
|
2017-01-08 23:26:06 +00:00
|
|
|
} catch (RequestException $e) {
|
2017-01-05 20:17:19 +00:00
|
|
|
if (Response::HTTP_NOT_FOUND === $e->getResponse()->getStatusCode()) {
|
|
|
|
throw new InvalidResponseException('API method not found', 0, $e);
|
|
|
|
} elseif (Response::HTTP_FORBIDDEN === $e->getResponse()->getStatusCode()) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
throw $e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-23 23:41:41 +00:00
|
|
|
/**
|
2015-05-28 22:47:06 +00:00
|
|
|
* Get user subscribers by user login
|
2015-03-27 19:49:21 +00:00
|
|
|
*
|
2015-03-23 23:41:41 +00:00
|
|
|
* @param string $login
|
2017-01-08 23:26:06 +00:00
|
|
|
*
|
2015-03-23 23:41:41 +00:00
|
|
|
* @return User[]
|
2017-01-08 23:26:06 +00:00
|
|
|
*
|
2015-10-05 00:59:22 +00:00
|
|
|
* @throws ApiException
|
|
|
|
* @throws InvalidResponseException
|
|
|
|
* @throws UserNotFoundException
|
2015-03-23 23:41:41 +00:00
|
|
|
*/
|
2017-01-08 23:26:06 +00:00
|
|
|
public function getUserSubscribersByLogin(string $login): array
|
2015-03-23 23:41:41 +00:00
|
|
|
{
|
2017-01-09 01:42:06 +00:00
|
|
|
$this->logger->debug('Trying to get user subscribers by login', ['login' => $login]);
|
|
|
|
|
2015-10-05 00:59:22 +00:00
|
|
|
try {
|
2015-10-05 01:10:07 +00:00
|
|
|
$usersList = $this->getGetRequestData('/api/user/'.urlencode($login).'/subscribers', [], true);
|
2017-01-08 23:26:06 +00:00
|
|
|
} catch (RequestException $e) {
|
2015-10-05 00:59:22 +00:00
|
|
|
if (Response::HTTP_NOT_FOUND === $e->getResponse()->getStatusCode()) {
|
|
|
|
throw new UserNotFoundException('User not found', 0, $e, null, $login);
|
|
|
|
} else {
|
|
|
|
throw $e;
|
|
|
|
}
|
|
|
|
}
|
2015-05-28 22:47:06 +00:00
|
|
|
|
2015-10-05 00:59:22 +00:00
|
|
|
return $this->getUsersFromList($usersList);
|
2015-05-28 22:47:06 +00:00
|
|
|
}
|
|
|
|
|
2015-05-31 21:19:03 +00:00
|
|
|
/**
|
|
|
|
* Get user subscribers by user id
|
|
|
|
*
|
2017-01-08 23:26:06 +00:00
|
|
|
* @param int $id
|
|
|
|
*
|
2015-05-31 21:19:03 +00:00
|
|
|
* @return User[]
|
2017-01-08 23:26:06 +00:00
|
|
|
*
|
2015-10-05 00:59:22 +00:00
|
|
|
* @throws ApiException
|
|
|
|
* @throws InvalidResponseException
|
|
|
|
* @throws UserNotFoundException
|
2015-05-31 21:19:03 +00:00
|
|
|
*/
|
2017-01-08 23:26:06 +00:00
|
|
|
public function getUserSubscribersById(int $id): array
|
2015-05-31 21:19:03 +00:00
|
|
|
{
|
2017-01-09 01:42:06 +00:00
|
|
|
$this->logger->debug('Trying to get user subscribers by id', ['id' => $id]);
|
|
|
|
|
2015-10-05 00:59:22 +00:00
|
|
|
try {
|
|
|
|
$usersList = $this->getGetRequestData('/api/user/id/'.(int) $id.'/subscribers', [], true);
|
2017-01-08 23:26:06 +00:00
|
|
|
} catch (RequestException $e) {
|
2015-10-05 00:59:22 +00:00
|
|
|
if (Response::HTTP_NOT_FOUND === $e->getResponse()->getStatusCode()) {
|
|
|
|
throw new UserNotFoundException('User not found', 0, $e, $id);
|
|
|
|
} else {
|
|
|
|
throw $e;
|
|
|
|
}
|
|
|
|
}
|
2015-05-31 21:19:03 +00:00
|
|
|
|
2015-10-05 00:59:22 +00:00
|
|
|
return $this->getUsersFromList($usersList);
|
2015-05-31 21:19:03 +00:00
|
|
|
}
|
|
|
|
|
2015-08-08 09:22:35 +00:00
|
|
|
/**
|
|
|
|
* Get user subscriptions by user login
|
|
|
|
*
|
|
|
|
* @param string $login
|
2017-01-08 23:26:06 +00:00
|
|
|
*
|
2015-08-08 09:22:35 +00:00
|
|
|
* @return User[]
|
2017-01-08 23:26:06 +00:00
|
|
|
*
|
2015-10-05 00:59:22 +00:00
|
|
|
* @throws ApiException
|
|
|
|
* @throws InvalidResponseException
|
|
|
|
* @throws UserNotFoundException
|
2015-08-08 09:22:35 +00:00
|
|
|
*/
|
2017-01-08 23:26:06 +00:00
|
|
|
public function getUserSubscriptionsByLogin(string $login): array
|
2015-08-08 09:22:35 +00:00
|
|
|
{
|
2017-01-09 01:42:06 +00:00
|
|
|
$this->logger->debug('Trying to get user subscriptions by login', ['login' => $login]);
|
|
|
|
|
2015-10-05 00:59:22 +00:00
|
|
|
try {
|
2015-10-05 01:10:07 +00:00
|
|
|
$usersList = $this->getGetRequestData('/api/user/'.urlencode($login).'/subscriptions', [], true);
|
2017-01-08 23:26:06 +00:00
|
|
|
} catch (RequestException $e) {
|
2015-10-05 00:59:22 +00:00
|
|
|
if (Response::HTTP_NOT_FOUND === $e->getResponse()->getStatusCode()) {
|
|
|
|
throw new UserNotFoundException('User not found', 0, $e, null, $login);
|
|
|
|
} else {
|
|
|
|
throw $e;
|
|
|
|
}
|
|
|
|
}
|
2015-08-08 09:22:35 +00:00
|
|
|
|
2015-10-05 00:59:22 +00:00
|
|
|
return $this->getUsersFromList($usersList);
|
2015-08-08 09:22:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get user subscriptions by user id
|
|
|
|
*
|
2017-01-08 23:26:06 +00:00
|
|
|
* @param int $id
|
|
|
|
*
|
2015-08-08 09:22:35 +00:00
|
|
|
* @return User[]
|
2017-01-08 23:26:06 +00:00
|
|
|
*
|
2015-10-05 00:59:22 +00:00
|
|
|
* @throws ApiException
|
|
|
|
* @throws InvalidResponseException
|
|
|
|
* @throws UserNotFoundException
|
2015-08-08 09:22:35 +00:00
|
|
|
*/
|
2017-01-08 23:26:06 +00:00
|
|
|
public function getUserSubscriptionsById(int $id): array
|
2015-08-08 09:22:35 +00:00
|
|
|
{
|
2017-01-09 01:42:06 +00:00
|
|
|
$this->logger->debug('Trying to get user subscriptions by id', ['id' => $id]);
|
|
|
|
|
2015-10-05 00:59:22 +00:00
|
|
|
try {
|
|
|
|
$usersList = $this->getGetRequestData('/api/user/id/'.(int) $id.'/subscriptions', [], true);
|
2017-01-08 23:26:06 +00:00
|
|
|
} catch (RequestException $e) {
|
2015-10-05 00:59:22 +00:00
|
|
|
if (Response::HTTP_NOT_FOUND === $e->getResponse()->getStatusCode()) {
|
|
|
|
throw new UserNotFoundException('User not found', 0, $e, $id);
|
|
|
|
} else {
|
|
|
|
throw $e;
|
|
|
|
}
|
|
|
|
}
|
2015-08-08 09:22:35 +00:00
|
|
|
|
2015-10-05 00:59:22 +00:00
|
|
|
return $this->getUsersFromList($usersList);
|
|
|
|
}
|
2015-08-08 09:22:35 +00:00
|
|
|
|
2015-10-05 00:59:22 +00:00
|
|
|
/**
|
2015-10-05 01:08:01 +00:00
|
|
|
* Get single user by login
|
|
|
|
*
|
|
|
|
* @param string $login
|
2017-01-08 23:26:06 +00:00
|
|
|
*
|
2015-10-05 01:08:01 +00:00
|
|
|
* @return User
|
2017-01-08 23:26:06 +00:00
|
|
|
*
|
2015-10-05 01:08:01 +00:00
|
|
|
* @throws UserNotFoundException
|
2017-01-08 23:26:06 +00:00
|
|
|
* @throws RequestException
|
2015-10-05 01:08:01 +00:00
|
|
|
*/
|
2017-01-08 23:26:06 +00:00
|
|
|
public function getUserByLogin(string $login): User
|
2015-10-05 01:08:01 +00:00
|
|
|
{
|
2017-01-09 01:42:06 +00:00
|
|
|
$this->logger->debug('Trying to get user by login', ['login' => $login]);
|
|
|
|
|
2015-10-05 01:08:01 +00:00
|
|
|
try {
|
2015-10-05 01:10:07 +00:00
|
|
|
$userInfo = $this->getGetRequestData('/api/user/login/'.urlencode($login), [], true);
|
2017-01-08 23:26:06 +00:00
|
|
|
} catch (RequestException $e) {
|
2015-10-05 01:08:01 +00:00
|
|
|
if (Response::HTTP_NOT_FOUND === $e->getResponse()->getStatusCode()) {
|
|
|
|
throw new UserNotFoundException('User not found', 0, $e, null, $login);
|
|
|
|
} else {
|
|
|
|
throw $e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->getUserFromUserInfo($userInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get single user by id
|
2015-10-05 00:59:22 +00:00
|
|
|
*
|
2017-01-08 23:26:06 +00:00
|
|
|
* @param int $id
|
|
|
|
*
|
2015-10-05 00:59:22 +00:00
|
|
|
* @return User
|
2017-01-08 23:26:06 +00:00
|
|
|
*
|
2015-10-05 00:59:22 +00:00
|
|
|
* @throws UserNotFoundException
|
2017-01-08 23:26:06 +00:00
|
|
|
* @throws RequestException
|
2015-10-05 00:59:22 +00:00
|
|
|
*/
|
2017-01-08 23:26:06 +00:00
|
|
|
public function getUserById(int $id): User
|
2015-10-05 00:59:22 +00:00
|
|
|
{
|
2017-01-09 01:42:06 +00:00
|
|
|
$this->logger->debug('Trying to get user by id', ['id' => $id]);
|
|
|
|
|
2015-10-05 00:59:22 +00:00
|
|
|
try {
|
2017-01-08 23:26:06 +00:00
|
|
|
$userInfo = $this->getGetRequestData('/api/user/id/'.$id, [], true);
|
|
|
|
} catch (RequestException $e) {
|
2015-10-05 00:59:22 +00:00
|
|
|
if (Response::HTTP_NOT_FOUND === $e->getResponse()->getStatusCode()) {
|
|
|
|
throw new UserNotFoundException('User not found', 0, $e, $id);
|
|
|
|
} else {
|
|
|
|
throw $e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->getUserFromUserInfo($userInfo);
|
2015-08-08 09:22:35 +00:00
|
|
|
}
|
|
|
|
|
2015-05-28 22:47:06 +00:00
|
|
|
/**
|
2015-10-05 00:59:22 +00:00
|
|
|
* Finds and updates or create new user from API response data
|
|
|
|
*
|
|
|
|
* @param array $userInfo
|
2017-01-08 23:26:06 +00:00
|
|
|
*
|
2015-10-05 00:59:22 +00:00
|
|
|
* @return User
|
2017-01-08 23:26:06 +00:00
|
|
|
*
|
2015-10-05 00:59:22 +00:00
|
|
|
* @throws ApiException
|
|
|
|
* @throws InvalidResponseException
|
|
|
|
*/
|
2017-01-08 23:26:06 +00:00
|
|
|
public function getUserFromUserInfo(array $userInfo): User
|
2015-10-05 00:59:22 +00:00
|
|
|
{
|
2017-01-09 01:42:06 +00:00
|
|
|
$this->logger->debug('Trying to create user from array', ['array' => $userInfo]);
|
|
|
|
|
2015-10-26 03:00:39 +00:00
|
|
|
// @todo Refactor to UserFactory->createFromArray()
|
2015-10-05 00:59:22 +00:00
|
|
|
if (array_key_exists('id', $userInfo) && array_key_exists('login', $userInfo) && array_key_exists('name', $userInfo) && is_numeric($userInfo['id'])) {
|
|
|
|
/** @var User $user */
|
2015-10-05 01:02:06 +00:00
|
|
|
if (null === ($user = $this->userRepository->find($userInfo['id']))) {
|
2015-10-05 00:59:22 +00:00
|
|
|
// Creating new user
|
|
|
|
$user = new User($userInfo['id']);
|
|
|
|
$this->em->persist($user);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Updating data
|
|
|
|
$user
|
|
|
|
->setLogin($userInfo['login'])
|
|
|
|
->setName($userInfo['name'])
|
|
|
|
;
|
|
|
|
|
|
|
|
return $user;
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new InvalidResponseException('Invalid API response. Mandatory fields do not exist.');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get array of User objects from API response containing user list
|
|
|
|
*
|
2017-01-09 01:42:06 +00:00
|
|
|
* @todo refactor
|
|
|
|
*
|
2015-10-05 00:59:22 +00:00
|
|
|
* @param array $users
|
2017-01-08 23:26:06 +00:00
|
|
|
*
|
2015-05-28 22:47:06 +00:00
|
|
|
* @return User[]
|
2017-01-08 23:26:06 +00:00
|
|
|
*
|
2015-10-05 00:59:22 +00:00
|
|
|
* @throws ApiException
|
|
|
|
* @throws InvalidResponseException
|
2015-05-28 22:47:06 +00:00
|
|
|
*/
|
2017-01-08 23:26:06 +00:00
|
|
|
private function getUsersFromList(array $users = []): array
|
2015-05-28 22:47:06 +00:00
|
|
|
{
|
2017-01-09 01:42:06 +00:00
|
|
|
$this->logger->debug('Trying to create multiple users from array', ['array' => $users]);
|
|
|
|
|
2015-10-05 00:59:22 +00:00
|
|
|
/** @var User[] $resultUsers */
|
2015-05-28 22:47:06 +00:00
|
|
|
$resultUsers = [];
|
2015-03-27 19:49:21 +00:00
|
|
|
|
2015-10-05 00:59:22 +00:00
|
|
|
foreach ($users as $userInfo) {
|
|
|
|
if (array_key_exists('id', $userInfo) && array_key_exists('login', $userInfo) && array_key_exists('name', $userInfo) && is_numeric($userInfo['id'])) {
|
2015-03-27 19:49:21 +00:00
|
|
|
|
2015-05-28 22:47:06 +00:00
|
|
|
// @todo Optimize with prehashed id's list
|
2015-10-05 01:02:06 +00:00
|
|
|
if (null === ($user = $this->userRepository->find($userInfo['id']))) {
|
2015-10-05 00:59:22 +00:00
|
|
|
$user = new User((int) $userInfo['id']);
|
2015-05-28 22:47:06 +00:00
|
|
|
$this->em->persist($user);
|
|
|
|
}
|
2015-03-27 19:49:21 +00:00
|
|
|
|
2015-05-28 22:47:06 +00:00
|
|
|
// Updating data
|
2015-10-05 00:59:22 +00:00
|
|
|
$user
|
|
|
|
->setLogin($userInfo['login'])
|
|
|
|
->setName($userInfo['name'])
|
|
|
|
;
|
2015-03-27 19:49:21 +00:00
|
|
|
|
2015-05-28 22:47:06 +00:00
|
|
|
$resultUsers[] = $user;
|
2015-10-05 00:59:22 +00:00
|
|
|
} else {
|
|
|
|
throw new InvalidResponseException('Invalid API response. Mandatory fields do not exist.');
|
2015-03-23 23:41:41 +00:00
|
|
|
}
|
|
|
|
}
|
2015-03-27 19:49:21 +00:00
|
|
|
|
2015-05-28 22:47:06 +00:00
|
|
|
return $resultUsers;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-03-29 04:07:58 +00:00
|
|
|
* Creates URL of avatar with specified size by User object
|
2015-10-05 00:59:22 +00:00
|
|
|
*
|
|
|
|
* @param User $user
|
2017-01-08 23:26:06 +00:00
|
|
|
* @param string $size
|
|
|
|
*
|
2015-10-05 00:59:22 +00:00
|
|
|
* @return string
|
2015-05-28 22:47:06 +00:00
|
|
|
*/
|
2017-01-08 23:26:06 +00:00
|
|
|
public function getAvatarUrl(User $user, string $size): string
|
2016-03-29 04:07:58 +00:00
|
|
|
{
|
|
|
|
return $this->getAvatarUrlByLogin($user->getLogin(), $size);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates URL of avatar with specified size by login string
|
|
|
|
*
|
2017-01-08 23:26:06 +00:00
|
|
|
* @param string $login
|
|
|
|
* @param string $size
|
2016-03-29 04:07:58 +00:00
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2017-01-08 23:26:06 +00:00
|
|
|
public function getAvatarUrlByLogin(string $login, string $size): string
|
2015-05-28 22:47:06 +00:00
|
|
|
{
|
2015-10-05 00:59:22 +00:00
|
|
|
if (!in_array($size, [self::AVATAR_SIZE_SMALL, self::AVATAR_SIZE_MEDIUM, self::AVATAR_SIZE_LARGE], true)) {
|
|
|
|
throw new \InvalidArgumentException('Avatar size must be one of restricted variants. See UserApi class AVATAR_SIZE_* constants.');
|
|
|
|
}
|
|
|
|
|
2016-03-29 04:07:58 +00:00
|
|
|
return $this->avatarsBaseUrl.urlencode($login).'/'.$size;
|
2015-03-23 23:41:41 +00:00
|
|
|
}
|
|
|
|
}
|