Skip to content

Commit

Permalink
add persist methods in repositories
Browse files Browse the repository at this point in the history
  • Loading branch information
mmadariaga committed Sep 29, 2023
1 parent b1198e6 commit 4f7569e
Show file tree
Hide file tree
Showing 2 changed files with 134 additions and 0 deletions.
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,93 @@
<?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 EntityT of EntityInterface
* @template DtoT of DataTransferObjectInterface
* @template-extends ServiceEntityRepository<EntityT>
*/
class DoctrineRepository extends ServiceEntityRepository implements RepositoryInterface

Check failure on line 22 in Infrastructure/Persistence/Doctrine/Repository/DoctrineRepository.php

View workflow job for this annotation

GitHub Actions / build

Class Doctrine\Bundle\DoctrineBundle\Repository\LazyServiceEntityRepository specifies template type T of interface Doctrine\Common\Collections\Selectable as EntityT of Ivoz\Core\Domain\Model\EntityInterface but it's already specified as mixed.

Check failure on line 22 in Infrastructure/Persistence/Doctrine/Repository/DoctrineRepository.php

View workflow job for this annotation

GitHub Actions / build

Class Doctrine\Bundle\DoctrineBundle\Repository\LazyServiceEntityRepository specifies template type T of interface Doctrine\Common\Collections\Selectable as EntityT of Ivoz\Core\Domain\Model\EntityInterface but it's already specified as mixed.

Check failure on line 22 in Infrastructure/Persistence/Doctrine/Repository/DoctrineRepository.php

View workflow job for this annotation

GitHub Actions / build

Class Doctrine\Bundle\DoctrineBundle\Repository\LazyServiceEntityRepository specifies template type T of interface Doctrine\Persistence\ObjectRepository as EntityT of Ivoz\Core\Domain\Model\EntityInterface but it's already specified as object.

Check failure on line 22 in Infrastructure/Persistence/Doctrine/Repository/DoctrineRepository.php

View workflow job for this annotation

GitHub Actions / build

Class Doctrine\Bundle\DoctrineBundle\Repository\LazyServiceEntityRepository specifies template type T of interface Doctrine\Persistence\ObjectRepository as EntityT of Ivoz\Core\Domain\Model\EntityInterface but it's already specified as object.

Check failure on line 22 in Infrastructure/Persistence/Doctrine/Repository/DoctrineRepository.php

View workflow job for this annotation

GitHub Actions / build

Class Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository specifies template type T of interface Doctrine\Common\Collections\Selectable as EntityT of Ivoz\Core\Domain\Model\EntityInterface but it's already specified as mixed.

Check failure on line 22 in Infrastructure/Persistence/Doctrine/Repository/DoctrineRepository.php

View workflow job for this annotation

GitHub Actions / build

Class Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository specifies template type T of interface Doctrine\Persistence\ObjectRepository as EntityT of Ivoz\Core\Domain\Model\EntityInterface but it's already specified as object.

Check failure on line 22 in Infrastructure/Persistence/Doctrine/Repository/DoctrineRepository.php

View workflow job for this annotation

GitHub Actions / build

Class Doctrine\ORM\EntityRepository specifies template type T of interface Doctrine\Common\Collections\Selectable as EntityT of Ivoz\Core\Domain\Model\EntityInterface but it's already specified as mixed.

Check failure on line 22 in Infrastructure/Persistence/Doctrine/Repository/DoctrineRepository.php

View workflow job for this annotation

GitHub Actions / build

Class Doctrine\ORM\EntityRepository specifies template type T of interface Doctrine\Common\Collections\Selectable as EntityT of Ivoz\Core\Domain\Model\EntityInterface but it's already specified as mixed.

Check failure on line 22 in Infrastructure/Persistence/Doctrine/Repository/DoctrineRepository.php

View workflow job for this annotation

GitHub Actions / build

Class Doctrine\ORM\EntityRepository specifies template type T of interface Doctrine\Common\Collections\Selectable as EntityT of Ivoz\Core\Domain\Model\EntityInterface but it's already specified as mixed.

Check failure on line 22 in Infrastructure/Persistence/Doctrine/Repository/DoctrineRepository.php

View workflow job for this annotation

GitHub Actions / build

Class Doctrine\ORM\EntityRepository specifies template type T of interface Doctrine\Common\Collections\Selectable as EntityT of Ivoz\Core\Domain\Model\EntityInterface but it's already specified as mixed.
{
public function __construct(
ManagerRegistry $registry,
string $entityClass,
private EntityPersisterInterface $entityPersister,
) {
parent::__construct(
$registry,
$entityClass
);
}

/**
* @param DtoT $dto
* @param EntityT|null $entity
* @return EntityT
*/
public function persistDto(DataTransferObjectInterface $dto, EntityInterface $entity = null, $dispatchImmediately = false): EntityInterface
{
return
$this
->entityPersister
->persistDto(
$dto,
$entity,
$dispatchImmediately
);
}

/**
* @param EntityT $entity
*/
public function persist(EntityInterface $entity, bool $dispatchImmediately = false): void
{
$this
->entityPersister
->persist(
$entity,
$dispatchImmediately
);
}

/**
* @param EntityT $entity
*/
public function remove(EntityInterface $entity): void
{
$this
->entityPersister
->remove(
$entity
);
}

/**
* @param EntityT[] $entities
*/
public function removeFromArray(array $entities): void
{
$this
->entityPersister
->removeFromArray(
$entities
);
}

public function dispatchQueued(): void
{
$this->entityPersister->dispatchQueued();
}
}

0 comments on commit 4f7569e

Please sign in to comment.