-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathVideoRepositoryInMemory.php
More file actions
45 lines (35 loc) · 999 Bytes
/
VideoRepositoryInMemory.php
File metadata and controls
45 lines (35 loc) · 999 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
39
40
41
42
43
44
45
<?php
declare(strict_types=1);
namespace CodelyTv\Mooc\Videos\Infrastructure;
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;
final class VideoRepositoryInMemory implements VideoRepository
{
private array $videos = [];
public function save(Video $video): void
{
$this->videos[] = $video;
}
public function search(VideoId $id): ?Video
{
foreach ($this->videos as $video) {
if ($video->id == $id) {
return $video;
}
}
return null;
}
public function findLastVideo(): ?Video
{
$lastVideo = max($this->videos);
return ($lastVideo) ? $lastVideo : null;
}
public function searchByCriteria(Criteria $criteria): Videos
{
// TODO Criteria
return new Videos($this->videos);
}
}