|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types = 1); |
|
3
|
|
|
|
|
4
|
|
|
namespace User\Entity; |
|
5
|
|
|
|
|
6
|
|
|
use Doctrine\ORM\Mapping as ORM; |
|
7
|
|
|
use Common\Entity; |
|
8
|
|
|
use InvalidArgumentException; |
|
9
|
|
|
use JMS\Serializer\Annotation as Serializer; |
|
10
|
|
|
use Respect\Validation\Exceptions\AllOfException; |
|
11
|
|
|
use Respect\Validation\Validator as v; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* User Entity |
|
15
|
|
|
* |
|
16
|
|
|
* @author Thiago Paes <[email protected]> |
|
17
|
|
|
* |
|
18
|
|
|
* @ORM\Table(name="user") |
|
19
|
|
|
* @ORM\Entity(repositoryClass="\User\Repository\User") |
|
20
|
|
|
* @ORM\HasLifecycleCallbacks |
|
21
|
|
|
*/ |
|
22
|
|
|
class User implements UserInterface |
|
23
|
|
|
{ |
|
24
|
|
|
use Entity; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @ORM\Column(name="id", type="integer", nullable=false) |
|
28
|
|
|
* @ORM\Id |
|
29
|
|
|
* @ORM\GeneratedValue(strategy="IDENTITY") |
|
30
|
|
|
* @Serializer\Type("integer") |
|
31
|
|
|
* @var int |
|
32
|
|
|
*/ |
|
33
|
|
|
protected $id; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @ORM\Column(name="name", type="string", length=1024, nullable=false) |
|
37
|
|
|
* @Serializer\Type("string") |
|
38
|
|
|
* @var string |
|
39
|
|
|
*/ |
|
40
|
|
|
protected $name; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @ORM\Column(name="email", type="string", length=255, nullable=false, unique=true) |
|
44
|
|
|
* @Serializer\Type("string") |
|
45
|
|
|
* @Serializer\Exclude |
|
46
|
|
|
* @var string |
|
47
|
|
|
*/ |
|
48
|
|
|
protected $email; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @ORM\Column(name="active", type="boolean", nullable=true) |
|
52
|
|
|
* @Serializer\Type("boolean") |
|
53
|
|
|
* @Serializer\Exclude |
|
54
|
|
|
* @var bool |
|
55
|
|
|
*/ |
|
56
|
|
|
protected $active; |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @ORM\Column(name="created", type="datetime", nullable=false) |
|
60
|
|
|
* @Serializer\Type("DateTime") |
|
61
|
|
|
* @var DateTime |
|
62
|
|
|
*/ |
|
63
|
|
|
protected $created; |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @ORM\Column(name="updated", type="datetime", nullable=false) |
|
67
|
|
|
* @Serializer\Type("DateTime") |
|
68
|
|
|
* @var DateTime |
|
69
|
|
|
*/ |
|
70
|
|
|
protected $updated; |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Constructor |
|
74
|
|
|
*/ |
|
75
|
|
|
public function __construct() |
|
76
|
|
|
{ |
|
77
|
|
|
$this->active = true; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* @inheritDoc |
|
82
|
|
|
*/ |
|
83
|
|
|
public function getId(): int |
|
84
|
|
|
{ |
|
85
|
|
|
return $this->id ?: 0; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @inheritdoc |
|
90
|
|
|
*/ |
|
91
|
|
|
public function getName(): string |
|
92
|
|
|
{ |
|
93
|
|
|
return $this->name; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* @inheritdoc |
|
98
|
|
|
*/ |
|
99
|
|
|
public function setName(string $name) |
|
100
|
|
|
{ |
|
101
|
|
|
try { |
|
102
|
|
|
v::notEmpty()->assert($name); |
|
103
|
|
|
|
|
104
|
|
|
$this->name = $name; |
|
105
|
|
|
} catch (AllOfException $e) { |
|
106
|
|
|
throw new InvalidArgumentException('Name is invalid'); |
|
107
|
|
|
} |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* @inheritdoc |
|
112
|
|
|
*/ |
|
113
|
|
|
public function getEmail(): string |
|
114
|
|
|
{ |
|
115
|
|
|
return $this->email; |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* @inheritdoc |
|
120
|
|
|
*/ |
|
121
|
|
|
public function setEmail(string $email) |
|
122
|
|
|
{ |
|
123
|
|
|
try { |
|
124
|
|
|
v::notEmpty()->email()->assert($email); |
|
125
|
|
|
|
|
126
|
|
|
$this->email = $email; |
|
127
|
|
|
} catch (AllOfException $e) { |
|
128
|
|
|
throw new InvalidArgumentException('E-mail is invalid'); |
|
129
|
|
|
} |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
/** |
|
133
|
|
|
* @inheritdoc |
|
134
|
|
|
*/ |
|
135
|
|
|
public function delete(): bool |
|
136
|
|
|
{ |
|
137
|
|
|
$this->active = false; |
|
138
|
|
|
|
|
139
|
|
|
return true; |
|
140
|
|
|
} |
|
141
|
|
|
} |
|
142
|
|
|
|