Rbac::getPermissions()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace WebComplete\rbac;
4
5
use WebComplete\rbac\entity\PermissionInterface;
6
use WebComplete\rbac\entity\RoleInterface;
7
use WebComplete\rbac\resource\ResourceInterface;
8
9
class Rbac implements RbacInterface
10
{
11
12
    /**
13
     * @var ResourceInterface
14
     */
15
    protected $resource;
16
17
    /**
18
     * @param ResourceInterface $resource
19
     *
20
     * @throws \WebComplete\rbac\exception\RbacException
21
     */
22
    public function __construct(ResourceInterface $resource)
23
    {
24
        $this->resource = $resource;
25
        $this->resource->load();
26
    }
27
28
    /**
29
     * @param string $name
30
     * @param string $description
31
     *
32
     * @return RoleInterface
33
     */
34
    public function createRole(string $name, string $description = ''): RoleInterface
35
    {
36
        return $this->resource->createRole($name, $description);
37
    }
38
39
    /**
40
     * @param string $name
41
     * @param string $description
42
     *
43
     * @return PermissionInterface
44
     * @throws \WebComplete\rbac\exception\RbacException
45
     */
46
    public function createPermission(string $name, string $description = ''): PermissionInterface
47
    {
48
        return $this->resource->createPermission($name, $description);
49
    }
50
51
    /**
52
     * @return RoleInterface[]
53
     */
54
    public function getRoles(): array
55
    {
56
        return $this->resource->getRoles();
57
    }
58
59
    /**
60
     * @param string $name
61
     *
62
     * @return RoleInterface|null
63
     */
64
    public function getRole(string $name)
65
    {
66
        return $this->resource->getRole($name);
67
    }
68
69
    /**
70
     * @param string $name
71
     */
72
    public function deleteRole(string $name)
73
    {
74
        $this->resource->deleteRole($name);
75
    }
76
77
    /**
78
     * @return PermissionInterface[]
79
     */
80
    public function getPermissions(): array
81
    {
82
        return $this->resource->getPermissions();
83
    }
84
85
    /**
86
     * @param string $name
87
     *
88
     * @return PermissionInterface|null
89
     */
90
    public function getPermission(string $name)
91
    {
92
        return $this->resource->getPermission($name);
93
    }
94
95
    /**
96
     * @param string $name
97
     */
98
    public function deletePermission(string $name)
99
    {
100
        $this->resource->deletePermission($name);
101
    }
102
103
    /**
104
     */
105
    public function clear()
106
    {
107
        $this->resource->clear();
108
    }
109
110
    /**
111
     * @throws \WebComplete\rbac\exception\RbacException
112
     */
113
    public function load()
114
    {
115
        $this->resource->load();
116
    }
117
118
    /**
119
     * @throws \WebComplete\rbac\exception\RbacException
120
     */
121
    public function save()
122
    {
123
        $this->resource->save();
124
    }
125
}
126