1 | <?php |
||
33 | class Controller extends \yii\web\Controller |
||
34 | { |
||
35 | /** |
||
36 | * @var string|array the configuration for creating the serializer that formats the response data. |
||
37 | */ |
||
38 | public $serializer = 'yii\rest\Serializer'; |
||
39 | /** |
||
40 | * @inheritdoc |
||
41 | */ |
||
42 | public $enableCsrfValidation = false; |
||
43 | |||
44 | |||
45 | /** |
||
46 | * @inheritdoc |
||
47 | */ |
||
48 | public function behaviors() |
||
49 | { |
||
50 | return [ |
||
51 | 'contentNegotiator' => [ |
||
52 | 'class' => ContentNegotiator::className(), |
||
53 | 'formats' => [ |
||
54 | 'application/json' => Response::FORMAT_JSON, |
||
55 | 'application/xml' => Response::FORMAT_XML, |
||
56 | ], |
||
57 | ], |
||
58 | 'verbFilter' => [ |
||
59 | 'class' => VerbFilter::className(), |
||
60 | 'actions' => $this->verbs(), |
||
61 | ], |
||
62 | 'authenticator' => [ |
||
63 | 'class' => CompositeAuth::className(), |
||
64 | ], |
||
65 | 'rateLimiter' => [ |
||
66 | 'class' => RateLimiter::className(), |
||
67 | ], |
||
68 | ]; |
||
69 | } |
||
70 | |||
71 | /** |
||
72 | * @inheritdoc |
||
73 | */ |
||
74 | 23 | public function afterAction($action, $result) |
|
79 | |||
80 | /** |
||
81 | * Declares the allowed HTTP verbs. |
||
82 | * Please refer to [[VerbFilter::actions]] on how to declare the allowed verbs. |
||
83 | * @return array the allowed HTTP verbs. |
||
84 | */ |
||
85 | protected function verbs() |
||
89 | |||
90 | /** |
||
91 | * Serializes the specified data. |
||
92 | * The default implementation will create a serializer based on the configuration given by [[serializer]]. |
||
93 | * It then uses the serializer to serialize the given data. |
||
94 | * @param mixed $data the data to be serialized |
||
95 | * @return mixed the serialized data. |
||
96 | */ |
||
97 | 23 | protected function serializeData($data) |
|
101 | } |
||
102 |