1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- <?php
- namespace backend\controllers;
- use components\Exception;
- use yii\helpers\ArrayHelper;
- use yii\web\Controller;
- /**
- * Class BaseController
- * @package backend\controllers
- */
- class BaseController extends Controller
- {
- /**
- * init
- */
- public function init()
- {
- \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
- parent::init();
- }
- /**
- * behaviors
- * @return array
- */
- public function behaviors()
- {
- return ArrayHelper::merge(parent::behaviors(), [
- 'bearerAuth' => [
- 'class' => \common\filters\auth\BearerAuth::className(),
- //'class' => \yii\filters\auth\HttpBearerAuth::className(),
- 'optional' => [
- 'token',
- 'signature',
- 'test',
- ],
- ]
- ] );
- }
- /**
- * beforeAction
- * @return bool
- * @throws Exception
- */
- public function beforeAction($action)
- {
- try {
- return parent::beforeAction($action);
- } catch (\Exception $e) {
- throw new Exception(isset($e->statusCode) ? $e->statusCode : $e->getCode(), $e->getMessage());
- }
- }
- }
|