Completed
Push — master ( 98ec57...b39146 )
by Andrii
02:05
created

RbacController   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 6
c 1
b 0
f 1
lcom 0
cbo 3
dl 0
loc 40
ccs 0
cts 30
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A actionInit() 0 5 1
A actionReinit() 0 5 1
B actionShow() 0 23 4
1
<?php
2
/**
3
 * RBAC implementation for HiPanel.
4
 *
5
 * @link      https://github.com/hiqdev/hipanel-rbac
6
 * @package   hipanel-rbac
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2016-2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hipanel\rbac\console;
12
13
use hipanel\rbac\Initer;
14
use Yii;
15
16
/**
17
 * Class RbacController.
18
 *
19
 * Usage: `hidev rbac/init`
20
 */
21
class RbacController extends \yii\console\Controller
22
{
23
    public $defaultAction = 'show';
24
25
    public function actionInit()
26
    {
27
        $auth = Yii::$app->get('authManager');
28
        Initer::init($auth);
29
    }
30
31
    public function actionReinit()
32
    {
33
        $auth = Yii::$app->get('authManager');
34
        Initer::reinit($auth);
35
    }
36
37
    public function actionShow()
38
    {
39
        $auth = Yii::$app->get('authManager');
40
41
        echo "Permissions:\n";
42
        $permissions = $auth->getPermissions();
43
        ksort($permissions);
44
        foreach ($permissions as $name => $perm) {
45
            echo "   $perm->name $perm->description\n";
46
        }
47
48
        echo "Roles:\n";
49
        foreach ($auth->getRoles() as $name => $role) {
50
            $children = implode(',', array_keys($auth->getChildren($name)));
51
            printf("   %-12s %s\n", "$role->name:", $children);
52
        }
53
54
        echo "Assignments:\n";
55
        foreach ($auth->getAllAssignments() as $userId => $roles) {
56
            $roles = implode(',', array_keys($roles));
57
            printf("   %-12s %s\n", "$userId:", $roles);
58
        }
59
    }
60
}
61