WIP: Symfony 6 project remake #2
|
@ -1,44 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace src\PointToolsBundle\Entity\Blogs;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Table(name="files", schema="posts")
|
||||
* @ORM\Entity(repositoryClass="Skobkin\Bundle\PointToolsBundle\Repository\Blogs\FileRepository", readOnly=true)
|
||||
*/
|
||||
class File
|
||||
{
|
||||
/**
|
||||
* @var integer
|
||||
*
|
||||
* @ORM\Column(name="id", type="integer")
|
||||
* @ORM\Id
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(name="remote_url", type="text", unique=true)
|
||||
*/
|
||||
private $remoteUrl;
|
||||
|
||||
|
||||
public function __construct($remoteUrl)
|
||||
{
|
||||
$this->remoteUrl = $remoteUrl;
|
||||
}
|
||||
|
||||
public function getId(): int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getRemoteUrl(): string
|
||||
{
|
||||
return $this->remoteUrl;
|
||||
}
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace src\PointToolsBundle\Repository\Blogs;
|
||||
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use src\PointToolsBundle\Entity\Blogs\File;
|
||||
|
||||
class FileRepository extends EntityRepository
|
||||
{
|
||||
public function add(File $entity): void
|
||||
{
|
||||
$this->getEntityManager()->persist($entity);
|
||||
}
|
||||
}
|
37
src/Entity/Blog/File.php
Normal file
37
src/Entity/Blog/File.php
Normal file
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Entity\Blog;
|
||||
|
||||
use App\Entity\Blog\Post;
|
||||
use App\Repository\Blog\FileRepository;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[ORM\Entity(repositoryClass: FileRepository::class)]
|
||||
#[ORM\Table(name: 'files', schema: 'posts')]
|
||||
class File
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue(strategy: 'AUTO')]
|
||||
#[ORM\Column(name: 'id', type: 'integer')]
|
||||
private ?int $id;
|
||||
|
||||
#[ORM\Column(name: 'remote_url', type: 'text', unique: true)]
|
||||
private string $remoteUrl;
|
||||
|
||||
|
||||
public function __construct($remoteUrl)
|
||||
{
|
||||
$this->remoteUrl = $remoteUrl;
|
||||
}
|
||||
|
||||
public function getId(): int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getRemoteUrl(): string
|
||||
{
|
||||
return $this->remoteUrl;
|
||||
}
|
||||
}
|
33
src/Repository/Blog/FileRepository.php
Normal file
33
src/Repository/Blog/FileRepository.php
Normal file
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Repository\Blog;
|
||||
|
||||
use App\Entity\Blog\File;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
* @extends ServiceEntityRepository<File>
|
||||
*
|
||||
* @method File|null find($id, $lockMode = null, $lockVersion = null)
|
||||
* @method File|null findOneBy(array $criteria, array $orderBy = null)
|
||||
* @method File[] findAll()
|
||||
* @method File[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
||||
*/
|
||||
class FileRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, File::class);
|
||||
}
|
||||
|
||||
public function save(File $entity, bool $flush = false): void
|
||||
{
|
||||
$this->getEntityManager()->persist($entity);
|
||||
|
||||
if ($flush) {
|
||||
$this->getEntityManager()->flush();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue