1 | <?php |
||
22 | class AdaptiveFilter extends ActionFilter |
||
23 | { |
||
24 | |||
25 | use DetectorTrait; |
||
26 | |||
27 | /** |
||
28 | * @var array list of request methods, which should allow page redirection in case wrong protocol is used. |
||
29 | * For all not listed request methods `BadRequestHttpException` will be thrown for secure action, while |
||
30 | * not secure ones will be allowed to be performed via secured protocol. |
||
31 | */ |
||
32 | public $redirectRequestMethods = ['GET', 'OPTIONS']; |
||
33 | |||
34 | /** |
||
35 | * @var integer the HTTP status code, which should be used in redirection. |
||
36 | */ |
||
37 | public $redirectStatusCode = 301; |
||
38 | |||
39 | /** |
||
40 | * @var array|string adaptive redirect url it can be an array like ['https://m.yourdomain.com', 'refer' => 'yourdomain.com'] |
||
41 | * or https://m.yourdomain.com/&refer=yourdomain.com |
||
42 | */ |
||
43 | public $redirectUrl; |
||
44 | |||
45 | /** |
||
46 | * @var bool weather you want to keep url requested path. |
||
47 | */ |
||
48 | public $keepUrlPath = false; |
||
49 | |||
50 | /** |
||
51 | * @var array|string|Request a [[Request]] component id or config of it using for prepare redirect url and checking should be redirect an user to adaptive url. |
||
52 | */ |
||
53 | public $request = 'request'; |
||
54 | |||
55 | /** |
||
56 | * @var array|string|Response a [[Response]] component id or config of it using for redirect an user. |
||
57 | */ |
||
58 | public $response = 'response'; |
||
59 | |||
60 | /** |
||
61 | * @inheritDoc |
||
62 | * @throws \yii\base\InvalidConfigException |
||
63 | */ |
||
64 | 8 | public function init() |
|
71 | |||
72 | /** |
||
73 | * @inheritDoc |
||
74 | * @throws InvalidConfigException |
||
75 | */ |
||
76 | 4 | public function beforeAction($action) |
|
88 | |||
89 | /** |
||
90 | * Get a adaptive redirect url |
||
91 | * |
||
92 | * @return string url |
||
93 | * @throws InvalidConfigException |
||
94 | */ |
||
95 | 4 | protected function getRedirectUrl(): string |
|
125 | |||
126 | /** |
||
127 | * Method checking should redirect to adaptive url or not. |
||
128 | * |
||
129 | * @return boolean whether current web request method is considered as 'read' type. |
||
130 | * @throws InvalidConfigException |
||
131 | */ |
||
132 | 4 | protected function shouldRedirect(): bool |
|
141 | |||
142 | |||
143 | } |
||
144 |