|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- <?php
-
-
- namespace yii\rest;
-
- use Yii;
- use yii\filters\auth\CompositeAuth;
- use yii\filters\ContentNegotiator;
- use yii\filters\RateLimiter;
- use yii\web\Response;
- use yii\filters\VerbFilter;
-
-
- class Controller extends \yii\web\Controller
- {
-
-
- public $serializer = 'yii\rest\Serializer';
-
-
- public $enableCsrfValidation = false;
-
-
-
-
- public function behaviors()
- {
- return [
- 'contentNegotiator' => [
- 'class' => ContentNegotiator::className(),
- 'formats' => [
- 'application/json' => Response::FORMAT_JSON,
- 'application/xml' => Response::FORMAT_XML,
- ],
- ],
- 'verbFilter' => [
- 'class' => VerbFilter::className(),
- 'actions' => $this->verbs(),
- ],
- 'authenticator' => [
- 'class' => CompositeAuth::className(),
- ],
- 'rateLimiter' => [
- 'class' => RateLimiter::className(),
- ],
- ];
- }
-
-
-
- public function afterAction($action, $result)
- {
- $result = parent::afterAction($action, $result);
- return $this->serializeData($result);
- }
-
-
-
- protected function verbs()
- {
- return [];
- }
-
-
-
- protected function serializeData($data)
- {
- return Yii::createObject($this->serializer)->serialize($data);
- }
- }
|