]> Raphaël G. Git Repositories - airbundle/blob - Entity/GoogleToken.php
Use full entity name instead of undefined short version
[airbundle] / Entity / GoogleToken.php
1 <?php declare(strict_types=1);
2
3 /*
4 * This file is part of the Rapsys AirBundle package.
5 *
6 * (c) Raphaël Gertz <symfony@rapsys.eu>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace Rapsys\AirBundle\Entity;
13
14 use Doctrine\Common\Collections\Collection;
15 use Doctrine\Common\Collections\ArrayCollection;
16 use Doctrine\ORM\Event\PreUpdateEventArgs;
17
18 /**
19 * GoogleToken
20 */
21 class GoogleToken {
22 /**
23 * @var int
24 */
25 private ?int $id;
26
27 /**
28 * @var string
29 */
30 private string $mail;
31
32 /**
33 * @var string
34 */
35 private string $access;
36
37 /**
38 * @var ?string
39 */
40 private ?string $refresh;
41
42 /**
43 * @var \DateTime
44 */
45 private \DateTime $expired;
46
47 /**
48 * @var \DateTime
49 */
50 private \DateTime $created;
51
52 /**
53 * @var \DateTime
54 */
55 private \DateTime $updated;
56
57 /**
58 * @var \Doctrine\Common\Collections\Collection
59 */
60 private Collection $googleCalendars;
61
62 /**
63 * @var \Rapsys\AirBundle\Entity\User
64 */
65 private User $user;
66
67 /**
68 * Constructor
69 *
70 * @param \Rapsys\AirBundle\Entity\User $user The user
71 * @param string The token user mail
72 * @param string The access token identifier
73 * @param \DateTime The access token expires
74 * @param ?string The refresh token identifier
75 */
76 public function __construct(User $user, string $mail, string $access, \DateTime $expired, ?string $refresh = null) {
77 //Set defaults
78 $this->user = $user;
79 $this->mail = $mail;
80 $this->access = $access;
81 $this->refresh = $refresh;
82 $this->expired = $expired;
83 $this->created = new \DateTime('now');
84 $this->updated = new \DateTime('now');
85 $this->googleCalendars = new ArrayCollection();
86 }
87
88 /**
89 * Get id
90 *
91 * @return ?int
92 */
93 public function getId(): ?int {
94 return $this->id;
95 }
96
97 /**
98 * Set mail
99 *
100 * @param string $mail
101 * @return GoogleToken
102 */
103 public function setMail(string $mail): GoogleToken {
104 $this->mail = $mail;
105
106 return $this;
107 }
108
109 /**
110 * Get mail
111 *
112 * @return string
113 */
114 public function getMail(): string {
115 return $this->mail;
116 }
117
118 /**
119 * Set access
120 *
121 * @param string $access
122 *
123 * @return GoogleToken
124 */
125 public function setAccess(string $access): GoogleToken {
126 $this->access = $access;
127
128 return $this;
129 }
130
131 /**
132 * Get access
133 *
134 * @return string
135 */
136 public function getAccess(): string {
137 return $this->access;
138 }
139
140 /**
141 * Set refresh
142 *
143 * @param string $refresh
144 *
145 * @return GoogleToken
146 */
147 public function setRefresh(?string $refresh): GoogleToken {
148 $this->refresh = $refresh;
149
150 return $this;
151 }
152
153 /**
154 * Get refresh
155 *
156 * @return string
157 */
158 public function getRefresh(): ?string {
159 return $this->refresh;
160 }
161
162 /**
163 * Set expired
164 *
165 * @param \DateTime $expired
166 *
167 * @return GoogleToken
168 */
169 public function setExpired(\DateTime $expired): GoogleToken {
170 $this->expired = $expired;
171
172 return $this;
173 }
174
175 /**
176 * Get expired
177 *
178 * @return \DateTime
179 */
180 public function getExpired(): \DateTime {
181 return $this->expired;
182 }
183
184 /**
185 * Set created
186 *
187 * @param \DateTime $created
188 *
189 * @return GoogleToken
190 */
191 public function setCreated(\DateTime $created): GoogleToken {
192 $this->created = $created;
193
194 return $this;
195 }
196
197 /**
198 * Get created
199 *
200 * @return \DateTime
201 */
202 public function getCreated(): \DateTime {
203 return $this->created;
204 }
205
206 /**
207 * Set updated
208 *
209 * @param \DateTime $updated
210 *
211 * @return GoogleToken
212 */
213 public function setUpdated(\DateTime $updated): GoogleToken {
214 $this->updated = $updated;
215
216 return $this;
217 }
218
219 /**
220 * Get updated
221 *
222 * @return \DateTime
223 */
224 public function getUpdated(): \DateTime {
225 return $this->updated;
226 }
227
228 /**
229 * Add google calendar
230 *
231 * @param GoogleCalendar $googleCalendar
232 *
233 * @return User
234 */
235 public function addGoogleCalendar(GoogleCalendar $googleCalendar): User {
236 $this->googleCalendars[] = $googleCalendar;
237
238 return $this;
239 }
240
241 /**
242 * Remove google calendar
243 *
244 * @param GoogleCalendar $googleCalendar
245 */
246 public function removeGoogleCalendar(GoogleCalendar $googleCalendar): bool {
247 return $this->googleCalendars->removeElement($googleCalendar);
248 }
249
250 /**
251 * Get google calendars
252 *
253 * @return \Doctrine\Common\Collections\Collection
254 */
255 public function getGoogleCalendars(): Collection {
256 return $this->googleCalendars;
257 }
258
259 /**
260 * Set user
261 *
262 * @param \Rapsys\AirBundle\Entity\User $user
263 *
264 * @return GoogleToken
265 */
266 public function setUser(User $user): GoogleToken {
267 $this->user = $user;
268
269 return $this;
270 }
271
272 /**
273 * Get user
274 *
275 * @return \Rapsys\AirBundle\Entity\User
276 */
277 public function getUser(): User {
278 return $this->user;
279 }
280
281 /**
282 * {@inheritdoc}
283 */
284 public function preUpdate(PreUpdateEventArgs $eventArgs): ?GoogleToken {
285 //Check that we have an snippet instance
286 if (($entity = $eventArgs->getEntity()) instanceof GoogleToken) {
287 //Set updated value
288 return $entity->setUpdated(new \DateTime('now'));
289 }
290 }
291 }