Compare commits
No commits in common. "b413934d352dcebb448e221b069586a5b9e52699" and "c2fb2b6dfc69aca1f9b7916524adbf2d79219e52" have entirely different histories.
b413934d35
...
c2fb2b6dfc
|
@ -3,7 +3,6 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace App\DataFixtures;
|
namespace App\DataFixtures;
|
||||||
|
|
||||||
use App\Enum\Blog\PostTypeEnum;
|
|
||||||
use Doctrine\Bundle\FixturesBundle\Fixture;
|
use Doctrine\Bundle\FixturesBundle\Fixture;
|
||||||
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
|
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
|
||||||
use Doctrine\Persistence\ObjectManager;
|
use Doctrine\Persistence\ObjectManager;
|
||||||
|
@ -29,31 +28,31 @@ class LoadPostData extends Fixture implements OrderedFixtureInterface
|
||||||
/** @var User $prWlUser */
|
/** @var User $prWlUser */
|
||||||
$prWlUser = $this->getReference('test_user_'.LoadUserData::USER_PRWL_ID);
|
$prWlUser = $this->getReference('test_user_'.LoadUserData::USER_PRWL_ID);
|
||||||
|
|
||||||
$longPost = (new Post(self::POST_ID_LONG, $mainUser, new \DateTime(), PostTypeEnum::Post))
|
$longPost = (new Post(self::POST_ID_LONG, $mainUser, new \DateTime(), Post::TYPE_POST))
|
||||||
->setText('Test post with many comments')
|
->setText('Test post with many comments')
|
||||||
->setPrivate(false)
|
->setPrivate(false)
|
||||||
->setDeleted(false)
|
->setDeleted(false)
|
||||||
;
|
;
|
||||||
|
|
||||||
$shortPost = (new Post(self::POST_ID_SHORT, $mainUser, new \DateTime(), PostTypeEnum::Post))
|
$shortPost = (new Post(self::POST_ID_SHORT, $mainUser, new \DateTime(), Post::TYPE_POST))
|
||||||
->setText('Test short post')
|
->setText('Test short post')
|
||||||
->setPrivate(false)
|
->setPrivate(false)
|
||||||
->setDeleted(false)
|
->setDeleted(false)
|
||||||
;
|
;
|
||||||
|
|
||||||
$privateUserPost = (new Post(self::POST_ID_PR_USER, $privateUser, new \DateTime(), PostTypeEnum::Post))
|
$privateUserPost = (new Post(self::POST_ID_PR_USER, $privateUser, new \DateTime(), Post::TYPE_POST))
|
||||||
->setText('Post from private user. Should not be visible in the public feed.')
|
->setText('Post from private user. Should not be visible in the public feed.')
|
||||||
->setPrivate(false)
|
->setPrivate(false)
|
||||||
->setDeleted(false)
|
->setDeleted(false)
|
||||||
;
|
;
|
||||||
|
|
||||||
$wlUserPost = (new Post(self::POST_ID_WL_USER, $wlUser, new \DateTime(), PostTypeEnum::Post))
|
$wlUserPost = (new Post(self::POST_ID_WL_USER, $wlUser, new \DateTime(), Post::TYPE_POST))
|
||||||
->setText('Post from whitelist-only user. Should only be visible for whitelisted users.')
|
->setText('Post from whitelist-only user. Should only be visible for whitelisted users.')
|
||||||
->setPrivate(false)
|
->setPrivate(false)
|
||||||
->setDeleted(false)
|
->setDeleted(false)
|
||||||
;
|
;
|
||||||
|
|
||||||
$privateWlUserPost = (new Post(self::POST_ID_PR_WL_USER, $prWlUser, new \DateTime(), PostTypeEnum::Post))
|
$privateWlUserPost = (new Post(self::POST_ID_PR_WL_USER, $prWlUser, new \DateTime(), Post::TYPE_POST))
|
||||||
->setText('Post from private AND whitelist-only user. Should not be visible in the public feed.')
|
->setText('Post from private AND whitelist-only user. Should not be visible in the public feed.')
|
||||||
->setPrivate(false)
|
->setPrivate(false)
|
||||||
->setDeleted(false)
|
->setDeleted(false)
|
||||||
|
|
|
@ -4,9 +4,9 @@ declare(strict_types=1);
|
||||||
namespace App\Entity\Blog;
|
namespace App\Entity\Blog;
|
||||||
|
|
||||||
use App\Entity\User;
|
use App\Entity\User;
|
||||||
use App\Enum\Blog\PostTypeEnum;
|
|
||||||
use App\Repository\Blog\TagRepository;
|
use App\Repository\Blog\TagRepository;
|
||||||
use Doctrine\Common\Collections\{ArrayCollection, Collection};
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
|
use Doctrine\Common\Collections\Collection;
|
||||||
use Doctrine\ORM\Mapping as ORM;
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
|
|
||||||
#[ORM\Entity(repositoryClass: TagRepository::class)]
|
#[ORM\Entity(repositoryClass: TagRepository::class)]
|
||||||
|
@ -14,6 +14,9 @@ use Doctrine\ORM\Mapping as ORM;
|
||||||
#[ORM\Table(name: 'tags', schema: 'posts')]
|
#[ORM\Table(name: 'tags', schema: 'posts')]
|
||||||
class Post
|
class Post
|
||||||
{
|
{
|
||||||
|
public const TYPE_POST = 'post';
|
||||||
|
public const TYPE_FEED = 'feed';
|
||||||
|
|
||||||
#[ORM\Id]
|
#[ORM\Id]
|
||||||
#[ORM\Column(name: 'id', type: 'text')]
|
#[ORM\Column(name: 'id', type: 'text')]
|
||||||
private string $id;
|
private string $id;
|
||||||
|
@ -27,8 +30,9 @@ class Post
|
||||||
#[ORM\Column(name: 'updated_at', type: 'datetime', nullable: true)]
|
#[ORM\Column(name: 'updated_at', type: 'datetime', nullable: true)]
|
||||||
private ?\DateTime $updatedAt;
|
private ?\DateTime $updatedAt;
|
||||||
|
|
||||||
#[ORM\Column(name: 'type', type: 'string', length: 6, enumType: PostTypeEnum::class)]
|
// TODO: Native Enum
|
||||||
private PostTypeEnum $type;
|
#[ORM\Column(name: 'type', type: 'string', length: 6)]
|
||||||
|
private string $type = self::TYPE_POST;
|
||||||
|
|
||||||
#[ORM\Column(name: 'private', type: 'boolean', nullable: true)]
|
#[ORM\Column(name: 'private', type: 'boolean', nullable: true)]
|
||||||
private bool $private;
|
private bool $private;
|
||||||
|
@ -56,7 +60,7 @@ class Post
|
||||||
private Collection $comments;
|
private Collection $comments;
|
||||||
|
|
||||||
|
|
||||||
public function __construct(string $id, User $author, \DateTime $createdAt, PostTypeEnum $type)
|
public function __construct(string $id, User $author, \DateTime $createdAt, string $type)
|
||||||
{
|
{
|
||||||
$this->id = $id;
|
$this->id = $id;
|
||||||
$this->author = $author;
|
$this->author = $author;
|
||||||
|
@ -101,7 +105,7 @@ class Post
|
||||||
return $this->updatedAt;
|
return $this->updatedAt;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getType(): PostTypeEnum
|
public function getType(): string
|
||||||
{
|
{
|
||||||
return $this->type;
|
return $this->type;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,8 @@ declare(strict_types=1);
|
||||||
namespace App\Entity;
|
namespace App\Entity;
|
||||||
|
|
||||||
use App\Repository\UserRepository;
|
use App\Repository\UserRepository;
|
||||||
use Doctrine\Common\Collections\{ArrayCollection, Collection};
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
|
use Doctrine\Common\Collections\Collection;
|
||||||
use Doctrine\ORM\Mapping as ORM;
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
|
|
||||||
#[ORM\Entity(repositoryClass: UserRepository::class)]
|
#[ORM\Entity(repositoryClass: UserRepository::class)]
|
||||||
|
@ -15,6 +16,10 @@ use Doctrine\ORM\Mapping as ORM;
|
||||||
#[ORM\Index(columns: ['is_removed'], name: 'idx_user_removed')]
|
#[ORM\Index(columns: ['is_removed'], name: 'idx_user_removed')]
|
||||||
class User
|
class User
|
||||||
{
|
{
|
||||||
|
public const AVATAR_SIZE_SMALL = '24';
|
||||||
|
public const AVATAR_SIZE_MEDIUM = '40';
|
||||||
|
public const AVATAR_SIZE_LARGE = '80';
|
||||||
|
|
||||||
#[ORM\Id]
|
#[ORM\Id]
|
||||||
#[ORM\Column(name: 'id', type: 'integer')]
|
#[ORM\Column(name: 'id', type: 'integer')]
|
||||||
private ?int $id = null;
|
private ?int $id = null;
|
||||||
|
|
|
@ -1,11 +0,0 @@
|
||||||
<?php
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace App\Enum;
|
|
||||||
|
|
||||||
enum AvatarSizeEnum: int
|
|
||||||
{
|
|
||||||
case Small = 24;
|
|
||||||
case Medium = 40;
|
|
||||||
case Large = 80;
|
|
||||||
}
|
|
|
@ -1,10 +0,0 @@
|
||||||
<?php
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace App\Enum\Blog;
|
|
||||||
|
|
||||||
enum PostTypeEnum: string
|
|
||||||
{
|
|
||||||
case Post = 'post';
|
|
||||||
case Feed = 'feed';
|
|
||||||
}
|
|
|
@ -3,7 +3,6 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace App\Factory\Blog;
|
namespace App\Factory\Blog;
|
||||||
|
|
||||||
use App\Enum\Blog\PostTypeEnum;
|
|
||||||
use App\Factory\AbstractFactory;
|
use App\Factory\AbstractFactory;
|
||||||
use App\Factory\UserFactory;
|
use App\Factory\UserFactory;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
|
@ -118,7 +117,7 @@ class PostFactory extends AbstractFactory
|
||||||
$postData->getId(),
|
$postData->getId(),
|
||||||
$author,
|
$author,
|
||||||
new \DateTime($postData->getCreated()),
|
new \DateTime($postData->getCreated()),
|
||||||
PostTypeEnum::tryFrom($postData->getType()) ?? PostTypeEnum::Post,
|
$postData->getType() ?: Post::TYPE_POST
|
||||||
);
|
);
|
||||||
$this->postRepository->save($post);
|
$this->postRepository->save($post);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,9 +3,10 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace App\Twig;
|
namespace App\Twig;
|
||||||
|
|
||||||
use App\Enum\AvatarSizeEnum;
|
use App\Entity\User;
|
||||||
use Twig\Extension\AbstractExtension;
|
use Twig\Extension\AbstractExtension;
|
||||||
use Twig\{TwigFilter, TwigFunction};
|
use Twig\TwigFilter;
|
||||||
|
use Twig\TwigFunction;
|
||||||
|
|
||||||
class PointUrlExtension extends AbstractExtension
|
class PointUrlExtension extends AbstractExtension
|
||||||
{
|
{
|
||||||
|
@ -15,7 +16,7 @@ class PointUrlExtension extends AbstractExtension
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getFunctions(): array
|
public function getFunctions()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
new TwigFunction('point_avatar', [$this, 'avatarFunction']),
|
new TwigFunction('point_avatar', [$this, 'avatarFunction']),
|
||||||
|
@ -28,7 +29,7 @@ class PointUrlExtension extends AbstractExtension
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getFilters(): array
|
public function getFilters()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
new TwigFilter('point_avatar', [$this, 'avatarFunction']),
|
new TwigFilter('point_avatar', [$this, 'avatarFunction']),
|
||||||
|
@ -43,20 +44,20 @@ class PointUrlExtension extends AbstractExtension
|
||||||
|
|
||||||
public function avatarSmallFunction(string $login): string
|
public function avatarSmallFunction(string $login): string
|
||||||
{
|
{
|
||||||
return $this->avatarFunction($login, AvatarSizeEnum::Small);
|
return $this->avatarFunction($login, User::AVATAR_SIZE_SMALL);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function avatarMediumFunction(string $login): string
|
public function avatarMediumFunction(string $login): string
|
||||||
{
|
{
|
||||||
return $this->avatarFunction($login, AvatarSizeEnum::Medium);
|
return $this->avatarFunction($login, User::AVATAR_SIZE_MEDIUM);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function avatarLargeFunction(string $login): string
|
public function avatarLargeFunction(string $login): string
|
||||||
{
|
{
|
||||||
return $this->avatarFunction($login, AvatarSizeEnum::Large);
|
return $this->avatarFunction($login, User::AVATAR_SIZE_LARGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function avatarFunction(string $login, AvatarSizeEnum $size): string
|
public function avatarFunction(string $login, $size): string
|
||||||
{
|
{
|
||||||
return $this->getAvatarUrlByLogin($login, $size);
|
return $this->getAvatarUrlByLogin($login, $size);
|
||||||
}
|
}
|
||||||
|
@ -76,8 +77,12 @@ class PointUrlExtension extends AbstractExtension
|
||||||
return sprintf('%s://%s/%s', $this->pointScheme, $this->pointDomain, $postId);
|
return sprintf('%s://%s/%s', $this->pointScheme, $this->pointDomain, $postId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getAvatarUrlByLogin(string $login, AvatarSizeEnum $size): string
|
private function getAvatarUrlByLogin(string $login, string $size): string
|
||||||
{
|
{
|
||||||
return sprintf('%s://%s/avatar/%s/%s', $this->pointScheme, $this->pointDomain, \urlencode($login), $size->value);
|
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