1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace zacksleo\yii2\oauth2\api\components; |
4
|
|
|
|
5
|
|
|
use yii\rest\Controller; |
6
|
|
|
use yii\helpers\ArrayHelper; |
7
|
|
|
use zacksleo\yii2\oauth2\api\filters\ErrorToExceptionFilter; |
8
|
|
|
use yii\filters\ContentNegotiator; |
9
|
|
|
use yii\web\Response; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class AuthController |
13
|
|
|
*/ |
14
|
|
|
class RestController extends Controller |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @inheritdoc |
18
|
|
|
*/ |
19
|
|
|
public function behaviors() |
20
|
|
|
{ |
21
|
|
|
$behaviors = ArrayHelper::merge(parent::behaviors(), [ |
22
|
|
|
'exceptionFilter' => [ |
23
|
|
|
'class' => ErrorToExceptionFilter::className() |
|
|
|
|
24
|
|
|
], |
25
|
|
|
[ |
26
|
|
|
'class' => ContentNegotiator::className(), |
|
|
|
|
27
|
|
|
'formats' => [ |
28
|
|
|
'application/json' => Response::FORMAT_JSON, |
29
|
|
|
], |
30
|
|
|
'languages' => [ |
31
|
|
|
'zh-CN', |
32
|
|
|
'zh-TW', |
33
|
|
|
'en-US', |
34
|
|
|
], |
35
|
|
|
], |
36
|
|
|
]); |
37
|
|
|
$auth = $behaviors['authenticator']; |
38
|
|
|
unset($behaviors['authenticator']); |
39
|
|
|
$behaviors['corsFilter'] = [ |
40
|
|
|
'class' => \yii\filters\Cors::className(), |
|
|
|
|
41
|
|
|
'cors' => [ |
42
|
|
|
'Origin' => ['*'], |
43
|
|
|
'Access-Control-Request-Method' => ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS'], |
44
|
|
|
'Access-Control-Request-Headers' => ['*'], |
45
|
|
|
'Access-Control-Allow-Credentials' => null, |
46
|
|
|
'Access-Control-Max-Age' => 86400, |
47
|
|
|
'Access-Control-Expose-Headers' => [ |
48
|
|
|
'X-Pagination-Current-Page', |
49
|
|
|
'X-Pagination-Page-Count', |
50
|
|
|
'X-Pagination-Per-Page', |
51
|
|
|
'X-Pagination-Total-Count' |
52
|
|
|
], |
53
|
|
|
], |
54
|
|
|
]; |
55
|
|
|
$behaviors['authenticator'] = $auth; |
56
|
|
|
$behaviors['authenticator']['except'] = ['options']; |
57
|
|
|
return $behaviors; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @inheritdoc |
62
|
|
|
*/ |
63
|
|
|
public function actions() |
64
|
|
|
{ |
65
|
|
|
return [ |
66
|
|
|
'options' => [ |
67
|
|
|
'class' => 'yii\rest\OptionsAction', |
68
|
|
|
], |
69
|
|
|
]; |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.