WIP: Symfony 6 project remake #2

Draft
skobkin wants to merge 103 commits from symfony6_remake into master
4 changed files with 80 additions and 69 deletions
Showing only changes of commit c5a63a4259 - Show all commits

View file

@ -1,44 +0,0 @@
<?php
namespace src\PointToolsBundle\Entity\Blogs;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Table(name="tags", schema="posts")
* @ORM\Entity(repositoryClass="Skobkin\Bundle\PointToolsBundle\Repository\Blogs\TagRepository", readOnly=true)
*/
class Tag
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="text", type="text", unique=true)
*/
private $text;
public function __construct(string $text)
{
$this->text = $text;
}
public function getId(): int
{
return $this->id;
}
public function getText(): string
{
return $this->text;
}
}

View file

@ -1,25 +0,0 @@
<?php
namespace src\PointToolsBundle\Repository\Blogs;
use Doctrine\ORM\EntityRepository;
use src\PointToolsBundle\Entity\Blogs\Tag;
use function Skobkin\Bundle\PointToolsBundle\Repository\Blogs\mb_strtolower;
class TagRepository extends EntityRepository
{
public function add(Tag $entity): void
{
$this->getEntityManager()->persist($entity);
}
public function findOneByLowerText(string $text): ?Tag
{
$qb = $this->createQueryBuilder('t');
return $qb
->where('LOWER(t.text) = :text')
->setParameter('text', mb_strtolower($text))
->getQuery()->getOneOrNullResult()
;
}
}

37
src/Entity/Blog/Tag.php Normal file
View file

@ -0,0 +1,37 @@
<?php
declare(strict_types=1);
namespace App\Entity\Blog;
use App\Entity\Blog\Post;
use App\Repository\Blog\TagRepository;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: TagRepository::class)]
#[ORM\Table(name: 'tags', schema: 'posts')]
class Tag
{
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'AUTO')]
#[ORM\Column(name: 'id', type: 'integer')]
private ?int $id;
#[ORM\Column(name: 'text', type: 'text', unique: true)]
private string $text;
public function __construct(string $text)
{
$this->text = $text;
}
public function getId(): ?int
{
return $this->id;
}
public function getText(): string
{
return $this->text;
}
}

View file

@ -0,0 +1,43 @@
<?php
declare(strict_types=1);
namespace App\Repository\Blog;
use App\Entity\Blog\Tag;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<Tag>
*
* @method Tag|null find($id, $lockMode = null, $lockVersion = null)
* @method Tag|null findOneBy(array $criteria, array $orderBy = null)
* @method Tag[] findAll()
* @method Tag[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class TagRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Tag::class);
}
public function save(Tag $entity, bool $flush = false): void
{
$this->getEntityManager()->persist($entity);
if ($flush) {
$this->getEntityManager()->flush();
}
}
public function findOneByLowerText(string $text): ?Tag
{
$qb = $this->createQueryBuilder('t');
return $qb
->where('LOWER(t.text) = :text')
->setParameter('text', \mb_strtolower($text))
->getQuery()->getOneOrNullResult()
;
}
}