-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b1198e6
commit 8a7d8e6
Showing
2 changed files
with
135 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace Ivoz\Core\Domain\Service\Repository; | ||
|
||
use Doctrine\Common\Collections\Selectable; | ||
use Doctrine\Persistence\ObjectRepository; | ||
use Ivoz\Core\Domain\DataTransferObjectInterface; | ||
use Ivoz\Core\Domain\Model\EntityInterface; | ||
|
||
/** | ||
* @template EntityT of EntityInterface | ||
* @template DtoT of DataTransferObjectInterface | ||
* @extends ObjectRepository<EntityT> | ||
* @extends Selectable<int, EntityT> | ||
*/ | ||
interface RepositoryInterface extends ObjectRepository, Selectable | ||
{ | ||
/** | ||
* @param DtoT $dto | ||
* @param EntityT|null $entity | ||
* @return EntityT | ||
*/ | ||
public function persistDto(DataTransferObjectInterface $dto, EntityInterface $entity = null, $dispatchImmediately = false): EntityInterface; | ||
|
||
/** | ||
* @param EntityT $entity | ||
*/ | ||
public function persist(EntityInterface $entity, bool $dispatchImmediately = false): void; | ||
|
||
/** | ||
* @param EntityT $entity | ||
*/ | ||
public function remove(EntityInterface $entity): void; | ||
|
||
/** | ||
* @param EntityT[] $entities | ||
*/ | ||
public function removeFromArray(array $entities): void; | ||
|
||
public function dispatchQueued(): void; | ||
} |
94 changes: 94 additions & 0 deletions
94
Infrastructure/Persistence/Doctrine/Repository/DoctrineRepository.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?php | ||
|
||
namespace Ivoz\Core\Infrastructure\Persistence\Doctrine\Repository; | ||
|
||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; | ||
use Doctrine\Persistence\ManagerRegistry; | ||
use Ivoz\Core\Domain\DataTransferObjectInterface; | ||
use Ivoz\Core\Domain\Model\EntityInterface; | ||
use Ivoz\Core\Domain\Service\EntityPersisterInterface; | ||
use Ivoz\Core\Domain\Service\Repository\RepositoryInterface; | ||
|
||
/** | ||
* CompanyDoctrineRepository | ||
* | ||
* This class was generated by the Doctrine ORM. Add your own custom | ||
* repository methods below. | ||
* | ||
* @template T of EntityInterface | ||
* @template DtoT of DataTransferObjectInterface | ||
* @extends ServiceEntityRepository<T> | ||
* @implements RepositoryInterface<T, DtoT> | ||
*/ | ||
class DoctrineRepository extends ServiceEntityRepository implements RepositoryInterface | ||
{ | ||
public function __construct( | ||
ManagerRegistry $registry, | ||
string $entityClass, | ||
private EntityPersisterInterface $entityPersister, | ||
) { | ||
parent::__construct( | ||
$registry, | ||
$entityClass | ||
); | ||
} | ||
|
||
/** | ||
* @param DtoT $dto | ||
* @param T|null $entity | ||
* @return T | ||
*/ | ||
public function persistDto(DataTransferObjectInterface $dto, EntityInterface $entity = null, $dispatchImmediately = false): EntityInterface | ||
{ | ||
return | ||
$this | ||
->entityPersister | ||
->persistDto( | ||
$dto, | ||
$entity, | ||
$dispatchImmediately | ||
); | ||
} | ||
|
||
/** | ||
* @param T $entity | ||
*/ | ||
public function persist(EntityInterface $entity, bool $dispatchImmediately = false): void | ||
{ | ||
$this | ||
->entityPersister | ||
->persist( | ||
$entity, | ||
$dispatchImmediately | ||
); | ||
} | ||
|
||
/** | ||
* @param T $entity | ||
*/ | ||
public function remove(EntityInterface $entity): void | ||
{ | ||
$this | ||
->entityPersister | ||
->remove( | ||
$entity | ||
); | ||
} | ||
|
||
/** | ||
* @param T[] $entities | ||
*/ | ||
public function removeFromArray(array $entities): void | ||
{ | ||
$this | ||
->entityPersister | ||
->removeFromArray( | ||
$entities | ||
); | ||
} | ||
|
||
public function dispatchQueued(): void | ||
{ | ||
$this->entityPersister->dispatchQueued(); | ||
} | ||
} |