1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the zibios/sharep. |
7
|
|
|
* |
8
|
|
|
* (c) Zbigniew Ślązak |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace App\Entity\Access; |
12
|
|
|
|
13
|
|
|
use App\Entity\EntityInterface; |
14
|
|
|
use App\Entity\Traits; |
15
|
|
|
use Doctrine\ORM\Mapping as ORM; |
16
|
|
|
use PascalDeVink\ShortUuid\ShortUuid; |
17
|
|
|
use Symfony\Bridge\Doctrine\Validator\Constraints as OrmAssert; |
18
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @ORM\Entity() |
22
|
|
|
* @ORM\Table(name="access_google_identities") |
23
|
|
|
* @OrmAssert\UniqueEntity(fields={"google_id"}, errorPath="google_id", message="Gmail ID already exist") |
24
|
|
|
* @OrmAssert\UniqueEntity(fields={"email"}, errorPath="email", message="Email already exist") |
25
|
|
|
* @OrmAssert\UniqueEntity(fields={"user"}, errorPath="user", message="User already exist") |
26
|
|
|
*/ |
27
|
|
|
class GoogleIdentity implements EntityInterface |
28
|
|
|
{ |
29
|
|
|
use Traits\PropertyIdGeneratedTrait; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var string |
33
|
|
|
* @ORM\Column(name="google_id", type="string", length=25, nullable=false, unique=true) |
34
|
|
|
* |
35
|
|
|
* @Assert\NotBlank() |
36
|
|
|
* @Assert\Length(min="1", max="25") |
37
|
|
|
*/ |
38
|
|
|
private $googleId; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var string |
42
|
|
|
* @ORM\Column(name="email", type="string", length=255, nullable=false, unique=true) |
43
|
|
|
* |
44
|
|
|
* @Assert\NotBlank() |
45
|
|
|
* @Assert\Email() |
46
|
|
|
* @Assert\Length(min="1", max="255") |
47
|
|
|
*/ |
48
|
|
|
private $email; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @var string |
52
|
|
|
* @ORM\Column(name="name", type="string", length=255, nullable=false) |
53
|
|
|
* |
54
|
|
|
* @Assert\NotBlank() |
55
|
|
|
* @Assert\Length(min="1", max="255") |
56
|
|
|
*/ |
57
|
|
|
private $name; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @var string |
61
|
|
|
* @ORM\Column(name="given_name", type="string", length=255, nullable=false) |
62
|
|
|
* |
63
|
|
|
* @Assert\NotBlank() |
64
|
|
|
* @Assert\Length(min="1", max="255") |
65
|
|
|
*/ |
66
|
|
|
private $givenName; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @var string |
70
|
|
|
* @ORM\Column(name="family_name", type="string", length=255, nullable=false) |
71
|
|
|
* |
72
|
|
|
* @Assert\NotBlank() |
73
|
|
|
* @Assert\Length(min="1", max="255") |
74
|
|
|
*/ |
75
|
|
|
private $familyName; |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @var string |
79
|
|
|
* @ORM\Column(name="picture", type="string", length=255, nullable=false) |
80
|
|
|
* |
81
|
|
|
* @Assert\NotBlank() |
82
|
|
|
* @Assert\Length(min="1", max="255") |
83
|
|
|
*/ |
84
|
|
|
private $picture; |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @var string |
88
|
|
|
* @ORM\Column(name="locale", type="string", length=5, nullable=false) |
89
|
|
|
* |
90
|
|
|
* @Assert\NotBlank() |
91
|
|
|
* @Assert\Locale() |
92
|
|
|
* @Assert\Length(min="2", max="5") |
93
|
|
|
*/ |
94
|
|
|
private $locale; |
95
|
|
|
|
96
|
|
|
//------------------------------------------------------------------------------------------- |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @var User |
100
|
|
|
* @ORM\OneToOne(targetEntity="App\Entity\Access\User", inversedBy="googleIdentity", cascade={"persist"}) |
101
|
|
|
* @ORM\JoinColumn(name="user_id", referencedColumnName="id", nullable=false, unique=true) |
102
|
|
|
* @Assert\NotBlank() |
103
|
|
|
*/ |
104
|
|
|
private $user; |
105
|
|
|
|
106
|
|
|
//------------------------------------------------------------------------------------------- |
107
|
|
|
|
108
|
|
|
public function __construct(User $user, string $googleId, string $email) |
109
|
|
|
{ |
110
|
|
|
$this->id = ShortUuid::uuid4(); |
111
|
|
|
$this->user = $user; |
112
|
|
|
$this->googleId = $googleId; |
113
|
|
|
$this->email = $email; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
//------------------------------------------------------------------------------------------- |
117
|
|
|
|
118
|
|
|
public function getUser(): User |
119
|
|
|
{ |
120
|
|
|
return $this->user; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
public function getGoogleId(): string |
124
|
|
|
{ |
125
|
|
|
return $this->googleId; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
public function getEmail(): string |
129
|
|
|
{ |
130
|
|
|
return $this->email; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
public function getName(): ?string |
134
|
|
|
{ |
135
|
|
|
return $this->name; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
public function setName(string $name): self |
139
|
|
|
{ |
140
|
|
|
$this->name = $name; |
141
|
|
|
|
142
|
|
|
return $this; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
public function getGivenName(): ?string |
146
|
|
|
{ |
147
|
|
|
return $this->givenName; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
public function setGivenName(string $givenName): self |
151
|
|
|
{ |
152
|
|
|
$this->givenName = $givenName; |
153
|
|
|
|
154
|
|
|
return $this; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
public function getFamilyName(): ?string |
158
|
|
|
{ |
159
|
|
|
return $this->familyName; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
public function setFamilyName(string $familyName): self |
163
|
|
|
{ |
164
|
|
|
$this->familyName = $familyName; |
165
|
|
|
|
166
|
|
|
return $this; |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
public function getPicture(): ?string |
170
|
|
|
{ |
171
|
|
|
return $this->picture; |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
public function setPicture(string $picture): self |
175
|
|
|
{ |
176
|
|
|
$this->picture = $picture; |
177
|
|
|
|
178
|
|
|
return $this; |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
public function getLocale(): ?string |
182
|
|
|
{ |
183
|
|
|
return $this->locale; |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
public function setLocale(string $locale): self |
187
|
|
|
{ |
188
|
|
|
$this->locale = $locale; |
189
|
|
|
|
190
|
|
|
return $this; |
191
|
|
|
} |
192
|
|
|
} |
193
|
|
|
|