]> Raphaël G. Git Repositories - airbundle/blob - Entity/GoogleToken.php
Pass google client and default markdown to constructor
[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 * Primary key
24 */
25 private ?int $id = null;
26
27 /**
28 * Create datetime
29 */
30 private \DateTime $created;
31
32 /**
33 * Update datetime
34 */
35 private \DateTime $updated;
36
37 /**
38 * Google calendars collection
39 */
40 private Collection $googleCalendars;
41
42 /**
43 * Constructor
44 *
45 * @param User $user The user instance
46 * @param string The token user mail
47 * @param string The access token identifier
48 * @param \DateTime The access token expires
49 * @param ?string The refresh token identifier
50 */
51 public function __construct(private User $user, private string $mail, private string $access, private \DateTime $expired, private ?string $refresh = null) {
52 //Set defaults
53 $this->created = new \DateTime('now');
54 $this->updated = new \DateTime('now');
55
56 //Set collections
57 $this->googleCalendars = new ArrayCollection();
58 }
59
60 /**
61 * Get id
62 *
63 * @return ?int
64 */
65 public function getId(): ?int {
66 return $this->id;
67 }
68
69 /**
70 * Set mail
71 *
72 * @param string $mail
73 * @return GoogleToken
74 */
75 public function setMail(string $mail): GoogleToken {
76 $this->mail = $mail;
77
78 return $this;
79 }
80
81 /**
82 * Get mail
83 *
84 * @return string
85 */
86 public function getMail(): string {
87 return $this->mail;
88 }
89
90 /**
91 * Set access
92 *
93 * @param string $access
94 *
95 * @return GoogleToken
96 */
97 public function setAccess(string $access): GoogleToken {
98 $this->access = $access;
99
100 return $this;
101 }
102
103 /**
104 * Get access
105 *
106 * @return string
107 */
108 public function getAccess(): string {
109 return $this->access;
110 }
111
112 /**
113 * Set refresh
114 *
115 * @param string $refresh
116 *
117 * @return GoogleToken
118 */
119 public function setRefresh(?string $refresh): GoogleToken {
120 $this->refresh = $refresh;
121
122 return $this;
123 }
124
125 /**
126 * Get refresh
127 *
128 * @return string
129 */
130 public function getRefresh(): ?string {
131 return $this->refresh;
132 }
133
134 /**
135 * Set expired
136 *
137 * @param \DateTime $expired
138 *
139 * @return GoogleToken
140 */
141 public function setExpired(\DateTime $expired): GoogleToken {
142 $this->expired = $expired;
143
144 return $this;
145 }
146
147 /**
148 * Get expired
149 *
150 * @return \DateTime
151 */
152 public function getExpired(): \DateTime {
153 return $this->expired;
154 }
155
156 /**
157 * Set created
158 *
159 * @param \DateTime $created
160 *
161 * @return GoogleToken
162 */
163 public function setCreated(\DateTime $created): GoogleToken {
164 $this->created = $created;
165
166 return $this;
167 }
168
169 /**
170 * Get created
171 *
172 * @return \DateTime
173 */
174 public function getCreated(): \DateTime {
175 return $this->created;
176 }
177
178 /**
179 * Set updated
180 *
181 * @param \DateTime $updated
182 *
183 * @return GoogleToken
184 */
185 public function setUpdated(\DateTime $updated): GoogleToken {
186 $this->updated = $updated;
187
188 return $this;
189 }
190
191 /**
192 * Get updated
193 *
194 * @return \DateTime
195 */
196 public function getUpdated(): \DateTime {
197 return $this->updated;
198 }
199
200 /**
201 * Add google calendar
202 *
203 * @param GoogleCalendar $googleCalendar
204 *
205 * @return User
206 */
207 public function addGoogleCalendar(GoogleCalendar $googleCalendar): User {
208 $this->googleCalendars[] = $googleCalendar;
209
210 return $this;
211 }
212
213 /**
214 * Remove google calendar
215 *
216 * @param GoogleCalendar $googleCalendar
217 */
218 public function removeGoogleCalendar(GoogleCalendar $googleCalendar): bool {
219 return $this->googleCalendars->removeElement($googleCalendar);
220 }
221
222 /**
223 * Get google calendars
224 *
225 * @return \Doctrine\Common\Collections\Collection
226 */
227 public function getGoogleCalendars(): Collection {
228 return $this->googleCalendars;
229 }
230
231 /**
232 * Set user
233 *
234 * @param \Rapsys\AirBundle\Entity\User $user
235 *
236 * @return GoogleToken
237 */
238 public function setUser(User $user): GoogleToken {
239 $this->user = $user;
240
241 return $this;
242 }
243
244 /**
245 * Get user
246 *
247 * @return \Rapsys\AirBundle\Entity\User
248 */
249 public function getUser(): User {
250 return $this->user;
251 }
252
253 /**
254 * {@inheritdoc}
255 */
256 public function preUpdate(PreUpdateEventArgs $eventArgs): ?GoogleToken {
257 //Check that we have an snippet instance
258 if (($entity = $eventArgs->getObject()) instanceof GoogleToken) {
259 //Set updated value
260 return $entity->setUpdated(new \DateTime('now'));
261 }
262 }
263 }