BaseValidateComponent::init()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 4
c 1
b 0
f 0
nc 4
nop 0
dl 0
loc 8
rs 10
1
<?php
2
3
namespace Itstructure\RbacModule\components;
4
5
use Yii;
6
use yii\base\{Component, InvalidConfigException};
7
use yii\rbac\ManagerInterface;
8
9
/**
10
 * Class BaseValidateComponent
11
 *
12
 * @property ManagerInterface $authManager
13
 *
14
 * @package Itstructure\RbacModule\components
15
 */
16
class BaseValidateComponent extends Component
17
{
18
    /**
19
     * Auth manager.
20
     *
21
     * @var ManagerInterface
22
     */
23
    private $authManager;
24
25
    /**
26
     * Initialize.
27
     */
28
    public function init()
29
    {
30
        if (null === $this->authManager) {
31
            $this->setAuthManager(Yii::$app->authManager);
32
        }
33
34
        if (null === $this->authManager) {
35
            throw new InvalidConfigException('The authManager is not defined.');
36
        }
37
    }
38
39
    /**
40
     * Returns the authManager (RBAC).
41
     *
42
     * @return ManagerInterface
43
     */
44
    public function getAuthManager(): ManagerInterface
45
    {
46
        return $this->authManager;
47
    }
48
49
    /**
50
     * Set authManager (RBAC).
51
     *
52
     * @param ManagerInterface $authManager
53
     */
54
    public function setAuthManager(ManagerInterface $authManager): void
55
    {
56
        $this->authManager = $authManager;
57
    }
58
}
59