forked from CodelyTV/php-ddd-example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Course.php
44 lines (33 loc) · 986 Bytes
/
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
<?php
declare(strict_types=1);
namespace CodelyTv\Mooc\Courses\Domain;
use CodelyTv\Mooc\Shared\Domain\Courses\CourseId;
use CodelyTv\Shared\Domain\Aggregate\AggregateRoot;
final class Course extends AggregateRoot
{
public function __construct(private CourseId $id, private CourseName $name, private CourseDuration $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;
}
}