Completed
Push — master ( 0ca8c7...32ef7a )
by Andrii
04:22
created

RbacController::actionShow()   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 21
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

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