forked from CodelyTV/php-ddd-example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
VideoRepositoryMySql.php
42 lines (34 loc) · 1.25 KB
/
VideoRepositoryMySql.php
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
39
40
41
42
<?php
declare(strict_types = 1);
namespace CodelyTv\Mooc\Videos\Infrastructure\Persistence;
use CodelyTv\Mooc\Videos\Domain\Video;
use CodelyTv\Mooc\Videos\Domain\VideoId;
use CodelyTv\Mooc\Videos\Domain\VideoRepository;
use CodelyTv\Mooc\Videos\Domain\Videos;
use CodelyTv\Shared\Domain\Criteria\Criteria;
use CodelyTv\Shared\Infrastructure\Doctrine\DoctrineCriteriaConverter;
use CodelyTv\Shared\Infrastructure\Doctrine\DoctrineRepository;
final class VideoRepositoryMySql extends DoctrineRepository implements VideoRepository
{
private static $criteriaToDoctrineFields = [
'id' => 'id',
'type' => 'type',
'title' => 'title',
'url' => 'url',
'course_id' => 'courseId',
];
public function save(Video $video): void
{
$this->persist($video);
}
public function search(VideoId $id): ?Video
{
return $this->repository(Video::class)->find($id);
}
public function searchByCriteria(Criteria $criteria): Videos
{
$doctrineCriteria = DoctrineCriteriaConverter::convert($criteria, self::$criteriaToDoctrineFields);
$videos = $this->repository(Video::class)->matching($doctrineCriteria)->toArray();
return new Videos($videos);
}
}