1 | <?php |
||
34 | class Token extends ActiveRecordWithId |
||
35 | { |
||
36 | use StateAttribute; |
||
37 | |||
38 | /** |
||
39 | * The table alias |
||
40 | */ |
||
41 | const TABLE_ALIAS = 'patron_tokens'; |
||
42 | |||
43 | /** |
||
44 | * @inheritdoc |
||
45 | * @return TokenActiveQuery |
||
46 | * @throws \yii\base\InvalidConfigException |
||
47 | */ |
||
48 | public static function find() |
||
49 | { |
||
50 | /** @noinspection PhpIncompatibleReturnTypeInspection */ |
||
51 | return Craft::createObject(TokenActiveQuery::class, [get_called_class()]); |
||
52 | } |
||
53 | |||
54 | /** |
||
55 | * @return bool |
||
56 | */ |
||
57 | public function isActive(): bool |
||
58 | { |
||
59 | return $this->isEnabled() && !$this->hasExpired(); |
||
60 | } |
||
61 | |||
62 | /** |
||
63 | * @return bool |
||
64 | */ |
||
65 | public function hasExpired(): bool |
||
66 | { |
||
67 | $dateExpires = $this->dateExpires ?: new DateTime('now'); |
||
68 | return DateTimeHelper::isInThePast($dateExpires); |
||
69 | } |
||
70 | |||
71 | /******************************************* |
||
72 | * EVENTS |
||
73 | *******************************************/ |
||
74 | |||
75 | /** |
||
76 | * @inheritdoc |
||
77 | * @throws \Throwable |
||
78 | */ |
||
79 | public function afterSave($insert, $changedAttributes) |
||
84 | |||
85 | |||
86 | /** |
||
87 | * @inheritdoc |
||
88 | */ |
||
89 | public function rules() |
||
137 | |||
138 | /** |
||
139 | * Get the associated Authorization |
||
140 | * |
||
141 | * @param array $config |
||
142 | * @return ActiveQueryInterface |
||
143 | */ |
||
144 | public function getProvider(array $config = []) |
||
160 | |||
161 | /** |
||
162 | * Get all of the associated environments. |
||
163 | * |
||
164 | * @param array $config |
||
165 | * @return \yii\db\ActiveQuery |
||
166 | */ |
||
167 | public function getEnvironments(array $config = []) |
||
183 | |||
184 | /** |
||
185 | * @param array $environments |
||
186 | * @return $this |
||
187 | */ |
||
188 | public function setEnvironments(array $environments = []) |
||
198 | |||
199 | /** |
||
200 | * @param string $key |
||
201 | * @param $environment |
||
202 | * @return TokenEnvironment |
||
203 | */ |
||
204 | protected function resolveEnvironment(string $key, $environment): TokenEnvironment |
||
220 | } |
||
221 |