diff --git a/Domain/Service/Repository/RepositoryInterface.php b/Domain/Service/Repository/RepositoryInterface.php new file mode 100644 index 0000000..e30bf8f --- /dev/null +++ b/Domain/Service/Repository/RepositoryInterface.php @@ -0,0 +1,41 @@ + + * @extends Selectable + */ +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; +} \ No newline at end of file diff --git a/Infrastructure/Persistence/Doctrine/Repository/DoctrineRepository.php b/Infrastructure/Persistence/Doctrine/Repository/DoctrineRepository.php new file mode 100644 index 0000000..3611b99 --- /dev/null +++ b/Infrastructure/Persistence/Doctrine/Repository/DoctrineRepository.php @@ -0,0 +1,94 @@ + + * @implements RepositoryInterface + */ +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(); + } +} \ No newline at end of file