Compare commits
2 commits
8a9a5028dc
...
690b849ca6
Author | SHA1 | Date | |
---|---|---|---|
690b849ca6 | |||
50d56f0007 |
|
@ -15,6 +15,8 @@ services:
|
|||
# Telegram Bot API
|
||||
$telegramToken: ''
|
||||
# Point API
|
||||
$pointDomain: 'point.im'
|
||||
$pointScheme: 'https'
|
||||
$pointApiDelay: ''
|
||||
$pointAppUserId: ''
|
||||
$pointApiClient: '@app.point.http_client'
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
[ ![Codeship Status for skobkin/point-tools](https://app.codeship.com/projects/bb9fe730-a175-0134-5572-12490b0b4938/status?branch=master)](https://app.codeship.com/projects/189850)
|
||||
[![Build Status](https://ci.skobk.in/api/badges/skobkin/point-tools/status.svg)](https://ci.skobk.in/skobkin/point-tools)
|
||||
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/b/skobkin/point-tools/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/b/skobkin/point-tools/?branch=master)
|
||||
[![codecov](https://codecov.io/bb/skobkin/point-tools/branch/master/graph/badge.svg)](https://codecov.io/bb/skobkin/point-tools)
|
||||
[![Total Downloads](https://poser.pugx.org/skobkin/point-tools/downloads)](https://packagist.org/packages/skobkin/point-tools)
|
||||
[![License](https://poser.pugx.org/skobkin/point-tools/license)](https://packagist.org/packages/skobkin/point-tools)
|
||||
|
||||
# Point Tools
|
||||
|
|
|
@ -1,100 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace src\PointToolsBundle\Twig;
|
||||
|
||||
use src\PointToolsBundle\Entity\User;
|
||||
|
||||
class PointUrlExtension extends \Twig_Extension
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $pointDomain;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $pointScheme;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $pointBaseUrl;
|
||||
|
||||
public function __construct(string $pointDomain, string $pointScheme, string $pointBaseUrl)
|
||||
{
|
||||
$this->pointDomain = $pointDomain;
|
||||
$this->pointScheme = $pointScheme;
|
||||
$this->pointBaseUrl = $pointBaseUrl;
|
||||
}
|
||||
|
||||
public function getFunctions()
|
||||
{
|
||||
return [
|
||||
new \Twig_SimpleFunction('point_avatar', [$this, 'avatarFunction']),
|
||||
new \Twig_SimpleFunction('point_avatar_small', [$this, 'avatarSmallFunction']),
|
||||
new \Twig_SimpleFunction('point_avatar_medium', [$this, 'avatarMediumFunction']),
|
||||
new \Twig_SimpleFunction('point_avatar_large', [$this, 'avatarLargeFunction']),
|
||||
new \Twig_SimpleFunction('point_user_url', [$this, 'userUrl']),
|
||||
new \Twig_SimpleFunction('point_user_blog_url', [$this, 'userBlogUrl']),
|
||||
new \Twig_SimpleFunction('point_post_url', [$this, 'postUrl']),
|
||||
];
|
||||
}
|
||||
|
||||
public function getFilters()
|
||||
{
|
||||
return [
|
||||
new \Twig_SimpleFilter('point_avatar', [$this, 'avatarFunction']),
|
||||
new \Twig_SimpleFilter('point_avatar_small', [$this, 'avatarSmallFunction']),
|
||||
new \Twig_SimpleFilter('point_avatar_medium', [$this, 'avatarMediumFunction']),
|
||||
new \Twig_SimpleFilter('point_avatar_large', [$this, 'avatarLargeFunction']),
|
||||
new \Twig_SimpleFilter('point_user_url', [$this, 'userUrl']),
|
||||
new \Twig_SimpleFilter('point_user_blog_url', [$this, 'userBlogUrl']),
|
||||
new \Twig_SimpleFilter('point_post_url', [$this, 'postUrl']),
|
||||
];
|
||||
}
|
||||
|
||||
public function avatarSmallFunction(string $login): string
|
||||
{
|
||||
return $this->avatarFunction($login, User::AVATAR_SIZE_SMALL);
|
||||
}
|
||||
|
||||
public function avatarMediumFunction(string $login): string
|
||||
{
|
||||
return $this->avatarFunction($login, User::AVATAR_SIZE_MEDIUM);
|
||||
}
|
||||
|
||||
public function avatarLargeFunction(string $login): string
|
||||
{
|
||||
return $this->avatarFunction($login, User::AVATAR_SIZE_LARGE);
|
||||
}
|
||||
|
||||
public function avatarFunction(string $login, $size): string
|
||||
{
|
||||
return $this->getAvatarUrlByLogin($login, $size);
|
||||
}
|
||||
|
||||
public function userUrl(string $login): string
|
||||
{
|
||||
return sprintf('%s://%s.%s/', $this->pointScheme, $login, $this->pointDomain);
|
||||
}
|
||||
|
||||
public function userBlogUrl(string $login): string
|
||||
{
|
||||
return sprintf('%s://%s.%s/blog/', $this->pointScheme, $login, $this->pointDomain);
|
||||
}
|
||||
|
||||
public function postUrl(string $postId): string
|
||||
{
|
||||
return sprintf('%s://%s/%s', $this->pointScheme, $this->pointDomain, $postId);
|
||||
}
|
||||
|
||||
private function getAvatarUrlByLogin(string $login, string $size): string
|
||||
{
|
||||
if (!in_array($size, [User::AVATAR_SIZE_SMALL, User::AVATAR_SIZE_MEDIUM, User::AVATAR_SIZE_LARGE], true)) {
|
||||
throw new \InvalidArgumentException('Avatar size must be one of restricted variants. See User::AVATAR_SIZE_* constants.');
|
||||
}
|
||||
|
||||
return sprintf('%s://%s/avatar/%s/%s', $this->pointScheme, $this->pointDomain, urlencode($login), $size);
|
||||
}
|
||||
}
|
88
src/Twig/PointUrlExtension.php
Normal file
88
src/Twig/PointUrlExtension.php
Normal file
|
@ -0,0 +1,88 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Twig;
|
||||
|
||||
use App\Entity\User;
|
||||
use Twig\Extension\AbstractExtension;
|
||||
use Twig\TwigFilter;
|
||||
use Twig\TwigFunction;
|
||||
|
||||
class PointUrlExtension extends AbstractExtension
|
||||
{
|
||||
public function __construct(
|
||||
private readonly string $pointDomain,
|
||||
private readonly string $pointScheme,
|
||||
) {
|
||||
}
|
||||
|
||||
public function getFunctions()
|
||||
{
|
||||
return [
|
||||
new TwigFunction('point_avatar', [$this, 'avatarFunction']),
|
||||
new TwigFunction('point_avatar_small', [$this, 'avatarSmallFunction']),
|
||||
new TwigFunction('point_avatar_medium', [$this, 'avatarMediumFunction']),
|
||||
new TwigFunction('point_avatar_large', [$this, 'avatarLargeFunction']),
|
||||
new TwigFunction('point_user_url', [$this, 'userUrl']),
|
||||
new TwigFunction('point_user_blog_url', [$this, 'userBlogUrl']),
|
||||
new TwigFunction('point_post_url', [$this, 'postUrl']),
|
||||
];
|
||||
}
|
||||
|
||||
public function getFilters()
|
||||
{
|
||||
return [
|
||||
new TwigFilter('point_avatar', [$this, 'avatarFunction']),
|
||||
new TwigFilter('point_avatar_small', [$this, 'avatarSmallFunction']),
|
||||
new TwigFilter('point_avatar_medium', [$this, 'avatarMediumFunction']),
|
||||
new TwigFilter('point_avatar_large', [$this, 'avatarLargeFunction']),
|
||||
new TwigFilter('point_user_url', [$this, 'userUrl']),
|
||||
new TwigFilter('point_user_blog_url', [$this, 'userBlogUrl']),
|
||||
new TwigFilter('point_post_url', [$this, 'postUrl']),
|
||||
];
|
||||
}
|
||||
|
||||
public function avatarSmallFunction(string $login): string
|
||||
{
|
||||
return $this->avatarFunction($login, User::AVATAR_SIZE_SMALL);
|
||||
}
|
||||
|
||||
public function avatarMediumFunction(string $login): string
|
||||
{
|
||||
return $this->avatarFunction($login, User::AVATAR_SIZE_MEDIUM);
|
||||
}
|
||||
|
||||
public function avatarLargeFunction(string $login): string
|
||||
{
|
||||
return $this->avatarFunction($login, User::AVATAR_SIZE_LARGE);
|
||||
}
|
||||
|
||||
public function avatarFunction(string $login, $size): string
|
||||
{
|
||||
return $this->getAvatarUrlByLogin($login, $size);
|
||||
}
|
||||
|
||||
public function userUrl(string $login): string
|
||||
{
|
||||
return sprintf('%s://%s.%s/', $this->pointScheme, $login, $this->pointDomain);
|
||||
}
|
||||
|
||||
public function userBlogUrl(string $login): string
|
||||
{
|
||||
return sprintf('%s://%s.%s/blog/', $this->pointScheme, $login, $this->pointDomain);
|
||||
}
|
||||
|
||||
public function postUrl(string $postId): string
|
||||
{
|
||||
return sprintf('%s://%s/%s', $this->pointScheme, $this->pointDomain, $postId);
|
||||
}
|
||||
|
||||
private function getAvatarUrlByLogin(string $login, string $size): string
|
||||
{
|
||||
if (!in_array($size, [User::AVATAR_SIZE_SMALL, User::AVATAR_SIZE_MEDIUM, User::AVATAR_SIZE_LARGE], true)) {
|
||||
throw new \InvalidArgumentException('Avatar size must be one of restricted variants. See User::AVATAR_SIZE_* constants.');
|
||||
}
|
||||
|
||||
return sprintf('%s://%s/avatar/%s/%s', $this->pointScheme, $this->pointDomain, urlencode($login), $size);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue