Completed
Push — master ( 2d333a...ab0ccf )
by Andrii
03:57
created

RbacController::actionInit()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 7
ccs 0
cts 6
cp 0
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
crap 2
1
<?php
2
3
/*
4
 * HiPanel core package
5
 *
6
 * @link      https://hipanel.com/
7
 * @package   hipanel-core
8
 * @license   BSD-3-Clause
9
 * @copyright Copyright (c) 2014-2016, HiQDev (http://hiqdev.com/)
10
 */
11
12
namespace hipanel\rbac\console;
13
14
use hipanel\rbac\Initer;
15
use Yii;
16
use yii\rbac\Item;
17
18
/**
19
 * Class RbacController.
20
 *
21
 * Usage: ./hidev rbac/init
22
 */
23
class RbacController extends \yii\console\Controller
24
{
25
    public function actionInit()
26
    {
27
        $auth = Yii::$app->get('authManager');
28
        $auth->setAssignment('freezer', 'sol');
29
30
        Initer::init($auth);
31
    }
32
33
    public function actionShow()
34
    {
35
        $auth = Yii::$app->get('authManager');
36
37
        echo "Permissions:\n";
38
        foreach ($auth->getItems(Item::TYPE_PERMISSION) as $name => $perm) {
39
            echo "\t$perm->name $perm->description\n";
40
        }
41
42
        echo "Roles:\n";
43
        foreach ($auth->getItems(Item::TYPE_ROLE) as $name => $role) {
44
            $children = implode(',', array_keys($auth->getChildren($name)));
45
            echo "\t$role->name [$children] $role->description\n";
46
        }
47
    }
48
}
49