-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathDoctrineRepository.php
More file actions
38 lines (30 loc) · 933 Bytes
/
DoctrineRepository.php
File metadata and controls
38 lines (30 loc) · 933 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
declare(strict_types=1);
namespace CodelyTv\Shared\Infrastructure\Persistence\Doctrine;
use CodelyTv\Shared\Domain\Aggregate\AggregateRoot;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityRepository;
abstract class DoctrineRepository
{
public function __construct(private EntityManager $entityManager)
{
}
protected function entityManager(): EntityManager
{
return $this->entityManager;
}
protected function persist(AggregateRoot $entity): void
{
$this->entityManager()->persist($entity);
$this->entityManager()->flush($entity);
}
protected function remove(AggregateRoot $entity): void
{
$this->entityManager()->remove($entity);
$this->entityManager()->flush($entity);
}
protected function repository(string $entityClass): EntityRepository
{
return $this->entityManager->getRepository($entityClass);
}
}