refactor: Update ChillDocStoreBundle - Add StoredObject repository.

This commit is contained in:
Pol Dellaiera 2021-08-17 14:32:48 +02:00 committed by Marc Ducobu
parent cd59f3a913
commit f358f1af8d
3 changed files with 82 additions and 23 deletions

View File

@ -1,7 +1,7 @@
<?php <?php
/*
* declare(strict_types=1);
*/
namespace Chill\DocStoreBundle\Entity; namespace Chill\DocStoreBundle\Entity;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
@ -9,10 +9,10 @@ use ChampsLibres\AsyncUploaderBundle\Model\AsyncFileInterface;
use ChampsLibres\AsyncUploaderBundle\Validator\Constraints\AsyncFileExists; use ChampsLibres\AsyncUploaderBundle\Validator\Constraints\AsyncFileExists;
/** /**
* Represent a document stored in an object store * Represent a document stored in an object store
* *
* @author Julien Fastré <julien.fastre@champs-libres.coop> * @author Julien Fastré <julien.fastre@champs-libres.coop>
* *
* @ORM\Entity() * @ORM\Entity()
* @ORM\Table("chill_doc.stored_object") * @ORM\Table("chill_doc.stored_object")
* @AsyncFileExists( * @AsyncFileExists(
@ -27,51 +27,49 @@ class StoredObject implements AsyncFileInterface
* @ORM\Column(type="integer") * @ORM\Column(type="integer")
*/ */
private $id; private $id;
/** /**
* @ORM\Column(type="text") * @ORM\Column(type="text")
*/ */
private $filename; private $filename;
/** /**
* @ORM\Column(type="json_array", name="key") * @ORM\Column(type="json_array", name="key")
* @var array * @var array
*/ */
private $keyInfos = array(); private $keyInfos = array();
/** /**
* *
* @var int[] * @var int[]
* @ORM\Column(type="json_array", name="iv") * @ORM\Column(type="json_array", name="iv")
*/ */
private $iv = array(); private $iv = array();
/** /**
* *
* @var \DateTime * @var \DateTime
* @ORM\Column(type="datetime", name="creation_date") * @ORM\Column(type="datetime", name="creation_date")
*/ */
private $creationDate; private $creationDate;
/** /**
*
* @var string
* @ORM\Column(type="text", name="type") * @ORM\Column(type="text", name="type")
*/ */
private $type = ''; private string $type = '';
/** /**
* *
* @var array * @var array
* @ORM\Column(type="json_array", name="datas") * @ORM\Column(type="json_array", name="datas")
*/ */
private $datas = []; private $datas = [];
public function __construct() public function __construct()
{ {
$this->creationDate = new \DateTime(); $this->creationDate = new \DateTime();
} }
public function getId() public function getId()
{ {
return $this->id; return $this->id;
@ -100,35 +98,39 @@ class StoredObject implements AsyncFileInterface
public function setFilename($filename) public function setFilename($filename)
{ {
$this->filename = $filename; $this->filename = $filename;
return $this; return $this;
} }
public function setCreationDate(\DateTime $creationDate) public function setCreationDate(\DateTime $creationDate)
{ {
$this->creationDate = $creationDate; $this->creationDate = $creationDate;
return $this; return $this;
} }
public function setType($type) public function setType($type)
{ {
$this->type = $type; $this->type = $type;
return $this; return $this;
} }
public function setDatas(array $datas) public function setDatas(array $datas)
{ {
$this->datas = $datas; $this->datas = $datas;
return $this; return $this;
} }
/**
* @deprecated Use method "getFilename()".
*/
public function getObjectName() public function getObjectName()
{ {
return $this->getFilename(); return $this->getFilename();
} }
public function getKeyInfos() public function getKeyInfos()
{ {
return $this->keyInfos; return $this->keyInfos;
@ -142,14 +144,14 @@ class StoredObject implements AsyncFileInterface
public function setKeyInfos($keyInfos) public function setKeyInfos($keyInfos)
{ {
$this->keyInfos = $keyInfos; $this->keyInfos = $keyInfos;
return $this; return $this;
} }
public function setIv($iv) public function setIv($iv)
{ {
$this->iv = $iv; $this->iv = $iv;
return $this; return $this;
} }

View File

@ -0,0 +1,51 @@
<?php
declare(strict_types=1);
namespace Chill\DocStoreBundle\Repository;
use Chill\DocStoreBundle\Entity\StoredObject;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use Doctrine\Persistence\ObjectRepository;
final class StoredObjectRepository implements ObjectRepository
{
private EntityRepository $repository;
public function __construct(EntityManagerInterface $entityManager)
{
$this->repository = $entityManager->getRepository(StoredObject::class);
}
/**
* @return array<int, StoredObject>
*/
public function findAll(): array
{
return $this->repository->findAll();
}
/**
* @return array<int, StoredObject>
*/
public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null): array
{
return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
}
public function findOneBy(array $criteria): ?StoredObject
{
return $this->repository->findOneBy($criteria);
}
public function getClassName(): string
{
return StoredObject::class;
}
public function find($id, $lockMode = null, $lockVersion = null): ?StoredObject
{
return $this->repository->find($id, $lockMode, $lockVersion);
}
}

View File

@ -2,6 +2,12 @@ parameters:
# cl_chill_person.example.class: Chill\PersonBundle\Example # cl_chill_person.example.class: Chill\PersonBundle\Example
services: services:
Chill\DocStoreBundle\Repository\:
autowire: true
autoconfigure: true
resource: '../Repository/'
tags: ['doctrine.repository_service']
Chill\DocStoreBundle\Form\DocumentCategoryType: Chill\DocStoreBundle\Form\DocumentCategoryType:
class: Chill\DocStoreBundle\Form\DocumentCategoryType class: Chill\DocStoreBundle\Form\DocumentCategoryType
arguments: ['%kernel.bundles%'] arguments: ['%kernel.bundles%']