Inheritance: extends yii\base\Behavior
コード例 #1
0
ファイル: Controller.php プロジェクト: portalsway2/APEDevices
 /**
  * @inheritdoc
  */
 public function behaviors()
 {
     $behaviors = ArrayHelper::merge(parent::behaviors(), ['authenticator' => ['class' => CompositeAuth::className(), 'authMethods' => [['class' => HttpBearerAuth::className()], ['class' => QueryParamAuth::className(), 'tokenParam' => 'accessToken']]], 'exceptionFilter' => ['class' => ErrorToExceptionFilter::className()], 'corsFilter' => ['class' => \backend\rest\filters\Cors::className(), 'cors' => ['Origin' => ['*'], 'Access-Control-Request-Method' => ['POST', 'PUT', 'OPTIONS', 'PATCH', 'DELETE'], 'Access-Control-Request-Headers' => ['X-Pagination-Total-Count', 'X-Pagination-Page-Count', 'X-Pagination-Current-Page', 'X-Pagination-Per-Page', 'Content-Length', 'Content-type', 'Link'], 'Access-Control-Allow-Credentials' => true, 'Access-Control-Max-Age' => 3600, 'Access-Control-Expose-Headers' => ['X-Pagination-Total-Count', 'X-Pagination-Page-Count', 'X-Pagination-Current-Page', 'X-Pagination-Per-Page', 'Content-Length', 'Content-type', 'Link'], 'Access-Control-Allow-Headers' => ['X-Pagination-Total-Count', 'X-Pagination-Page-Count', 'X-Pagination-Current-Page', 'X-Pagination-Per-Page', 'Content-Length', 'Content-type', 'Link']]]]);
     if (isset(\Yii::$app->params['httpCacheActive']) and \Yii::$app->params['httpCacheActive']) {
         $params = \Yii::$app->getRequest()->getQueryParams();
         unset($params['accessToken']);
         $behaviors['httpCache'] = ['class' => HttpCache::className(), 'params' => $params, 'lastModified' => function ($action, $params) {
             $q = new \yii\db\Query();
             $class = $this->modelClass;
             if (in_array('updated_at', $class::getTableSchema()->getColumnNames())) {
                 return strtotime($q->from($class::tableName())->max('updated_at'));
             }
             if (in_array('modified', $class::getTableSchema()->getColumnNames())) {
                 return strtotime($q->from($class::tableName())->max('modified'));
             }
             return null;
         }, 'etagSeed' => function (Action $action, $params) {
             $iterator = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($params));
             $keys = array();
             foreach ($iterator as $key => $value) {
                 // Build long key name based on parent keys
                 for ($i = $iterator->getDepth() - 1; $i >= 0; $i--) {
                     $key = $iterator->getSubIterator($i)->key() . '_' . $key;
                     if (!is_array($iterator->getSubIterator($i)->current())) {
                         $value = $iterator->getSubIterator($i)->current() . '_' . $value;
                     }
                 }
                 $keys[] = $key . '-' . $value;
             }
             $uniqueId = implode('-', $keys);
             return $uniqueId;
         }];
     }
     return $behaviors;
 }
コード例 #2
0
 public function behaviors()
 {
     $behaviors = parent::behaviors();
     // replace to top contentNegotiator filter for displaying errors in correct format
     $content_negotiator = $behaviors['contentNegotiator'];
     unset($behaviors['contentNegotiator']);
     $content_negotiator['formats'] = Yii::$app->params['formats'];
     $behaviors = ArrayHelper::merge(['contentNegotiator' => $content_negotiator, 'oauth2access' => ['class' => OAuth2AccessFilter::className()], 'exceptionFilter' => ['class' => ErrorToExceptionFilter::className()]], $behaviors, ['access' => ['class' => AccessControl::className(), 'rules' => $this->accessRules(), 'ruleConfig' => ['class' => 'api\\components\\AccessRule']]]);
     return $behaviors;
 }
コード例 #3
0
ファイル: UserController.php プロジェクト: no7kpo/denm
 public function behaviors()
 {
     return ArrayHelper::merge(parent::behaviors(), ['authenticator' => ['class' => CompositeAuth::className(), 'authMethods' => [['class' => HttpBearerAuth::className()], ['class' => QueryParamAuth::className(), 'tokenParam' => 'accessToken']]], 'exceptionFilter' => ['class' => ErrorToExceptionFilter::className()]]);
 }
コード例 #4
0
 /**
  * @inheritdoc
  */
 public function behaviors()
 {
     return ArrayHelper::merge(parent::behaviors(), ['exceptionFilter' => ['class' => ErrorToExceptionFilter::className()], 'corsFilter' => ['class' => \backend\rest\filters\Cors::className(), 'cors' => ['Origin' => ['*'], 'Access-Control-Request-Method' => ['POST', 'PUT', 'OPTIONS', 'PATCH', 'DELETE'], 'Access-Control-Request-Headers' => ['X-Pagination-Total-Count', 'X-Pagination-Page-Count', 'X-Pagination-Current-Page', 'X-Pagination-Per-Page', 'Content-Length', 'Content-type', 'Link'], 'Access-Control-Allow-Credentials' => true, 'Access-Control-Max-Age' => 3600, 'Access-Control-Expose-Headers' => ['X-Pagination-Total-Count', 'X-Pagination-Page-Count', 'X-Pagination-Current-Page', 'X-Pagination-Per-Page', 'Content-Length', 'Content-type', 'Link'], 'Access-Control-Allow-Headers' => ['X-Pagination-Total-Count', 'X-Pagination-Page-Count', 'X-Pagination-Current-Page', 'X-Pagination-Per-Page', 'Content-Length', 'Content-type', 'Link']]]]);
 }
コード例 #5
0
 /**
  * @inheritdoc
  */
 public function behaviors()
 {
     return ['verbFilter' => ['class' => VerbFilter::className(), 'actions' => $this->verbs()], 'exceptionFilter' => ['class' => ErrorToExceptionFilter::className()]];
 }
コード例 #6
0
ファイル: RestController.php プロジェクト: weiyiyi/base
 /**
  * @inheritdoc
  */
 public function behaviors()
 {
     return ArrayHelper::merge(parent::behaviors(), ['exceptionFilter' => ['class' => ErrorToExceptionFilter::className()]]);
 }
コード例 #7
0
 /**
  * @inheritdoc
  */
 public function behaviors()
 {
     return ArrayHelper::merge([['class' => Cors::className(), 'cors' => ['Origin' => ['*'], 'Access-Control-Request-Method' => ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS'], 'Access-Control-Request-Headers' => ['*'], 'Access-Control-Allow-Headers' => ['*'], 'Access-Control-Allow-Credentials' => true, 'Access-Control-Expose-Headers' => ['Link', 'X-Pagination-Current-Page', 'X-Pagination-Page-Count', 'X-Pagination-Per-Page', 'X-Pagination-Total-Count']]], 'authenticator' => ['class' => CompositeAuth::className(), 'except' => $this->authenticatorExceptions, 'authMethods' => [['class' => HttpBearerAuth::className()], ['class' => QueryParamAuth::className(), 'tokenParam' => 'accessToken']]], 'exceptionFilter' => ['class' => ErrorToExceptionFilter::className()]], parent::behaviors());
 }