1 | <?php |
||
32 | class Patron extends Plugin |
||
33 | { |
||
34 | /** |
||
35 | * @inheritdoc |
||
36 | */ |
||
37 | 15 | public function init() |
|
38 | { |
||
39 | 15 | parent::init(); |
|
40 | |||
41 | // Components |
||
42 | 15 | $this->setComponents([ |
|
43 | 15 | 'providers' => services\Providers::class, |
|
44 | 'tokens' => services\Tokens::class, |
||
45 | 'manageProviders' => services\ManageProviders::class, |
||
46 | 'manageTokens' => services\ManageTokens::class, |
||
47 | 'session' => services\Session::class |
||
48 | ]); |
||
49 | |||
50 | // Modules |
||
51 | 15 | $this->setModules([ |
|
52 | 15 | 'cp' => cp\Cp::class |
|
53 | |||
54 | ]); |
||
55 | |||
56 | // Template variables |
||
57 | 15 | Event::on( |
|
58 | 15 | CraftVariable::class, |
|
59 | 15 | CraftVariable::EVENT_INIT, |
|
60 | function (Event $event) { |
||
61 | /** @var CraftVariable $variable */ |
||
62 | $variable = $event->sender; |
||
63 | $variable->set('patron', self::getInstance()); |
||
64 | 15 | } |
|
65 | ); |
||
66 | |||
67 | // CP routes |
||
68 | 15 | Event::on( |
|
69 | 15 | UrlManager::class, |
|
70 | 15 | UrlManager::EVENT_REGISTER_CP_URL_RULES, |
|
71 | 15 | [self::class, 'onRegisterCpUrlRules'] |
|
72 | ); |
||
73 | |||
74 | // Register our site routes |
||
75 | 15 | Event::on( |
|
76 | 15 | UrlManager::class, |
|
77 | 15 | UrlManager::EVENT_REGISTER_SITE_URL_RULES, |
|
78 | function (RegisterUrlRulesEvent $event) { |
||
79 | if ($callbackUrlRule = $this->getSettings()->getCallbackUrlRule()) { |
||
80 | $event->rules = array_merge( |
||
81 | $event->rules, |
||
82 | $callbackUrlRule |
||
83 | ); |
||
84 | } |
||
85 | 15 | } |
|
86 | ); |
||
87 | 15 | } |
|
88 | |||
89 | /** |
||
90 | * @inheritdoc |
||
91 | */ |
||
92 | public function getCpNavItem() |
||
110 | |||
111 | /** |
||
112 | * @inheritdoc |
||
113 | * @return SettingsModel |
||
114 | */ |
||
115 | public function createSettingsModel() |
||
119 | |||
120 | /** |
||
121 | * @inheritdoc |
||
122 | * @throws \yii\base\ExitException |
||
123 | */ |
||
124 | public function getSettingsResponse() |
||
132 | |||
133 | /******************************************* |
||
134 | * SERVICES |
||
135 | *******************************************/ |
||
136 | |||
137 | /** |
||
138 | * @noinspection PhpDocMissingThrowsInspection |
||
139 | * @return services\Providers |
||
140 | */ |
||
141 | 3 | public function getProviders(): services\Providers |
|
142 | { |
||
143 | /** @noinspection PhpUnhandledExceptionInspection */ |
||
144 | /** @noinspection PhpIncompatibleReturnTypeInspection */ |
||
145 | 3 | return $this->get('providers'); |
|
146 | } |
||
147 | |||
148 | /** |
||
149 | * @noinspection PhpDocMissingThrowsInspection |
||
150 | * @return services\Tokens |
||
151 | */ |
||
152 | 3 | public function getTokens(): services\Tokens |
|
153 | { |
||
154 | /** @noinspection PhpUnhandledExceptionInspection */ |
||
155 | /** @noinspection PhpIncompatibleReturnTypeInspection */ |
||
156 | 3 | return $this->get('tokens'); |
|
157 | } |
||
158 | |||
159 | /** |
||
160 | * @noinspection PhpDocMissingThrowsInspection |
||
161 | * @return services\ManageProviders |
||
162 | */ |
||
163 | 3 | public function manageProviders(): services\ManageProviders |
|
164 | { |
||
165 | /** @noinspection PhpUnhandledExceptionInspection */ |
||
166 | /** @noinspection PhpIncompatibleReturnTypeInspection */ |
||
167 | 3 | return $this->get('manageProviders'); |
|
168 | } |
||
169 | |||
170 | /** |
||
171 | * @noinspection PhpDocMissingThrowsInspection |
||
172 | * @return services\ManageTokens |
||
173 | */ |
||
174 | 3 | public function manageTokens(): services\ManageTokens |
|
175 | { |
||
176 | /** @noinspection PhpUnhandledExceptionInspection */ |
||
177 | /** @noinspection PhpIncompatibleReturnTypeInspection */ |
||
178 | 3 | return $this->get('manageTokens'); |
|
179 | } |
||
180 | |||
181 | /** |
||
182 | * @noinspection PhpDocMissingThrowsInspection |
||
183 | * @return services\Session |
||
184 | */ |
||
185 | 3 | public function getSession(): services\Session |
|
191 | |||
192 | |||
193 | /******************************************* |
||
194 | * MODULES |
||
195 | *******************************************/ |
||
196 | |||
197 | /** |
||
198 | * @noinspection PhpDocMissingThrowsInspection |
||
199 | * @return cp\Cp |
||
200 | */ |
||
201 | public function getCp(): cp\Cp |
||
207 | |||
208 | /******************************************* |
||
209 | * EVENTS |
||
210 | *******************************************/ |
||
211 | |||
212 | /** |
||
213 | * @param RegisterUrlRulesEvent $event |
||
214 | */ |
||
215 | public static function onRegisterCpUrlRules(RegisterUrlRulesEvent $event) |
||
231 | |||
232 | |||
233 | /******************************************* |
||
234 | * LOGGING |
||
235 | *******************************************/ |
||
236 | |||
237 | /** |
||
238 | * Logs an informative message. |
||
239 | * |
||
240 | * @param $message |
||
241 | * @param string $category |
||
242 | */ |
||
243 | public static function info($message, $category = 'patron') |
||
247 | |||
248 | /** |
||
249 | * Logs a warning message. |
||
250 | * |
||
251 | * @param $message |
||
252 | * @param string $category |
||
253 | */ |
||
254 | public static function warning($message, $category = 'patron') |
||
258 | |||
259 | /** |
||
260 | * Logs an error message. |
||
261 | * |
||
262 | * @param $message |
||
263 | * @param string $category |
||
264 | */ |
||
265 | public static function error($message, $category = 'patron') |
||
269 | } |
||
270 |