-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUser.php
48 lines (37 loc) · 1.06 KB
/
User.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
<?php
/*
* Copyright (c) Fusonic GmbH. All rights reserved.
* Licensed under the MIT License. See LICENSE file in the project root for license information.
*/
declare(strict_types=1);
namespace Fusonic\DDDExtensions\Tests\Domain;
use Fusonic\DDDExtensions\Domain\Model\AggregateRoot;
use Fusonic\DDDExtensions\Domain\Model\Traits\IntegerIdTrait;
use Fusonic\DDDExtensions\Tests\Domain\Event\RegisterUserEvent;
final class User extends AggregateRoot
{
use IntegerIdTrait;
private string $name;
private ?Job $job;
public function __construct(string $name, ?string $jobName = null)
{
$this->name = $name;
$this->job = null !== $jobName ? new Job($jobName) : null;
}
public function getId(): UserId
{
return new UserId($this->id);
}
public function getName(): string
{
return $this->name;
}
public function getJobName(): ?string
{
return $this->job?->getName();
}
public function register(): void
{
$this->raise(new RegisterUserEvent($this->getId()));
}
}