BackendController::behaviors()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 20
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 11
nc 1
nop 0
1
<?php
2
3
namespace inblank\activeuser\components;
4
5
use inblank\activeuser\traits\CommonTrait;
6
use yii;
7
use yii\filters\AccessControl;
8
use yii\filters\VerbFilter;
9
use yii\web\Controller;
10
use yii\web\ForbiddenHttpException;
11
12
/**
13
 * Class BackendController
14
 * @package inblank\activeuser\components
15
 *
16
 * @property \inblank\activeuser\Module $module
17
 */
18
class BackendController extends Controller{
19
20
    use CommonTrait;
21
22
    public function init(){
23
        parent::init();
24
        $this->getView()->params['frontendUrlManager'] = $this->module->frontendUrlManager;
25
    }
26
27
    public function behaviors()
28
    {
29
        return [
30
            'access' => [
31
                'class' => AccessControl::className(),
0 ignored issues
show
Deprecated Code introduced by
The method yii\base\BaseObject::className() has been deprecated with message: since 2.0.14. On PHP >=5.5, use `::class` instead.

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.

Loading history...
32
                'rules' => [
33
                    [
34
                        'allow' => true,
35
                        'roles' => ['adminAccess'],
36
                    ],
37
                ],
38
            ],
39
            'verbs' => [
40
                'class' => VerbFilter::className(),
0 ignored issues
show
Deprecated Code introduced by
The method yii\base\BaseObject::className() has been deprecated with message: since 2.0.14. On PHP >=5.5, use `::class` instead.

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.

Loading history...
41
                'actions' => [
42
                    'delete' => ['post'],
43
                ],
44
            ],
45
        ];
46
    }
47
48
    public function checkPermission($permission, $params = []){
49
        if(Yii::$app->authManager) {
50
            if (!Yii::$app->user->can($permission, $params)) {
51
                throw new ForbiddenHttpException(Yii::t('activeuser_backend', "You can't perform this action"));
52
            }
53
        }
54
    }
55
}
56