1 | <?php |
||
33 | class Token extends ActiveRecordWithId |
||
34 | { |
||
35 | use StateAttribute, |
||
36 | traits\ProviderAttribute, |
||
37 | traits\RelatedEnvironmentsAttribute; |
||
38 | |||
39 | /** |
||
40 | * The table alias |
||
41 | */ |
||
42 | const TABLE_ALIAS = 'patron_tokens'; |
||
43 | |||
44 | /** |
||
45 | * @inheritdoc |
||
46 | */ |
||
47 | protected $getterPriorityAttributes = [ |
||
48 | 'providerId' |
||
49 | ]; |
||
50 | |||
51 | /******************************************* |
||
52 | * QUERY |
||
53 | *******************************************/ |
||
54 | |||
55 | /** |
||
56 | * @inheritdoc |
||
57 | * @return TokenActiveQuery |
||
58 | * @throws \yii\base\InvalidConfigException |
||
59 | */ |
||
60 | public static function find() |
||
61 | { |
||
62 | /** @noinspection PhpIncompatibleReturnTypeInspection */ |
||
63 | return Craft::createObject(TokenActiveQuery::class, [get_called_class()]); |
||
64 | } |
||
65 | |||
66 | /** |
||
67 | * @inheritdoc |
||
68 | */ |
||
69 | public function rules() |
||
110 | |||
111 | /** |
||
112 | * @return bool |
||
113 | */ |
||
114 | public function isActive(): bool |
||
115 | { |
||
116 | return $this->isEnabled() && !$this->hasExpired(); |
||
117 | } |
||
118 | |||
119 | /** |
||
120 | * @return bool |
||
121 | */ |
||
122 | public function hasExpired(): bool |
||
123 | { |
||
124 | $dateExpires = $this->dateExpires ?: new DateTime('now'); |
||
125 | return DateTimeHelper::isInThePast($dateExpires); |
||
126 | } |
||
127 | |||
128 | |||
129 | /******************************************* |
||
130 | * EVENTS |
||
131 | *******************************************/ |
||
132 | |||
133 | /** |
||
134 | * @inheritdoc |
||
135 | */ |
||
136 | public function beforeSave($insert): bool |
||
144 | |||
145 | |||
146 | /******************************************* |
||
147 | * UPDATE / INSERT |
||
148 | *******************************************/ |
||
149 | |||
150 | /** |
||
151 | * @inheritdoc |
||
152 | * @throws \Throwable |
||
153 | */ |
||
154 | protected function insertInternal($attributes = null) |
||
162 | |||
163 | /** |
||
164 | * @inheritdoc |
||
165 | * @throws \Throwable |
||
166 | */ |
||
167 | protected function updateInternal($attributes = null) |
||
175 | |||
176 | /******************************************* |
||
177 | * ENVIRONMENTS |
||
178 | *******************************************/ |
||
179 | |||
180 | /** |
||
181 | * @inheritdoc |
||
182 | */ |
||
183 | protected static function environmentRecordClass(): string |
||
187 | |||
188 | /** |
||
189 | * @inheritdoc |
||
190 | */ |
||
191 | protected function prepareEnvironmentRecordConfig(array $config = []): array |
||
196 | |||
197 | /** |
||
198 | * @inheritdoc |
||
199 | */ |
||
200 | protected function environmentRelationshipQuery(): ActiveQueryInterface |
||
207 | |||
208 | |||
209 | /** |
||
210 | * Get all of the associated provider instances. |
||
211 | * |
||
212 | * @param array $config |
||
213 | * @return \yii\db\ActiveQuery |
||
214 | */ |
||
215 | public function getInstances(array $config = []) |
||
231 | } |
||
232 |