|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Kreta package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Beñat Espiña <[email protected]> |
|
7
|
|
|
* (c) Gorka Laucirica <[email protected]> |
|
8
|
|
|
* |
|
9
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
10
|
|
|
* file that was distributed with this source code. |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
declare(strict_types = 1); |
|
14
|
|
|
|
|
15
|
|
|
namespace Kreta\IdentityAccess\Domain\Model\User; |
|
16
|
|
|
|
|
17
|
|
|
use BenGorFile\File\Domain\Model\FileId; |
|
18
|
|
|
use BenGorFile\File\Domain\Model\FileMimeType; |
|
19
|
|
|
use BenGorFile\File\Domain\Model\FileName; |
|
20
|
|
|
use BenGorUser\User\Domain\Model\User as BaseUser; |
|
21
|
|
|
use BenGorUser\User\Domain\Model\UserEmail; |
|
22
|
|
|
use BenGorUser\User\Domain\Model\UserId; |
|
23
|
|
|
use BenGorUser\User\Domain\Model\UserPassword; |
|
24
|
|
|
|
|
25
|
|
|
class User extends BaseUser |
|
26
|
|
|
{ |
|
27
|
|
|
private $fullName; |
|
28
|
|
|
private $username; |
|
29
|
|
|
private $image; |
|
30
|
|
|
|
|
31
|
|
|
protected function __construct(UserId $id, UserEmail $email, array $userRoles, UserPassword $password) |
|
32
|
|
|
{ |
|
33
|
|
|
parent::__construct($id, $email, $userRoles, $password); |
|
34
|
|
|
$this->username = Username::fromEmail($email); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function editProfile(UserEmail $email, Username $username, FullName $fullName) |
|
38
|
|
|
{ |
|
39
|
|
|
$this->email = $email; |
|
40
|
|
|
$this->username = $username; |
|
41
|
|
|
$this->fullName = $fullName; |
|
42
|
|
|
$this->updatedOn = new \DateTimeImmutable(); |
|
43
|
|
|
|
|
44
|
|
|
$this->publish( |
|
45
|
|
|
new UserProfileEdited( |
|
46
|
|
|
$this->id(), |
|
47
|
|
|
$this->email() |
|
48
|
|
|
) |
|
49
|
|
|
); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function uploadImage(FileName $name, FileMimeType $mimeType) |
|
53
|
|
|
{ |
|
54
|
|
|
$this->image = new Image(new FileId(), $name, $mimeType); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function username() : Username |
|
58
|
|
|
{ |
|
59
|
|
|
return $this->username; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function fullName() |
|
63
|
|
|
{ |
|
64
|
|
|
// This ternary is a hack that avoids the |
|
65
|
|
|
// DoctrineORM limitation with nullable embeddables |
|
66
|
|
|
return $this->fullName instanceof FullName |
|
67
|
|
|
&& !$this->fullName->fullName() |
|
68
|
|
|
? null |
|
69
|
|
|
: $this->fullName; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
public function image() |
|
73
|
|
|
{ |
|
74
|
|
|
return $this->image; |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|