1 | <?php |
||
29 | class Token extends ActiveRecordWithId |
||
30 | { |
||
31 | use StateAttributeTrait, |
||
32 | ProviderAttributeTrait; |
||
33 | |||
34 | /** |
||
35 | * The table alias |
||
36 | */ |
||
37 | const TABLE_ALIAS = 'patron_tokens'; |
||
38 | |||
39 | /** |
||
40 | * @inheritdoc |
||
41 | */ |
||
42 | protected $getterPriorityAttributes = [ |
||
43 | 'providerId' |
||
44 | ]; |
||
45 | |||
46 | /******************************************* |
||
47 | * QUERY |
||
48 | *******************************************/ |
||
49 | |||
50 | /** |
||
51 | * @inheritdoc |
||
52 | * @return TokenActiveQuery |
||
53 | * @throws \yii\base\InvalidConfigException |
||
54 | */ |
||
55 | public static function find() |
||
56 | { |
||
57 | /** @noinspection PhpIncompatibleReturnTypeInspection */ |
||
58 | return Craft::createObject(TokenActiveQuery::class, [get_called_class()]); |
||
59 | } |
||
60 | |||
61 | /** |
||
62 | * @inheritdoc |
||
63 | */ |
||
64 | public function rules() |
||
105 | |||
106 | /** |
||
107 | * @return bool |
||
108 | */ |
||
109 | public function isActive(): bool |
||
110 | { |
||
111 | return $this->isEnabled() && !$this->hasExpired(); |
||
112 | } |
||
113 | |||
114 | /** |
||
115 | * @return bool |
||
116 | */ |
||
117 | public function hasExpired(): bool |
||
118 | { |
||
119 | $dateExpires = $this->dateExpires ?: new DateTime('now'); |
||
120 | return DateTimeHelper::isInThePast($dateExpires); |
||
121 | } |
||
122 | |||
123 | |||
124 | /******************************************* |
||
125 | * PROJECT CONFIG |
||
126 | *******************************************/ |
||
127 | |||
128 | /** |
||
129 | * Return an array suitable for Craft's Project config |
||
130 | */ |
||
131 | public function toProjectConfig(): array |
||
141 | } |
||
142 |