forked from CodelyTV/php-ddd-example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Course.php
51 lines (39 loc) · 1.14 KB
/
Course.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
43
44
45
46
47
48
49
50
51
<?php
declare(strict_types = 1);
namespace CodelyTv\Mooc\Courses\Domain;
use CodelyTv\Mooc\Shared\Domain\Course\CourseId;
use CodelyTv\Shared\Domain\Aggregate\AggregateRoot;
final class Course extends AggregateRoot
{
private CourseId $id;
private CourseName $name;
private CourseDuration $duration;
public function __construct(CourseId $id, CourseName $name, CourseDuration $duration)
{
$this->id = $id;
$this->name = $name;
$this->duration = $duration;
}
public static function create(CourseId $id, CourseName $name, CourseDuration $duration): self
{
$course = new self($id, $name, $duration);
$course->record(new CourseCreatedDomainEvent($id->value(), $name->value(), $duration->value()));
return $course;
}
public function id(): CourseId
{
return $this->id;
}
public function name(): CourseName
{
return $this->name;
}
public function duration(): CourseDuration
{
return $this->duration;
}
public function rename(CourseName $newName): void
{
$this->name = $newName;
}
}