1 | <?php |
||
37 | class Provider extends ActiveRecordWithId |
||
38 | { |
||
39 | use HandleRules, |
||
40 | StateAttribute; |
||
41 | |||
42 | /** |
||
43 | * The table alias |
||
44 | */ |
||
45 | const TABLE_ALIAS = 'patron_providers'; |
||
46 | |||
47 | /** |
||
48 | * @var SettingsInterface |
||
49 | */ |
||
50 | private $settingsModel; |
||
51 | |||
52 | /** |
||
53 | * The length of the identifier |
||
54 | */ |
||
55 | const CLIENT_ID_LENGTH = 100; |
||
56 | |||
57 | /** |
||
58 | * The length of the secret |
||
59 | */ |
||
60 | const CLIENT_SECRET_LENGTH = 100; |
||
61 | |||
62 | /** |
||
63 | * @return string|null |
||
64 | */ |
||
65 | public function getIcon() |
||
75 | |||
76 | /** |
||
77 | * @inheritdoc |
||
78 | * @return ProviderActiveQuery |
||
79 | * @throws \yii\base\InvalidConfigException |
||
80 | */ |
||
81 | public static function find() |
||
82 | { |
||
83 | /** @noinspection PhpIncompatibleReturnTypeInspection */ |
||
84 | return Craft::createObject(ProviderActiveQuery::class, [get_called_class()]); |
||
85 | } |
||
86 | |||
87 | /** |
||
88 | * @inheritdoc |
||
89 | */ |
||
90 | public function rules() |
||
139 | |||
140 | /** |
||
141 | * Get all of the associated tokens. |
||
142 | * |
||
143 | * @param array $config |
||
144 | * @return \yii\db\ActiveQuery |
||
145 | */ |
||
146 | public function getTokens(array $config = []) |
||
162 | |||
163 | /** |
||
164 | * Get all of the associated environments. |
||
165 | * |
||
166 | * @param array $config |
||
167 | * @return \yii\db\ActiveQuery |
||
168 | */ |
||
169 | public function getEnvironments(array $config = []) |
||
185 | |||
186 | /** |
||
187 | * @param array $environments |
||
188 | * @return $this |
||
189 | */ |
||
190 | public function setEnvironments(array $environments = []) |
||
200 | |||
201 | /** |
||
202 | * @param string $key |
||
203 | * @param $environment |
||
204 | * @return ProviderEnvironment |
||
205 | */ |
||
206 | protected function resolveEnvironment(string $key, $environment): ProviderEnvironment |
||
222 | |||
223 | /******************************************* |
||
224 | * EVENTS |
||
225 | *******************************************/ |
||
226 | |||
227 | |||
228 | /** |
||
229 | * @inheritdoc |
||
230 | * @throws \Throwable |
||
231 | */ |
||
232 | public function afterSave($insert, $changedAttributes) |
||
237 | |||
238 | /** |
||
239 | * @return string |
||
240 | */ |
||
241 | public function getDisplayName(): string |
||
242 | { |
||
243 | return ProviderHelper::displayName( |
||
244 | $this->class |
||
245 | ); |
||
246 | } |
||
247 | |||
248 | /** |
||
249 | * @return Twig_Markup |
||
250 | * @throws \yii\base\InvalidConfigException |
||
251 | */ |
||
252 | public function getSettingsHtml(): Twig_Markup |
||
253 | { |
||
254 | return Template::raw( |
||
255 | $this->getSettingsModel()->inputHtml() |
||
256 | ); |
||
257 | } |
||
258 | |||
259 | /** |
||
260 | * @return SettingsInterface |
||
261 | * @throws \yii\base\InvalidConfigException |
||
262 | */ |
||
263 | protected function getSettingsModel(): SettingsInterface |
||
264 | { |
||
265 | if (!$this->settingsModel instanceof SettingsInterface) { |
||
266 | $this->settingsModel = Patron::getInstance()->manageProviders()->resolveSettings($this, $this->settings); |
||
267 | } |
||
268 | |||
269 | return $this->settingsModel; |
||
270 | } |
||
271 | } |
||
272 |