1 | <?php |
||
42 | class Provider extends ActiveRecordWithId |
||
43 | { |
||
44 | use HandleRulesTrait, |
||
45 | StateAttributeTrait; |
||
46 | |||
47 | /** |
||
48 | * The table alias |
||
49 | */ |
||
50 | const TABLE_ALIAS = 'patron_providers'; |
||
51 | |||
52 | const CLIENT_ID_LENGTH = 100; |
||
53 | const CLIENT_SECRET_LENGTH = 255; |
||
54 | |||
55 | protected $getterPriorityAttributes = ['settings']; |
||
56 | |||
57 | /** |
||
58 | * @inheritdoc |
||
59 | * @return ProviderActiveQuery |
||
60 | * @throws \yii\base\InvalidConfigException |
||
61 | */ |
||
62 | public static function find() |
||
63 | { |
||
64 | /** @noinspection PhpIncompatibleReturnTypeInspection */ |
||
65 | return Craft::createObject(ProviderActiveQuery::class, [get_called_class()]); |
||
66 | } |
||
67 | |||
68 | /** |
||
69 | * @inheritdoc |
||
70 | */ |
||
71 | protected static function findByCondition($condition) |
||
80 | |||
81 | /** |
||
82 | * @return string|null |
||
83 | */ |
||
84 | public function getIcon() |
||
94 | |||
95 | /** |
||
96 | * @return SettingsInterface |
||
97 | * @throws \yii\base\InvalidConfigException |
||
98 | */ |
||
99 | public function getSettings(): SettingsInterface |
||
113 | |||
114 | |||
115 | /** |
||
116 | * @param $record |
||
117 | * @param $row |
||
118 | */ |
||
119 | public static function populateRecord($record, $row) |
||
131 | |||
132 | /** |
||
133 | * @inheritdoc |
||
134 | */ |
||
135 | public function rules() |
||
190 | |||
191 | |||
192 | /******************************************* |
||
193 | * RELATIONS |
||
194 | *******************************************/ |
||
195 | |||
196 | /** |
||
197 | * Get all of the associated tokens. |
||
198 | * |
||
199 | * @param array $config |
||
200 | * @return \yii\db\ActiveQuery |
||
201 | */ |
||
202 | public function getTokens(array $config = []) |
||
218 | |||
219 | /** |
||
220 | * Get all of the associated tokens. |
||
221 | * |
||
222 | * @param array $config |
||
223 | * @return \yii\db\ActiveQuery |
||
224 | */ |
||
225 | public function getLocks(array $config = []) |
||
241 | |||
242 | /******************************************* |
||
243 | * SAVE |
||
244 | *******************************************/ |
||
245 | |||
246 | /** |
||
247 | * @param PluginInterface $plugin |
||
248 | * @param bool $runValidation |
||
249 | * @param null $attributeNames |
||
250 | * @return bool |
||
251 | */ |
||
252 | public function saveAndLock(PluginInterface $plugin, $runValidation = true, $attributeNames = null): bool |
||
260 | |||
261 | |||
262 | /******************************************* |
||
263 | * LOCK |
||
264 | *******************************************/ |
||
265 | |||
266 | /** |
||
267 | * @param PluginInterface $plugin |
||
268 | * @return bool |
||
269 | */ |
||
270 | public function addLock(PluginInterface $plugin): bool |
||
294 | |||
295 | /** |
||
296 | * @param PluginInterface $plugin |
||
297 | * @return bool |
||
298 | * @throws \Throwable |
||
299 | */ |
||
300 | public function removeLock(PluginInterface $plugin): bool |
||
315 | |||
316 | /** |
||
317 | * @return bool |
||
318 | */ |
||
319 | public function isLocked(): bool |
||
323 | |||
324 | /** |
||
325 | * @param PluginInterface $plugin |
||
326 | * @return int|null |
||
327 | */ |
||
328 | protected function getPluginId(PluginInterface $plugin) |
||
342 | |||
343 | /** |
||
344 | * @param PluginInterface $plugin |
||
345 | * @return int|null |
||
346 | */ |
||
347 | protected function getPluginName(PluginInterface $plugin) |
||
361 | |||
362 | |||
363 | /******************************************* |
||
364 | * DELETE |
||
365 | *******************************************/ |
||
366 | |||
367 | /** |
||
368 | * @param PluginInterface|null $plugin |
||
369 | * @return bool|false|int |
||
370 | * @throws \Throwable |
||
371 | * @throws \yii\db\StaleObjectException |
||
372 | */ |
||
373 | public function delete(PluginInterface $plugin = null) |
||
377 | |||
378 | /** |
||
379 | * @param PluginInterface|null $plugin |
||
380 | * @return bool |
||
381 | * @throws \craft\errors\InvalidPluginException |
||
382 | */ |
||
383 | protected function canDelete(PluginInterface $plugin = null) |
||
427 | |||
428 | /** |
||
429 | * @return string |
||
430 | * @throws \ReflectionException |
||
431 | */ |
||
432 | public function getDisplayName(): string |
||
433 | { |
||
434 | if (empty($this->class)) { |
||
435 | return 'Unknown'; |
||
436 | } |
||
437 | |||
438 | return ProviderHelper::displayName( |
||
439 | $this->class |
||
440 | ); |
||
441 | } |
||
442 | |||
443 | |||
444 | /******************************************* |
||
445 | * PROJECT CONFIG |
||
446 | *******************************************/ |
||
447 | |||
448 | /** |
||
449 | * Return an array suitable for Craft's Project config |
||
450 | */ |
||
451 | public function toProjectConfig(): array |
||
462 | } |
||
463 |