Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add persist methods in repositories #19

Merged
merged 1 commit into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions Domain/Service/Repository/RepositoryInterface.php
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;
}
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();
}
}
Loading